Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 5f76e89

Browse files
committed
Optimize Dockerfile #127
1 parent 42b9958 commit 5f76e89

4 files changed

Lines changed: 57 additions & 19 deletions

File tree

Dockerfile

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
1-
FROM golang:1.15 as build
2-
3-
RUN mkdir /app
4-
WORKDIR /app
1+
FROM golang:alpine AS build
52
ARG VERSION
3+
RUN wget \
4+
--output-document "/cointop-$VERSION.tar.gz" \
5+
"https://github.com/miguelmota/cointop/archive/$VERSION.tar.gz" \
6+
&& wget \
7+
--output-document "/cointop-colors-master.tar.gz" \
8+
"https://github.com/cointop-sh/colors/archive/master.tar.gz" \
9+
&& mkdir --parents \
10+
"$GOPATH/src/github.com/miguelmota/cointop" \
11+
"/usr/local/share/cointop/colors" \
12+
&& tar \
13+
--directory "$GOPATH/src/github.com/miguelmota/cointop" \
14+
--extract \
15+
--file "/cointop-$VERSION.tar.gz" \
16+
--strip-components 1 \
17+
&& tar \
18+
--directory /usr/local/share/cointop/colors \
19+
--extract \
20+
--file /cointop-colors-master.tar.gz \
21+
--strip-components 1 \
22+
&& rm \
23+
"/cointop-$VERSION.tar.gz" \
24+
/cointop-colors-master.tar.gz \
25+
&& cd "$GOPATH/src/github.com/miguelmota/cointop" \
26+
&& CGO_ENABLED=0 go install -ldflags "-s -w -X 'github.com/miguelmota/cointop/cointop.version=$VERSION'" \
27+
&& cd "$GOPATH" \
28+
&& rm -r src/github.com \
29+
&& apk add --no-cache upx \
30+
&& upx --lzma /go/bin/cointop \
31+
&& apk del upx
632

7-
COPY . ./
8-
RUN go build -ldflags=-s -ldflags=-w -ldflags=-X=github.com/miguelmota/cointop/cointop.version=$VERSION -o main .
9-
ADD https://github.com/cointop-sh/colors/archive/master.tar.gz ./
10-
RUN tar zxf master.tar.gz --exclude images
11-
12-
FROM busybox:glibc
13-
RUN mkdir -p /etc/ssl
14-
COPY --from=build /etc/ssl/certs/ /etc/ssl/certs
15-
COPY --from=build /app/main /bin/cointop
16-
COPY --from=build /app/colors-master /root/.config/cointop/colors
17-
ENTRYPOINT ["/bin/cointop"]
18-
CMD []
33+
FROM busybox
34+
ARG VERSION
35+
ARG MAINTAINER
36+
COPY --from=build /etc/ssl/certs /etc/ssl/certs
37+
COPY --from=build /go/bin/cointop /usr/local/bin/cointop
38+
COPY --from=build /usr/local/share /usr/local/share
39+
ENV \
40+
COINTOP_COLORS_DIR=/usr/local/share/cointop/colors \
41+
XDG_CONFIG_HOME=/config
42+
EXPOSE 2222
43+
LABEL \
44+
maintainer="$MAINTAINER" \
45+
version="$VERSION"
46+
ENTRYPOINT ["cointop"]

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
VERSION = $$(git describe --abbrev=0 --tags)
22
VERSION_DATE = $$(git log -1 --pretty='%ad' --date=format:'%Y-%m-%d' $(VERSION))
33
COMMIT_REV = $$(git rev-list -n 1 $(VERSION))
4+
MAINTAINER = "Miguel Mota"
45

56
all: build
67

@@ -228,7 +229,7 @@ release:
228229
VERSION=$(VERSION) goreleaser
229230

230231
docker-build:
231-
docker build --build-arg VERSION=$(VERSION) -t cointop/cointop .
232+
docker build --build-arg VERSION=$(VERSION) --build-arg MAINTAINER=$(MAINTAINER) -t cointop/cointop .
232233

233234
docker-tag:
234235
docker tag cointop/cointop:latest cointop/cointop:$(VERSION)

cmd/commands/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package cmd
44

55
import (
66
"fmt"
7+
"os"
78
"strings"
89
"time"
910

@@ -21,6 +22,7 @@ func ServerCmd() *cobra.Command {
2122
var executableBinary string = "cointop"
2223
var hostKeyFile string = cssh.DefaultHostKeyFile
2324
var userConfigType string = cssh.UserConfigTypePublicKey
25+
var colorsDir string = os.Getenv("COINTOP_COLORS_DIR")
2426

2527
serverCmd := &cobra.Command{
2628
Use: "server",
@@ -36,6 +38,7 @@ func ServerCmd() *cobra.Command {
3638
ExecutableBinary: executableBinary,
3739
HostKeyFile: hostKeyFile,
3840
UserConfigType: userConfigType,
41+
ColorsDir: colorsDir,
3942
})
4043

4144
fmt.Printf("Running SSH server on port %v\n", port)

pkg/ssh/server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Config struct {
4646
HostKeyFile string
4747
MaxSessions uint
4848
UserConfigType string
49+
ColorsDir string
4950
}
5051

5152
// Server is server struct
@@ -60,6 +61,7 @@ type Server struct {
6061
maxSessions uint
6162
sessionCount uint
6263
userConfigType string
64+
colorsDir string
6365
}
6466

6567
// NewServer returns a new server instance
@@ -74,6 +76,10 @@ func NewServer(config *Config) *Server {
7476
}
7577
validateUserConfigType(userConfigType)
7678
hostKeyFile = pathutil.NormalizePath(hostKeyFile)
79+
colorsDir := pathutil.NormalizePath("~/.config/cointop/colors")
80+
if config.ColorsDir != "" {
81+
colorsDir = pathutil.NormalizePath(config.ColorsDir)
82+
}
7783
return &Server{
7884
port: config.Port,
7985
address: config.Address,
@@ -83,6 +89,7 @@ func NewServer(config *Config) *Server {
8389
hostKeyFile: hostKeyFile,
8490
maxSessions: config.MaxSessions,
8591
userConfigType: userConfigType,
92+
colorsDir: colorsDir,
8693
}
8794
}
8895

@@ -153,7 +160,6 @@ func (s *Server) ListenAndServe() error {
153160
}
154161

155162
configPath := fmt.Sprintf("%s/config", configDir)
156-
colorsDir := pathutil.NormalizePath("~/.config/cointop/colors")
157163

158164
cmdCtx, cancelCmd := context.WithCancel(sshSession.Context())
159165
defer cancelCmd()
@@ -166,7 +172,7 @@ func (s *Server) ListenAndServe() error {
166172
"--config",
167173
configPath,
168174
"--colors-dir",
169-
colorsDir,
175+
s.colorsDir,
170176
}
171177

172178
if len(cmdUserArgs) > 0 {

0 commit comments

Comments
 (0)