Skip to content

Commit f517efc

Browse files
committed
feat: docker build
1 parent 640ec98 commit f517efc

5 files changed

Lines changed: 269 additions & 188 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
IMAGE_TAG=latest
2+
13
SPEEDTEST_SITE_TITLE=SpeedTest Next
24
SPEEDTEST_GITHUB_URL=https://github.com/taurusxin/speedtest-next
35
SPEEDTEST_TARGET_IPV4=speedtest-v4only.taurusxin.com
46
SPEEDTEST_TARGET_IPV6=speedtest-v6only.taurusxin.com
57

68
# 可选配置项
9+
# SPEEDTEST_ALLOWED_ORIGINS=https://speedtest.taurusxin.com,https://speedtest-v4only.taurusxin.com
710
# SPEEDTEST_LATENCY_SAMPLE_COUNT=10
811
# SPEEDTEST_LATENCY_SAMPLE_GAP_MS=160
912
# SPEEDTEST_DOWNLOAD_CONCURRENCY=6

.github/workflows/release.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-release-assets:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- goos: linux
19+
goarch: amd64
20+
archive: tar.gz
21+
- goos: linux
22+
goarch: arm64
23+
archive: tar.gz
24+
- goos: darwin
25+
goarch: amd64
26+
archive: tar.gz
27+
- goos: darwin
28+
goarch: arm64
29+
archive: tar.gz
30+
- goos: windows
31+
goarch: amd64
32+
archive: zip
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: "20"
42+
43+
- name: Setup pnpm
44+
uses: pnpm/action-setup@v4
45+
with:
46+
version: 10
47+
48+
- name: Setup Go
49+
uses: actions/setup-go@v5
50+
with:
51+
go-version-file: go.mod
52+
53+
- name: Install frontend dependencies
54+
working-directory: web
55+
run: pnpm install --frozen-lockfile
56+
57+
- name: Build frontend
58+
working-directory: web
59+
run: pnpm build
60+
61+
- name: Build binary
62+
env:
63+
CGO_ENABLED: "0"
64+
GOOS: ${{ matrix.goos }}
65+
GOARCH: ${{ matrix.goarch }}
66+
run: |
67+
mkdir -p dist
68+
BINARY_NAME=speedtest-next
69+
if [ "${{ matrix.goos }}" = "windows" ]; then
70+
BINARY_NAME=speedtest-next.exe
71+
fi
72+
go build -o "dist/${BINARY_NAME}" .
73+
74+
- name: Package tar.gz
75+
if: matrix.archive == 'tar.gz'
76+
run: |
77+
VERSION="${GITHUB_REF_NAME}"
78+
PACKAGE="speedtest-next_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz"
79+
tar -C dist -czf "$PACKAGE" .
80+
echo "PACKAGE=$PACKAGE" >> "$GITHUB_ENV"
81+
82+
- name: Package zip
83+
if: matrix.archive == 'zip'
84+
run: |
85+
VERSION="${GITHUB_REF_NAME}"
86+
PACKAGE="speedtest-next_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.zip"
87+
cd dist
88+
zip -r "../$PACKAGE" .
89+
cd ..
90+
echo "PACKAGE=$PACKAGE" >> "$GITHUB_ENV"
91+
92+
- name: Upload release asset
93+
uses: softprops/action-gh-release@v2
94+
with:
95+
files: ${{ env.PACKAGE }}
96+
97+
docker-image:
98+
runs-on: ubuntu-latest
99+
steps:
100+
- name: Checkout
101+
uses: actions/checkout@v4
102+
103+
- name: Set up QEMU
104+
uses: docker/setup-qemu-action@v3
105+
106+
- name: Set up Docker Buildx
107+
uses: docker/setup-buildx-action@v3
108+
109+
- name: Log in to Docker Hub
110+
uses: docker/login-action@v3
111+
with:
112+
username: ${{ secrets.DOCKERHUB_USERNAME }}
113+
password: ${{ secrets.DOCKERHUB_TOKEN }}
114+
115+
- name: Extract Docker metadata
116+
id: meta
117+
uses: docker/metadata-action@v5
118+
with:
119+
images: taurusxin/speedtest-next
120+
tags: |
121+
type=ref,event=tag
122+
type=raw,value=latest
123+
124+
- name: Build and push Docker image
125+
uses: docker/build-push-action@v6
126+
with:
127+
context: .
128+
file: ./Dockerfile
129+
platforms: linux/amd64,linux/arm64
130+
push: true
131+
tags: ${{ steps.meta.outputs.tags }}
132+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)