diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 76f30ba..98842fa 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,10 +1,6 @@ name: Linter on: - push: - paths: - - "**/*.go" - - ".github/workflows/linter.yml" pull_request: types: [opened, synchronize, reopened] paths: diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml new file mode 100644 index 0000000..a89dfc8 --- /dev/null +++ b/.github/workflows/release-docker.yml @@ -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}} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0205082..e477d28 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.gitignore b/.gitignore index f04e4b6..bb40d4f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /upload /.vscode sonic.db +sonic __debug_bin /resources/template/theme/ !/resources/template/theme/default-theme-anatole \ No newline at end of file diff --git a/scripts/Dockerfile b/scripts/Dockerfile index d8cb4c7..b221601 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -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