Skip to content

Commit decc878

Browse files
docker: improved container build time
To enable go modules cache add following to `.env.override`: ``` SHELLHUB_GOPROXY=http://<ADDRESS> ``` Replace `<ADDRESS>` with the address proxy cache URL. For caching go modules Athens (https://docs.gomods.io) is the recommended proxy cache but you can use anything else. To run Athens on `http://localhost:3333`: ``` docker run \ --name athens \ -e ATHENS_DISK_STORAGE_ROOT=/var/cache/misc \ -e ATHENS_STORAGE_TYPE=disk \ --restart always -d -p '3333:3000' gomods/athens:latest ``` To enable npm modules cache add following to `.env.override`: ``` SHELLHUB_NPM_REGISTRY=http://<ADDRESS> ``` For caching npm modules, Athens (https://verdaccio.org/) is the recommended proxy cache but you can use anything else. To run Athens on `http://localhost:4873`: ``` docker run --name verdaccio --restart always -d -p 4873:4873 verdaccio/verdaccio ``` This closes #941.
1 parent 62be114 commit decc878

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ SHELLHUB_ENTERPRISE_ADMIN_PASSWORD=
5151
# Internal to our cloud service. - don't worry about it
5252
SHELLHUB_CLOUD=false
5353

54+
# Set Go modules proxy cache URL (development only)
55+
#SHELLHUB_GOPROXY=http://localhost:3333
56+
57+
# Set NPM proxy cache URL (development only)
58+
#SHELLHUB_NPM_REGISTRY=http://localhost:4873
59+
5460
# Webhook config
5561
SHELLHUB_WEBHOOK_URL=""
5662
SHELLHUB_WEBHOOK_PORT=""

agent/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# base stage
22
FROM golang:1.16.4-alpine3.13 AS base
33

4+
ARG GOPROXY
5+
46
RUN apk add --update git ca-certificates build-base bash util-linux setpriv
57

68
RUN ln -sf /bin/bash /bin/sh
@@ -19,6 +21,7 @@ RUN go mod download
1921
FROM base AS builder
2022

2123
ARG SHELLHUB_VERSION=latest
24+
ARG GOPROXY
2225

2326
COPY ./pkg $GOPATH/src/github.com/shellhub-io/shellhub/pkg
2427
COPY ./agent .
@@ -34,6 +37,9 @@ RUN go build -tags docker -ldflags "-X main.AgentVersion=${SHELLHUB_VERSION}"
3437
# development stage
3538
FROM base AS development
3639

40+
ARG GOPROXY
41+
ENV GOPROXY ${GOPROXY}
42+
3743
RUN apk add --update openssl openssh-client
3844
RUN go get github.com/markbates/refresh && go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1
3945

api/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# base stage
22
FROM golang:1.16.4-alpine3.13 AS base
33

4+
ARG GOPROXY
5+
46
RUN apk add --no-cache git ca-certificates
57

68
WORKDIR $GOPATH/src/github.com/shellhub-io/shellhub
@@ -16,6 +18,8 @@ RUN go mod download
1618
# builder stage
1719
FROM base AS builder
1820

21+
ARG GOPROXY
22+
1923
COPY ./pkg $GOPATH/src/github.com/shellhub-io/shellhub/pkg
2024
COPY ./api .
2125

@@ -30,6 +34,9 @@ RUN go build
3034
# development stage
3135
FROM base AS development
3236

37+
ARG GOPROXY
38+
ENV GOPROXY ${GOPROXY}
39+
3340
RUN apk add --update openssl build-base docker-cli
3441
RUN go get github.com/markbates/refresh && \
3542
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1 && \

docker-compose.dev.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ services:
77
context: .
88
dockerfile: ssh/Dockerfile
99
target: development
10+
network: host
11+
args:
12+
- GOPROXY=${SHELLHUB_GOPROXY}
1013
volumes:
1114
- ./ssh:/go/src/github.com/shellhub-io/shellhub/ssh
1215
- ./pkg:/go/src/github.com/shellhub-io/shellhub/pkg
@@ -18,6 +21,9 @@ services:
1821
context: .
1922
dockerfile: api/Dockerfile
2023
target: development
24+
network: host
25+
args:
26+
- GOPROXY=${SHELLHUB_GOPROXY}
2127
volumes:
2228
- ./api:/go/src/github.com/shellhub-io/shellhub/api
2329
- ./pkg:/go/src/github.com/shellhub-io/shellhub/pkg
@@ -28,6 +34,9 @@ services:
2834
context: .
2935
dockerfile: ui/Dockerfile
3036
target: development
37+
network: host
38+
args:
39+
- NPM_CONFIG_REGISTRY=${SHELLHUB_NPM_REGISTRY}
3140
volumes:
3241
- ./ui:/src
3342
environment:
@@ -47,8 +56,11 @@ services:
4756
context: .
4857
dockerfile: agent/Dockerfile
4958
target: development
59+
network: host
5060
args:
51-
SHELLHUB_VERSION: latest
61+
- SHELLHUB_VERSION=latest
62+
- GOPROXY=${SHELLHUB_GOPROXY}
63+
5264
privileged: true
5365
network_mode: host
5466
pid: host

ssh/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# base stage
22
FROM golang:1.16.4-alpine3.13 AS base
33

4+
ARG GOPROXY
5+
46
RUN apk add --update git ca-certificates build-base openssh-client
57

68
WORKDIR $GOPATH/src/github.com/shellhub-io/shellhub
@@ -16,6 +18,8 @@ RUN go mod download
1618
# builder stage
1719
FROM base AS builder
1820

21+
ARG GOPROXY
22+
1923
COPY ./pkg $GOPATH/src/github.com/shellhub-io/shellhub/pkg
2024
COPY ./ssh .
2125

@@ -30,6 +34,9 @@ RUN go build -tags internal_api
3034
# development stage
3135
FROM base AS development
3236

37+
ARG GOPROXY
38+
ENV GOPROXY ${GOPROXY}
39+
3340
RUN apk add --update openssl
3441
RUN go get github.com/markbates/refresh && go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1
3542

ui/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM node:12.16.0-alpine as base
22

3+
ARG NPM_CONFIG_REGISTRY
4+
35
RUN apk add --update build-base python
46

57
WORKDIR /app
@@ -10,6 +12,9 @@ RUN npm install
1012

1113
FROM base as development
1214

15+
ARG NPM_CONFIG_REGISTRY
16+
ARG ENV ${NPM_CONFIG_REGISTRY}
17+
1318
WORKDIR /src
1419

1520
COPY --from=base /app/node_modules /node_modules
@@ -20,6 +25,8 @@ CMD ["/scripts/entrypoint-dev.sh"]
2025

2126
FROM base as builder
2227

28+
ARG NPM_CONFIG_REGISTRY
29+
2330
WORKDIR /app
2431

2532
COPY ui/. .

0 commit comments

Comments
 (0)