-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
43 lines (42 loc) · 2.11 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
# syntax=registry.cn-shenzhen.aliyuncs.com/dev-ops/dockerfile:1.9.0
FROM registry.cn-shenzhen.aliyuncs.com/dev-ops/golang:1.23.1-alpine3.20 as golang
ENV APP go-gin-rest-api
RUN sed -i 's/https/http/' /etc/apk/repositories && \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && \
apk add --no-cache ca-certificates git && \
rm -rf /var/cache/apk/* /tmp/*
ADD ./ /app/go-gin-rest-api
ADD .git/ /app/go-gin-rest-api/.git
WORKDIR /app/go-gin-rest-api
RUN export GitBranch=$(git name-rev --name-only HEAD) && \
export GitRevision=$(git rev-parse --short HEAD) && \
export GitCommitLog=`git log --pretty=oneline -n 1` && \
export BuildTime=`date +'%Y.%m.%d.%H%M%S'` && \
export BuildGoVersion=`go version` && \
export LDFlags="-s -w -X 'main.GitBranch=${GitBranch}' -X 'main.GitRevision=${GitRevision}' -X 'main.GitCommitLog=${GitCommitLog}' -X 'main.BuildTime=${BuildTime}' -X 'main.BuildGoVersion=${BuildGoVersion}'" && \
go build -tags=jsoniter -ldflags="$LDFlags" -o ./go-gin-rest-api
FROM registry.cn-shenzhen.aliyuncs.com/dev-ops/alpine:3.20.3
LABEL MAINTAINER="13579443@qq.com"
ENV TZ='Asia/Shanghai'
ENV LANG UTF-8
ENV LC_ALL zh_CN.UTF-8
ENV LC_CTYPE zh_CN.UTF-8
RUN TERM=linux && export TERM
RUN sed -i 's/https/http/' /etc/apk/repositories && \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && \
apk add --no-cache ca-certificates tzdata bash sudo busybox-extras curl && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtim && \
echo "Asia/Shanghai" > /etc/timezone && \
rm -rf /var/cache/apk/* /tmp/* && \
addgroup -g 1000 app && \
adduser -u 1000 -G app -D app && \
adduser -u 1001 -G app -D dev && \
chmod 4755 /bin/busybox && \
mkdir -p /app && \
chown -R app:app /app
WORKDIR /app/go-gin-rest-api/
COPY --from=golang --chown=app:app --chmod=755 /app/go-gin-rest-api/go-gin-rest-api /app/go-gin-rest-api/go-gin-rest-api
COPY --from=golang --chown=app:app --chmod=755 /app/go-gin-rest-api/conf /app/go-gin-rest-api/conf
CMD ["./go-gin-rest-api"]