Skip to content

Commit 60412cb

Browse files
author
1379
committedMay 1, 2023
feat: use github action to build and release docker image
1 parent 0ec15ed commit 60412cb

File tree

5 files changed

+52
-13
lines changed

5 files changed

+52
-13
lines changed
 

‎.github/workflows/linter.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Linter
22

33
on:
4-
push:
5-
paths:
6-
- "**/*.go"
7-
- ".github/workflows/linter.yml"
84
pull_request:
95
types: [opened, synchronize, reopened]
106
paths:

‎.github/workflows/release-docker.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release-Docker
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
docker:
9+
runs-on: ubuntu-latest
10+
steps:
11+
-
12+
name: Set up QEMU
13+
uses: docker/setup-qemu-action@v2
14+
-
15+
name: Set up Docker Buildx
16+
uses: docker/setup-buildx-action@v2
17+
-
18+
name: Login to Docker Hub
19+
uses: docker/login-action@v2
20+
with:
21+
username: ${{ secrets.DOCKERHUB_USERNAME }}
22+
password: ${{ secrets.DOCKERHUB_TOKEN }}
23+
-
24+
name: Set build time
25+
run: |
26+
echo "BUILD_TIME=$(date +%FT%T%z)" >> $GITHUB_ENV
27+
-
28+
name: Build and push
29+
uses: docker/build-push-action@v4
30+
with:
31+
platforms: linux/arm64,linux/amd64
32+
push: true
33+
file: ./scripts/Dockerfile
34+
tags: gosonic/sonic:test
35+
build-args: |
36+
SONIC_VERSION=${{github.ref_name}}
37+
BUILD_COMMIT=${{github.sha}}
38+
BUILD_TIME=${{env.BUILD_TIME}}

‎.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Show workflow information
5555
run: |
5656
echo "GOOS: $GOOS, GOARCH: $GOARCH"
57-
echo "BUILD_TIME=$(date --rfc-3339=seconds)" >> $GITHUB_ENV
57+
echo "BUILD_TIME=$(date +%FT%T%z)" >> $GITHUB_ENV
5858
5959
- name: Build
6060
uses: crazy-max/ghaction-xgo@v2

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/upload
55
/.vscode
66
sonic.db
7+
sonic
78
__debug_bin
89
/resources/template/theme/
910
!/resources/template/theme/default-theme-anatole

‎scripts/Dockerfile

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
FROM golang:1.19.3-alpine as builder
2-
32
RUN apk --no-cache add git ca-certificates gcc g++
43

5-
WORKDIR /go/src/github.com/go-sonic/
6-
7-
RUN git clone --recursive --depth 1 https://github.com/go-sonic/sonic.git
8-
4+
COPY . /go/src/github.com/go-sonic/sonic/
95
WORKDIR /go/src/github.com/go-sonic/sonic
106

11-
RUN GOPROXY=https://goproxy.cn CGO_ENABLED=1 GOOS=linux go build -o sonic -ldflags="-s -w" -trimpath .
7+
ARG BUILD_COMMIT
8+
ARG BUILD_TIME
9+
ARG SONIC_VERSION
10+
11+
12+
RUN CGO_ENABLED=1 GOOS=linux && \
13+
go build -o sonic -ldflags="-s -w -X github.com/go-sonic/sonic/consts.SonicVersion=${SONIC_VERSION} -X github.com/go-sonic/sonic/consts.BuildCommit=${BUILD_COMMIT} -X github.com/go-sonic/sonic/consts.BuildTime=${BUILD_TIME}" -trimpath .
1214

1315
RUN mkdir -p /app/conf && \
1416
mkdir /app/resources && \
@@ -17,12 +19,14 @@ RUN mkdir -p /app/conf && \
1719
cp -r /go/src/github.com/go-sonic/sonic/resources /app/ && \
1820
cp /go/src/github.com/go-sonic/sonic/scripts/docker_init.sh /app/
1921

22+
23+
24+
2025
FROM alpine:latest as prod
2126

2227
COPY --from=builder /app/ /app/
2328

24-
RUN apk update \
25-
&& apk add --no-cache tzdata \
29+
RUN apk add --no-cache tzdata \
2630
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
2731
&& echo "Asia/Shanghai" > /etc/timezone
2832

0 commit comments

Comments
 (0)
Please sign in to comment.