Skip to content

Commit 115f538

Browse files
committed
新增 Dockerfile、.dockerignore 和 .goreleaser.yaml 文件,配置 Docker 镜像构建和发布流程,同时更新 GitHub Actions 工作流以支持自动化构建和发布。
1 parent 5cd06e9 commit 115f538

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git
2+
.gitignore
3+
README.md
4+
Dockerfile
5+
.dockerignore
6+
*.md
7+
.github
8+
.idea
9+
.vscode

.github/workflows/action.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Releaser And Build Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
releaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
- name: Tag
21+
run: git fetch --force --tags
22+
- name: Setup Go
23+
uses: actions/setup-go@v4
24+
with:
25+
go-version: stable
26+
- name: Release
27+
uses: goreleaser/goreleaser-action@v4
28+
with:
29+
distribution: goreleaser
30+
version: latest
31+
args: release --clean
32+
33+
34+
docker:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
40+
- name: Docker meta
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: |
45+
ghcr.io/${{ github.repository }}
46+
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
47+
48+
- name: Set up QEMU
49+
uses: docker/setup-qemu-action@v3
50+
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
54+
- name: Login to GitHub Container Registry
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ghcr.io
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Login to Docker Hub
62+
uses: docker/login-action@v3
63+
with:
64+
username: ${{ secrets.DOCKERHUB_USERNAME }}
65+
password: ${{ secrets.DOCKERHUB_TOKEN }}
66+
67+
- name: Build and push
68+
uses: docker/build-push-action@v5
69+
with:
70+
context: .
71+
push: true
72+
platforms: linux/amd64,linux/arm64,linux/arm/v7
73+
build-args: |
74+
GITHUB_SHA=${{ github.sha }}
75+
tags: ${{ steps.meta.outputs.tags }}
76+
labels: ${{ steps.meta.outputs.labels }}

.goreleaser.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
before:
2+
hooks:
3+
# - go mod tidy
4+
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- windows
11+
- darwin
12+
goarch:
13+
- amd64
14+
- arm64
15+
- arm
16+
- "386"
17+
goarm:
18+
- "7"
19+
ignore:
20+
- goos: darwin
21+
goarch: arm
22+
- goos: windows
23+
goarch: arm
24+
- goos: darwin
25+
goarch: "386"
26+
mod_timestamp: '{{ .CommitTimestamp }}'
27+
flags:
28+
- -trimpath
29+
ldflags:
30+
- -s -w -X main.CurrentCommit={{ .ShortCommit }}
31+
32+
archives:
33+
- format: tar.gz
34+
name_template: >-
35+
{{ .ProjectName }}_
36+
{{- title .Os }}_
37+
{{- if eq .Arch "amd64" }}x86_64
38+
{{- else if eq .Arch "386" }}i386
39+
{{- else if eq .Arch "arm64" }}aarch64
40+
{{- else if eq .Arch "arm" }}armv7
41+
{{- else }}{{ .Arch }}{{ end }}
42+
format_overrides:
43+
- goos: windows
44+
format: zip
45+
46+
changelog:
47+
sort: asc
48+
filters:
49+
exclude:
50+
- '^docs:'
51+
- '^test:'
52+
- '^chore:'
53+
- Merge pull request
54+
- Merge branch

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:alpine AS builder
2+
WORKDIR /app
3+
COPY . .
4+
ARG GITHUB_SHA
5+
RUN echo "Building commit: ${GITHUB_SHA:0:7}" && \
6+
go mod tidy && \
7+
go build -ldflags="-s -w -X main.CurrentCommit=${GITHUB_SHA:0:7}" -o main .
8+
9+
FROM alpine
10+
ENV TZ=Asia/Shanghai
11+
RUN apk add --no-cache alpine-conf ca-certificates && \
12+
/usr/sbin/setup-timezone -z Asia/Shanghai && \
13+
apk del alpine-conf && \
14+
rm -rf /var/cache/apk/*
15+
COPY --from=builder /app/main /app/main
16+
CMD /app/main
17+
EXPOSE 5245

0 commit comments

Comments
 (0)