-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDockerfile
80 lines (57 loc) · 2.21 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Define global user name
ARG server_user=goapi
# Start from a Alpine Linux image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang:1.14.4-alpine3.12 As build
RUN apk add --update --no-cache \
tzdata \
ca-certificates \
git \
&& update-ca-certificates
ENV GO111MODULE on
# Module cache pre-warm
WORKDIR /go/cache
COPY go.mod .
COPY go.sum .
RUN go mod download
RUN go mod verify
WORKDIR /go/src/github.com/twreporter/go-api
# Copy the local package files to the container's workspace.
COPY . .
ENV DOCKERIZE_VERSION v0.6.1
# Download mysql health check docker
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
# Build the migrate tool
RUN MIGRATE_PATH=$(cat go.mod | grep migrate | awk '{print $1}') && \
go build -o /go/bin/migrate -tags 'mysql' ${MIGRATE_PATH}/cmd/migrate
# Inherit global user argument
ARG server_user
# Add the user for running go-api
RUN adduser -D -g '' ${server_user}
# Install
RUN go install
# Minimize image size by only using the required binary
FROM alpine:3.12
COPY --from=build /go/bin /usr/local/bin /usr/local/bin/
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build /etc/passwd /etc/passwd
ARG server_user
WORKDIR /home/${server_user}
COPY ./aws_credentials /home/${server_user}/.aws/credentials
COPY ./pubsub_credentials /home/${server_user}/pubsub_credentials
COPY ./entrypoint.sh /home/${server_user}/entrypoint.sh
COPY ./migrations /home/${server_user}/migrations/
COPY ./template /home/${server_user}/template/
RUN chmod +x entrypoint.sh
ENV GOOGLE_APPLICATION_CREDENTIALS /home/${server_user}/pubsub_credentials
ENV MIGRATION_DIR /home/${server_user}/migrations/
# Specify the user for running go-api
USER ${server_user}
# Run the outyet command by default when the container starts.
ENTRYPOINT ["./entrypoint.sh"]
CMD ["go-api"]
# Document that the service listens on port 8080.
EXPOSE 8080