Skip to content

Commit

Permalink
fix: docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Sep 14, 2023
1 parent 35ebf4b commit 50f798d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
export COMMIT_TIME=$(git show -s --format=%ci $COMMIT_HASH)
export CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
- name: Build
run: mkdir -p ./temp && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/hitokoto-osc/notification-worker/config.BuildTag=$COMMIT_HASH -X github.com/hitokoto-osc/notification-worker/config.BuildTime=$CURRENT_TIME -X github.com/hitokoto-osc/notification-worker/config.CommitTime=$COMMIT_TIME -s -w --extldflags '-static -fpic'" -o ./temp/linux_amd64/hitokoto_notification_worker main.go
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/hitokoto-osc/notification-worker/config.BuildTag=$COMMIT_HASH -X github.com/hitokoto-osc/notification-worker/config.BuildTime=$CURRENT_TIME -X github.com/hitokoto-osc/notification-worker/config.CommitTime=$COMMIT_TIME -s -w --extldflags '-static -fpic'" -o ./notification-worker main.go
-
name: Build and push
uses: docker/build-push-action@v4
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ before:
- go mod download
# you may remove this if you don't need go generate
- go generate ./...
project_name: notification-worker
builds:
- env:
- CGO_ENABLED=0
Expand Down Expand Up @@ -56,7 +57,7 @@ dockers:
- "hitokoto/notification-worker:latest"
- "hitokoto/notification-worker:{{ .Tag }}"
- "hitokoto/notification-worker:v{{ .Major }}"
dockerfile: Dockerfile
dockerfile: ./manifest/docker/Dockerfile
use: buildx
build_flag_templates:
- "--pull"
Expand Down
8 changes: 5 additions & 3 deletions manifest/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ RUN apk add alpine-conf tzdata && \
apk del alpine-conf

ENV WORKDIR /app
ADD ./temp/linux_amd64/hitokoto_notification_worker $WORKDIR/hitokoto_notification_worker
RUN chmod +x $WORKDIR/hitokoto_notification_worker
VOLUME $WORKDIR/data
ADD ./config.example.yml $WORKDIR/config.yml
ADD ./notification-worker $WORKDIR/notification-worker
RUN chmod +x $WORKDIR/notification-worker

###############################################################################
# START
###############################################################################
WORKDIR $WORKDIR
CMD ["./hitokoto_notification_worker"]
CMD ["./notification-worker"]

0 comments on commit 50f798d

Please sign in to comment.