Skip to content

Commit f76e1af

Browse files
committed
chore: reduce docker image size
1 parent fb2e482 commit f76e1af

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

.github/workflows/docker-image.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212

13+
strategy:
14+
matrix:
15+
goos: [linux]
16+
goarch: [amd64, arm64]
1317
steps:
1418
- uses: actions/checkout@v3
1519
- name: Docker Login
1620
env:
1721
DOCKER_USER: ${{ secrets.DOCKER_USER }}
1822
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
23+
GOOS: ${{ matrix.goos }}
24+
GOARCH: ${{ matrix.goarch }}
25+
CGO_ENABLED: 0
26+
GO111MODULE: on
1927
run: |
2028
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
2129
- name: Build the Docker image

Dockerfile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
FROM golang:1.20 AS builder
2-
3-
ENV GO111MODULE=on \
4-
CGO_ENABLED=0 \
5-
GOOS=linux \
6-
GOARCH=amd64
7-
2+
RUN apk --no-cache add tzdata
83
WORKDIR /build
94
COPY . .
105
RUN go mod tidy && go build -ldflags "-s -w" -o main
116

127

13-
FROM alpine
14-
15-
RUN apk --update --no-cache add tzdata ca-certificates \
16-
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
17-
&& mkdir -p conf && touch conf/whitelist
8+
FROM scratch
9+
COPY --from=builder /user/share/zoneinfo /user/share/zoneinfo
10+
COPY --from=builder /build/conf conf
1811
COPY --from=builder /build/main /
12+
ENV TZ=Asia/Shanghai
1913

2014
ENTRYPOINT ["/main"]

0 commit comments

Comments
 (0)