M004: close Docker and deployment workflow

This commit is contained in:
illusia committed 2026-09-01 17:02:54 +08:00
1 parent 3cca211ae9
commit 3397e90749
9 files changed
+238 -7

No files matched your search

+11 -4
View File
@@ -26,12 +26,16 @@ jobs:
web/package-lock.json
- name: Build application
shell: pwsh
env:
RELEASE_VERSION: ${{ inputs.version }}
run: |
$ErrorActionPreference = "Stop"
npm ci --no-audit --no-fund
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
npm --prefix web ci --no-audit --no-fund
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
npm version --no-git-tag-version $env:RELEASE_VERSION
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
npm --prefix web run build
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
npm run build
@@ -71,7 +75,7 @@ jobs:
$smokeRoot = Join-Path $env:RUNNER_TEMP ($packageName + "-smoke")
Copy-Item -Recurse -LiteralPath $packageRoot -Destination $smokeRoot
@{
port = 31440
port = 3040
tsHost = "203.0.113.10"
tsPort = 9987
tsServerPassword = ""
@@ -85,7 +89,7 @@ jobs:
$health = $null
for ($attempt = 0; $attempt -lt 30 -and -not $health; $attempt++) {
Start-Sleep -Milliseconds 500
try { $health = Invoke-RestMethod -Uri "http://127.0.0.1:31440/api/health" -TimeoutSec 2 } catch {}
try { $health = Invoke-RestMethod -Uri "http://127.0.0.1:3040/api/health" -TimeoutSec 2 } catch {}
}
if (-not $health -or $health.status -ne "ok" -or $health.version -ne $env:RELEASE_VERSION) {
throw "Windows release health check failed"
@@ -113,10 +117,13 @@ jobs:
package-lock.json
web/package-lock.json
- name: Build application
env:
RELEASE_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
npm ci --no-audit --no-fund
npm --prefix web ci --no-audit --no-fund
npm version --no-git-tag-version "$RELEASE_VERSION"
npm --prefix web run build
npm run build
npm prune --omit=dev --no-audit --no-fund
@@ -148,7 +155,7 @@ jobs:
cp -a "$package_root" "$smoke_root"
cat > "$smoke_root/config.json" <<'CONFIG'
{
"port": 31441,
"port": 3040,
"tsHost": "203.0.113.10",
"tsPort": 9987,
"tsServerPassword": "",
@@ -164,7 +171,7 @@ jobs:
trap 'kill "$app_pid" 2>/dev/null || true; wait "$app_pid" 2>/dev/null || true' EXIT
health=""
for _ in $(seq 1 30); do
health="$(curl -fsS --max-time 2 http://127.0.0.1:31441/api/health 2>/dev/null || true)"
health="$(curl -fsS --max-time 2 http://127.0.0.1:3040/api/health 2>/dev/null || true)"
if grep -q '"status":"ok"' <<<"$health" && grep -q "\"version\":\"$RELEASE_VERSION\"" <<<"$health"; then break; fi
sleep 0.5
done
+52
View File
@@ -0,0 +1,52 @@
name: Continuous integration
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.22.2
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
- name: Install dependencies
run: |
npm ci --no-audit --no-fund
npm --prefix web ci --no-audit --no-fund
- name: Test and build
run: |
npm test
npm run build
npm --prefix web run build
docker-smoke:
needs: verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Build image
run: docker build --tag webspeak:ci .
- name: Run health smoke test
run: |
set -euo pipefail
docker run --detach --name webspeak-ci --publish 3040:3040 webspeak:ci
trap 'docker logs webspeak-ci; docker rm --force webspeak-ci' EXIT
for attempt in $(seq 1 30); do
if curl --fail --silent http://127.0.0.1:3040/health | grep -q '"status":"ok"'; then
exit 0
fi
sleep 2
done
exit 1
+45
View File
@@ -0,0 +1,45 @@
name: Publish Docker image
on:
push:
branches: [main]
tags: ["v*.*.*"]
workflow_dispatch:
permissions:
contents: read
packages: write
env:
IMAGE_NAME: ghcr.io/echosixhiya/webspeak
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=tag
type=sha
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max