Skip to content

Commit

Permalink
ci: update Dockerfile and deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhan005 committed Jan 8, 2024
1 parent 16d8522 commit dffe81b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
19 changes: 3 additions & 16 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down

0 comments on commit dffe81b

Please sign in to comment.