feat: use github action to build and release docker image

pull/235/head
1379 2 years ago
parent 0ec15edcd9
commit 60412cba69

@ -1,10 +1,6 @@
name: Linter
on:
push:
paths:
- "**/*.go"
- ".github/workflows/linter.yml"
pull_request:
types: [opened, synchronize, reopened]
paths:

@ -0,0 +1,38 @@
name: Release-Docker
on:
release:
types: [published]
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set build time
run: |
echo "BUILD_TIME=$(date +%FT%T%z)" >> $GITHUB_ENV
-
name: Build and push
uses: docker/build-push-action@v4
with:
platforms: linux/arm64,linux/amd64
push: true
file: ./scripts/Dockerfile
tags: gosonic/sonic:test
build-args: |
SONIC_VERSION=${{github.ref_name}}
BUILD_COMMIT=${{github.sha}}
BUILD_TIME=${{env.BUILD_TIME}}

@ -54,7 +54,7 @@ jobs:
- name: Show workflow information
run: |
echo "GOOS: $GOOS, GOARCH: $GOARCH"
echo "BUILD_TIME=$(date --rfc-3339=seconds)" >> $GITHUB_ENV
echo "BUILD_TIME=$(date +%FT%T%z)" >> $GITHUB_ENV
- name: Build
uses: crazy-max/ghaction-xgo@v2

1
.gitignore vendored

@ -4,6 +4,7 @@
/upload
/.vscode
sonic.db
sonic
__debug_bin
/resources/template/theme/
!/resources/template/theme/default-theme-anatole

@ -1,14 +1,16 @@
FROM golang:1.19.3-alpine as builder
RUN apk --no-cache add git ca-certificates gcc g++
WORKDIR /go/src/github.com/go-sonic/
RUN git clone --recursive --depth 1 https://github.com/go-sonic/sonic.git
COPY . /go/src/github.com/go-sonic/sonic/
WORKDIR /go/src/github.com/go-sonic/sonic
RUN GOPROXY=https://goproxy.cn CGO_ENABLED=1 GOOS=linux go build -o sonic -ldflags="-s -w" -trimpath .
ARG BUILD_COMMIT
ARG BUILD_TIME
ARG SONIC_VERSION
RUN CGO_ENABLED=1 GOOS=linux && \
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 .
RUN mkdir -p /app/conf && \
mkdir /app/resources && \
@ -17,12 +19,14 @@ RUN mkdir -p /app/conf && \
cp -r /go/src/github.com/go-sonic/sonic/resources /app/ && \
cp /go/src/github.com/go-sonic/sonic/scripts/docker_init.sh /app/
FROM alpine:latest as prod
COPY --from=builder /app/ /app/
RUN apk update \
&& apk add --no-cache tzdata \
RUN apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone

Loading…
Cancel
Save