-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
50 lines (39 loc) · 1.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
FROM golang:alpine as builder
ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct \
GIN_MODE=release \
PORT=8799
# install makefile tools
#RUN apk --no-cache add make gcc libc-dev git
# create and use work directory
WORKDIR /app
#copy go models file
COPY go.mod go.sum ./
#download swag
RUN go get -u github.com/swaggo/swag/cmd/swag
#download other model
RUN go mod download
# copy project source file to work dir
COPY . .
# exec Makefile
RUN go run github.com/swaggo/swag/cmd/swag init
# compile go source file to app dir
RUN go build -o ./executable
# use pure alpine as runtime environment
FROM alpine AS runner
RUN apk --no-cache add ca-certificates
COPY --from=builder /app/executable .
COPY --from=builder /app/config ./config
COPY --from=builder /app/docs ./docs
ARG env
ENV env=${env:-prod}
# replace source with aliyun
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk update
# add time zone setting
RUN apk update && apk add tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone && apk del tzdata
EXPOSE 8799
# run go executable file
# use shell form to support env param
ENTRYPOINT ./executable "env=$env"