-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dockerfile
50 lines (38 loc) · 1.42 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# image for compiling binary
ARG BUILDER_IMAGE="golang:1.16-alpine"
# here we'll run binary app
ARG RUNNER_IMAGE="alpine:3.12"
FROM ${BUILDER_IMAGE} as builder
### variables
# disable golang package proxying for this modules. necessary for private repos. Example: github.com/company-name
ARG GOPRIVATE=""
# ssh key for accessing private repos
ARG SSH_KEY
ENV GO111MODULE on
ENV GOPRIVATE ${GOPRIVATE}
RUN apk add --update gcc g++ openssh git make
# configure git to work with private repos
RUN mkdir -p ~/.ssh/ &&\
echo "${SSH_KEY}" >> ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa && ssh-keyscan github.com >> ~/.ssh/known_hosts &&\
git config --global url."[email protected]:".insteadOf "https://github.com/"
### copying project files
WORKDIR /go/src/github.com/wajox/gobase
# copy gomod
COPY go.mod go.sum ./
# Get dependancies. Also will be cached if we won't change mod/sum
RUN go mod download
# COPY the source code as the last step
COPY . .
# creates build/main files
RUN make build
FROM ${RUNNER_IMAGE}
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories &&\
apk update &&\
apk add --no-cache\
ca-certificates
RUN mkdir -p ./api
RUN mkdir -p ./db/migrations
COPY --from=builder /go/src/github.com/wajox/gobase/api ./api
COPY --from=builder /go/src/github.com/wajox/gobase/db/migrations ./db/migrations
COPY --from=builder /go/src/github.com/wajox/gobase/build/app .
CMD ["./app", "s"]