diff --git a/Dockerfile b/Dockerfile index cdff1eb..44aa528 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,46 @@ -FROM golang:1.15 as build - -RUN mkdir /app -WORKDIR /app +FROM golang:alpine AS build ARG VERSION +RUN wget \ + --output-document "/cointop-$VERSION.tar.gz" \ + "https://github.com/miguelmota/cointop/archive/$VERSION.tar.gz" \ +&& wget \ + --output-document "/cointop-colors-master.tar.gz" \ + "https://github.com/cointop-sh/colors/archive/master.tar.gz" \ +&& mkdir --parents \ + "$GOPATH/src/github.com/miguelmota/cointop" \ + "/usr/local/share/cointop/colors" \ +&& tar \ + --directory "$GOPATH/src/github.com/miguelmota/cointop" \ + --extract \ + --file "/cointop-$VERSION.tar.gz" \ + --strip-components 1 \ +&& tar \ + --directory /usr/local/share/cointop/colors \ + --extract \ + --file /cointop-colors-master.tar.gz \ + --strip-components 1 \ +&& rm \ + "/cointop-$VERSION.tar.gz" \ + /cointop-colors-master.tar.gz \ +&& cd "$GOPATH/src/github.com/miguelmota/cointop" \ +&& CGO_ENABLED=0 go install -ldflags "-s -w -X 'github.com/miguelmota/cointop/cointop.version=$VERSION'" \ +&& cd "$GOPATH" \ +&& rm -r src/github.com \ +&& apk add --no-cache upx \ +&& upx --lzma /go/bin/cointop \ +&& apk del upx -COPY . ./ -RUN go build -ldflags=-s -ldflags=-w -ldflags=-X=github.com/miguelmota/cointop/cointop.version=$VERSION -o main . -ADD https://github.com/cointop-sh/colors/archive/master.tar.gz ./ -RUN tar zxf master.tar.gz --exclude images - -FROM busybox:glibc -RUN mkdir -p /etc/ssl -COPY --from=build /etc/ssl/certs/ /etc/ssl/certs -COPY --from=build /app/main /bin/cointop -COPY --from=build /app/colors-master /root/.config/cointop/colors -ENTRYPOINT ["/bin/cointop"] -CMD [] +FROM busybox +ARG VERSION +ARG MAINTAINER +COPY --from=build /etc/ssl/certs /etc/ssl/certs +COPY --from=build /go/bin/cointop /usr/local/bin/cointop +COPY --from=build /usr/local/share /usr/local/share +ENV \ + COINTOP_COLORS_DIR=/usr/local/share/cointop/colors \ + XDG_CONFIG_HOME=/config +EXPOSE 2222 +LABEL \ + maintainer="$MAINTAINER" \ + version="$VERSION" +ENTRYPOINT ["cointop"] diff --git a/Makefile b/Makefile index 3679d0b..49d3cc2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ VERSION = $$(git describe --abbrev=0 --tags) VERSION_DATE = $$(git log -1 --pretty='%ad' --date=format:'%Y-%m-%d' $(VERSION)) COMMIT_REV = $$(git rev-list -n 1 $(VERSION)) +MAINTAINER = "Miguel Mota" all: build @@ -228,7 +229,7 @@ release: VERSION=$(VERSION) goreleaser docker-build: - docker build --build-arg VERSION=$(VERSION) -t cointop/cointop . + docker build --build-arg VERSION=$(VERSION) --build-arg MAINTAINER=$(MAINTAINER) -t cointop/cointop . docker-tag: docker tag cointop/cointop:latest cointop/cointop:$(VERSION) diff --git a/cmd/commands/server.go b/cmd/commands/server.go index ecd281d..93d59bd 100644 --- a/cmd/commands/server.go +++ b/cmd/commands/server.go @@ -4,6 +4,7 @@ package cmd import ( "fmt" + "os" "strings" "time" @@ -21,6 +22,7 @@ func ServerCmd() *cobra.Command { var executableBinary string = "cointop" var hostKeyFile string = cssh.DefaultHostKeyFile var userConfigType string = cssh.UserConfigTypePublicKey + var colorsDir string = os.Getenv("COINTOP_COLORS_DIR") serverCmd := &cobra.Command{ Use: "server", @@ -36,6 +38,7 @@ func ServerCmd() *cobra.Command { ExecutableBinary: executableBinary, HostKeyFile: hostKeyFile, UserConfigType: userConfigType, + ColorsDir: colorsDir, }) fmt.Printf("Running SSH server on port %v\n", port) diff --git a/pkg/ssh/server.go b/pkg/ssh/server.go index 50222a5..19d42f7 100644 --- a/pkg/ssh/server.go +++ b/pkg/ssh/server.go @@ -46,6 +46,7 @@ type Config struct { HostKeyFile string MaxSessions uint UserConfigType string + ColorsDir string } // Server is server struct @@ -60,6 +61,7 @@ type Server struct { maxSessions uint sessionCount uint userConfigType string + colorsDir string } // NewServer returns a new server instance @@ -74,6 +76,10 @@ func NewServer(config *Config) *Server { } validateUserConfigType(userConfigType) hostKeyFile = pathutil.NormalizePath(hostKeyFile) + colorsDir := pathutil.NormalizePath("~/.config/cointop/colors") + if config.ColorsDir != "" { + colorsDir = pathutil.NormalizePath(config.ColorsDir) + } return &Server{ port: config.Port, address: config.Address, @@ -83,6 +89,7 @@ func NewServer(config *Config) *Server { hostKeyFile: hostKeyFile, maxSessions: config.MaxSessions, userConfigType: userConfigType, + colorsDir: colorsDir, } } @@ -153,7 +160,6 @@ func (s *Server) ListenAndServe() error { } configPath := fmt.Sprintf("%s/config", configDir) - colorsDir := pathutil.NormalizePath("~/.config/cointop/colors") cmdCtx, cancelCmd := context.WithCancel(sshSession.Context()) defer cancelCmd() @@ -166,7 +172,7 @@ func (s *Server) ListenAndServe() error { "--config", configPath, "--colors-dir", - colorsDir, + s.colorsDir, } if len(cmdUserArgs) > 0 {