-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathAPI.Dockerfile
64 lines (44 loc) · 1.53 KB
/
API.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
# Builder image
FROM golang:1.17-alpine as builder
RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories && \
apk add --no-cache \
wget \
git
RUN mkdir -p /home/build && \
mkdir -p /home/api
ARG build_dir=/home/build
ARG api_dir=/home/api
ENV ServiceName=gf.bridgx.api
WORKDIR $build_dir
COPY . .
# Cache dependencies
ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn,direct
COPY go.mod go.mod
COPY go.sum go.sum
#RUN go mod download
RUN mkdir -p output/conf output/bin
# detect mysql start
COPY wait-for-api.sh output/bin/wait-for-api.sh
RUN find conf/ -type f ! -name "*_local.*" | xargs -I{} cp {} output/conf/
RUN cp scripts/run_api.sh output/
RUN CGO_ENABLED=0 GO111MODULE=on go build -o output/bin/${ServiceName} ./cmd/api
RUN cp -rf output/* $api_dir
# --------------------------------------------------------------------------------- #
# Executable image
FROM alpine:3.14
RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories
RUN apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
ENV TZ Asia/Shanghai
RUN apk add --no-cache bash
ENV ServiceName=gf.bridgx.api
ENV SpecifiedConfig=prod
COPY --from=builder /home/api /home/tiger/api
RUN addgroup -S tiger && adduser -S tiger -G tiger
WORKDIR /home/tiger/api
RUN chown -R tiger:tiger /home/tiger && chmod +x run_api.sh && chmod +x bin/wait-for-api.sh
USER tiger
EXPOSE 9090
CMD ["/bin/sh","/home/tiger/api/run_api.sh"]