Skip to content

Commit cd8ddae

Browse files
authored
refactor server command (#206)
1 parent 8f2830a commit cd8ddae

File tree

27 files changed

+1218
-674
lines changed

27 files changed

+1218
-674
lines changed

.github/workflows/release.yml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,53 @@ on:
66
- 'v*'
77

88
env:
9-
ENABLE_UPX: 1
9+
IMAGE_NAME: ${{ github.repository }}
1010

1111
jobs:
1212
release:
13-
name: Release Binary
13+
name: Release Binary and Docker
1414
runs-on: ubuntu-latest
1515
container:
1616
image: goreleaser/goreleaser-cross:v1.24
17+
permissions:
18+
contents: write
19+
packages: write
20+
id-token: write
21+
1722
steps:
1823
- name: Checkout
1924
uses: actions/checkout@v4
2025
with:
2126
fetch-depth: 0
22-
- run: git config --global --add safe.directory "$(pwd)"
27+
28+
- name: Fix git permissions
29+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
2330

24-
- name: Setup Go
25-
uses: actions/setup-go@v4
31+
- name: Install UPX
32+
uses: crazy-max/ghaction-upx@v3
2633
with:
27-
go-version: '^1.24'
34+
install-only: true
35+
36+
- name: Set up QEMU
37+
uses: docker/setup-qemu-action@v3
2838

29-
- name: Cache go module
30-
uses: actions/cache@v3
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Log in to GitHub Container Registry
43+
uses: docker/login-action@v3
3144
with:
32-
path: ~/go/pkg/mod
33-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
34-
restore-keys: |
35-
${{ runner.os }}-go-
45+
registry: ghcr.io
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
3648

37-
- name: Install UPX
38-
uses: crazy-max/ghaction-upx@v3
49+
- name: Log in to Docker Hub
50+
uses: docker/login-action@v3
3951
with:
40-
install-only: true
52+
username: ${{ secrets.DOCKERHUB_USERNAME }}
53+
password: ${{ secrets.DOCKERHUB_TOKEN }}
4154

4255
- name: Run GoReleaser
4356
run: goreleaser release --clean
4457
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
ENABLE_UPX: true
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 146 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,79 @@ before:
66
- go mod tidy
77

88
builds:
9-
- id: darwin-amd64
9+
- id: chatlog-builds
1010
binary: chatlog
11-
env:
12-
- CGO_ENABLED=1
13-
- CC=o64-clang
14-
- CXX=o64-clang++
15-
goos:
16-
- darwin
17-
goarch:
18-
- amd64
1911
ldflags:
2012
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
21-
22-
- id: darwin-arm64
23-
binary: chatlog
2413
env:
2514
- CGO_ENABLED=1
26-
- CC=oa64-clang
27-
- CXX=oa64-clang++
2815
goos:
2916
- darwin
30-
goarch:
31-
- arm64
32-
ldflags:
33-
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
34-
35-
- id: windows-amd64
36-
binary: chatlog
37-
env:
38-
- CGO_ENABLED=1
39-
- CC=x86_64-w64-mingw32-gcc
40-
- CXX=x86_64-w64-mingw32-g++
41-
goos:
4217
- windows
18+
- linux
4319
goarch:
4420
- amd64
45-
ldflags:
46-
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
47-
48-
- id: windows-arm64
49-
binary: chatlog
50-
env:
51-
- CGO_ENABLED=1
52-
- CC=/llvm-mingw/bin/aarch64-w64-mingw32-gcc
53-
- CXX=/llvm-mingw/bin/aarch64-w64-mingw32-g++
54-
goos:
55-
- windows
56-
goarch:
5721
- arm64
58-
ldflags:
59-
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
22+
overrides:
23+
- goos: darwin
24+
goarch: amd64
25+
env:
26+
- CGO_ENABLED=1
27+
- CC=o64-clang
28+
- CXX=o64-clang++
29+
- goos: darwin
30+
goarch: arm64
31+
env:
32+
- CGO_ENABLED=1
33+
- CC=oa64-clang
34+
- CXX=oa64-clang++
35+
- goos: windows
36+
goarch: amd64
37+
env:
38+
- CGO_ENABLED=1
39+
- CC=x86_64-w64-mingw32-gcc
40+
- CXX=x86_64-w64-mingw32-g++
41+
- goos: windows
42+
goarch: arm64
43+
env:
44+
- CGO_ENABLED=1
45+
- CC=/llvm-mingw/bin/aarch64-w64-mingw32-gcc
46+
- CXX=/llvm-mingw/bin/aarch64-w64-mingw32-g++
47+
- goos: linux
48+
goarch: amd64
49+
env:
50+
- CGO_ENABLED=1
51+
- CC=x86_64-linux-gnu-gcc
52+
- CXX=x86_64-linux-gnu-g++
53+
- goos: linux
54+
goarch: arm64
55+
env:
56+
- CGO_ENABLED=1
57+
- CC=aarch64-linux-gnu-gcc
58+
- CXX=aarch64-linux-gnu-g++
59+
60+
upx:
61+
- enabled: true
62+
goos: [darwin, windows, linux]
63+
goarch: [amd64, arm64]
64+
compress: best
65+
lzma: true
6066

6167
archives:
6268
- id: default
63-
format: tar.gz
69+
formats: tar.gz
6470
name_template: >-
6571
{{ .ProjectName }}_
6672
{{- .Version }}_
6773
{{- .Os }}_
6874
{{- .Arch }}
6975
format_overrides:
7076
- goos: windows
71-
format: zip
77+
formats: zip
7278
files:
7379
- LICENSE
7480
- README.md
7581

76-
upx:
77-
- enabled: "{{ .Env.ENABLE_UPX }}"
78-
goos: [darwin, windows]
79-
goarch: [amd64]
80-
compress: best
81-
8282
checksum:
8383
name_template: 'checksums.txt'
8484
algorithm: sha256
@@ -88,3 +88,101 @@ release:
8888
draft: true
8989
prerelease: auto
9090
mode: replace
91+
92+
# Docker 镜像配置
93+
dockers:
94+
# GitHub Container Registry
95+
- image_templates:
96+
- "ghcr.io/sjzar/chatlog:{{ .Tag }}-amd64"
97+
- "ghcr.io/sjzar/chatlog:latest-amd64"
98+
dockerfile: Dockerfile
99+
use: buildx
100+
goos: linux
101+
goarch: amd64
102+
build_flag_templates:
103+
- "--platform=linux/amd64"
104+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
105+
- "--label=org.opencontainers.image.description=chat log tool, easily use your own chat data."
106+
- "--label=org.opencontainers.image.url=https://github.com/sjzar/chatlog"
107+
- "--label=org.opencontainers.image.source=https://github.com/sjzar/chatlog"
108+
- "--label=org.opencontainers.image.version={{.Version}}"
109+
- "--label=org.opencontainers.image.created={{.Date}}"
110+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
111+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
112+
113+
- image_templates:
114+
- "ghcr.io/sjzar/chatlog:{{ .Tag }}-arm64"
115+
- "ghcr.io/sjzar/chatlog:latest-arm64"
116+
dockerfile: Dockerfile
117+
use: buildx
118+
goos: linux
119+
goarch: arm64
120+
build_flag_templates:
121+
- "--platform=linux/arm64"
122+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
123+
- "--label=org.opencontainers.image.description=chat log tool, easily use your own chat data."
124+
- "--label=org.opencontainers.image.url=https://github.com/sjzar/chatlog"
125+
- "--label=org.opencontainers.image.source=https://github.com/sjzar/chatlog"
126+
- "--label=org.opencontainers.image.version={{.Version}}"
127+
- "--label=org.opencontainers.image.created={{.Date}}"
128+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
129+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
130+
131+
# Docker Hub
132+
- image_templates:
133+
- "sjzar/chatlog:{{ .Tag }}-amd64"
134+
- "sjzar/chatlog:latest-amd64"
135+
dockerfile: Dockerfile
136+
use: buildx
137+
goos: linux
138+
goarch: amd64
139+
build_flag_templates:
140+
- "--platform=linux/amd64"
141+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
142+
- "--label=org.opencontainers.image.description=chat log tool, easily use your own chat data."
143+
- "--label=org.opencontainers.image.url=https://github.com/sjzar/chatlog"
144+
- "--label=org.opencontainers.image.source=https://github.com/sjzar/chatlog"
145+
- "--label=org.opencontainers.image.version={{.Version}}"
146+
- "--label=org.opencontainers.image.created={{.Date}}"
147+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
148+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
149+
150+
- image_templates:
151+
- "sjzar/chatlog:{{ .Tag }}-arm64"
152+
- "sjzar/chatlog:latest-arm64"
153+
dockerfile: Dockerfile
154+
use: buildx
155+
goos: linux
156+
goarch: arm64
157+
build_flag_templates:
158+
- "--platform=linux/arm64"
159+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
160+
- "--label=org.opencontainers.image.description=chat log tool, easily use your own chat data."
161+
- "--label=org.opencontainers.image.url=https://github.com/sjzar/chatlog"
162+
- "--label=org.opencontainers.image.source=https://github.com/sjzar/chatlog"
163+
- "--label=org.opencontainers.image.version={{.Version}}"
164+
- "--label=org.opencontainers.image.created={{.Date}}"
165+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
166+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
167+
168+
# Docker manifest 配置用于多架构镜像
169+
docker_manifests:
170+
# GitHub Container Registry manifests
171+
- name_template: "ghcr.io/sjzar/chatlog:{{ .Tag }}"
172+
image_templates:
173+
- "ghcr.io/sjzar/chatlog:{{ .Tag }}-amd64"
174+
- "ghcr.io/sjzar/chatlog:{{ .Tag }}-arm64"
175+
- name_template: "ghcr.io/sjzar/chatlog:latest"
176+
image_templates:
177+
- "ghcr.io/sjzar/chatlog:latest-amd64"
178+
- "ghcr.io/sjzar/chatlog:latest-arm64"
179+
180+
# Docker Hub manifests
181+
- name_template: "sjzar/chatlog:{{ .Tag }}"
182+
image_templates:
183+
- "sjzar/chatlog:{{ .Tag }}-amd64"
184+
- "sjzar/chatlog:{{ .Tag }}-arm64"
185+
- name_template: "sjzar/chatlog:latest"
186+
image_templates:
187+
- "sjzar/chatlog:latest-amd64"
188+
- "sjzar/chatlog:latest-arm64"

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM debian:12-slim
2+
3+
LABEL maintainer="Sarv <https://github.com/sjzar>"
4+
5+
ARG DEBIAN_FRONTEND=noninteractive
6+
7+
RUN apt-get update && \
8+
apt-get install -y --no-install-recommends ca-certificates tzdata curl && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
RUN groupadd -r -g 1001 chatlog && \
12+
useradd -r -u 1001 -g chatlog -m -d /home/chatlog chatlog && \
13+
mkdir -p /app/data /app/work && \
14+
chown -R chatlog:chatlog /app
15+
16+
USER chatlog
17+
18+
WORKDIR /app
19+
20+
COPY --from=mwader/static-ffmpeg:7.1.1 --chown=chatlog:chatlog /ffmpeg /usr/local/bin/
21+
22+
COPY --chown=chatlog:chatlog chatlog /usr/local/bin/chatlog
23+
24+
EXPOSE 5030
25+
26+
ENV CHATLOG_DATA_DIR=/app/data \
27+
CHATLOG_WORK_DIR=/app/work \
28+
CHATLOG_HTTP_ADDR=0.0.0.0:5030 \
29+
PATH="/usr/local/bin:${PATH}"
30+
31+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
32+
CMD curl -f http://localhost:5030/health || exit 1
33+
34+
CMD ["chatlog", "server"]

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ LDFLAGS := -ldflags '-X "github.com/sjzar/chatlog/pkg/version.Version=$(VERSION)
88
PLATFORMS := \
99
darwin/amd64 \
1010
darwin/arm64 \
11+
linux/amd64 \
12+
linux/arm64 \
1113
windows/amd64 \
1214
windows/arm64
1315

1416
UPX_PLATFORMS := \
1517
darwin/amd64 \
16-
windows/386 \
18+
linux/amd64 \
19+
linux/arm64 \
1720
windows/amd64
1821

1922
.PHONY: all clean lint tidy test build crossbuild upx

0 commit comments

Comments
 (0)