From dffe81b6b561da4e83aa2635735db3e6be556c8b Mon Sep 17 00:00:00 2001 From: E99p1ant Date: Mon, 8 Jan 2024 23:12:38 +0800 Subject: [PATCH] ci: update Dockerfile and deploy.yml --- .github/workflows/deploy.yml | 19 +++---------------- Dockerfile | 14 +++++++++++++- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 96cf4a3..c377ee6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,36 +12,23 @@ jobs: outputs: image_tag: ${{ steps.image-tag.outputs.tag }} steps: - - name: Set up Go 1.20 - uses: actions/setup-go@v1 - with: - go-version: 1.20 - id: go - - name: Check out code into the Go module directory uses: actions/checkout@v3 - - name: Get dependencies - run: | - go mod tidy - - - name: Build - run: | - CGO_ENABLED=0 go build -v -ldflags "-w -s -extldflags '-static' -X 'github.com/NekoWheel/NekoBox/internal/conf.BuildCommit=$GITHUB_SHA'" -o NekoBox ./cmd/ - - name: Set image tag id: image-tag run: echo "tag=$(date -u '+%Y%m%d-%I%M%S')" >> $GITHUB_OUTPUT - name: Build & Publish to Registry - uses: wuhan005/publish-docker-action@master + uses: jerray/publish-docker-action@master with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} registry: ${{ secrets.DOCKER_REGISTRY }} repository: ${{ secrets.DOCKER_NAME }} auto_tag: true - tag_format: ${{ steps.image-tag.outputs.tag }} + build_args: GITHUB_SHA=${{ github.sha }} + tags: ${{ steps.image-tag.outputs.tag }} deploy: name: Deploy diff --git a/Dockerfile b/Dockerfile index 980ace3..4bbdd18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,23 @@ +FROM golang:1.20-alpine as builder + +WORKDIR /app + +ENV CGO_ENABLED=0 + +COPY . . + +RUN go mod tidy +RUN go build -v -ldflags "-w -s -extldflags '-static' -X 'github.com/NekoWheel/NekoBox/internal/conf.BuildCommit=$GITHUB_SHA'" -o NekoBox ./cmd/ + FROM alpine:latest RUN apk update && apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone -ADD NekoBox /home/app/NekoBox WORKDIR /home/app +COPY --from=builder /app/NekoBox . + RUN chmod 777 /home/app/NekoBox ENTRYPOINT ["./NekoBox", "web"]