ci: restore persistent production deployment
Verify and deploy production / verify-and-deploy (push) Has been cancelled
Verify and deploy production / verify-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
name: Verify and deploy production
|
||||
|
||||
concurrency:
|
||||
group: rednote-tool-studio-production
|
||||
cancel-in-progress: false
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
verify-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
container: node:24-bookworm-slim
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Type check
|
||||
run: npm run typecheck
|
||||
|
||||
- name: Unit tests
|
||||
run: npm test
|
||||
|
||||
- name: Production build
|
||||
run: npm run build
|
||||
|
||||
- name: Deploy persistent production container
|
||||
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
||||
env:
|
||||
STUDIO_USERNAME: studio
|
||||
STUDIO_PASSWORD: ${{ secrets.STUDIO_PASSWORD }}
|
||||
DEPLOY_PORT: ${{ vars.DEPLOY_PORT }}
|
||||
DEPLOY_DOCKERFILE: Dockerfile.deploy
|
||||
GITHUB_SHA: ${{ gitea.sha }}
|
||||
run: |
|
||||
if [ -z "$STUDIO_PASSWORD" ]; then
|
||||
echo "STUDIO_PASSWORD repository secret is required for production deployment"
|
||||
exit 1
|
||||
fi
|
||||
node scripts/deploy.mjs
|
||||
|
||||
- name: Verify persistent deployment settings
|
||||
if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
||||
run: |
|
||||
node --input-type=module <<'JS'
|
||||
import Docker from "dockerode";
|
||||
|
||||
const docker = new Docker({ socketPath: "/var/run/docker.sock" });
|
||||
const container = docker.getContainer("rednote-tool-studio");
|
||||
const state = await container.inspect();
|
||||
const restartPolicy = state.HostConfig.RestartPolicy?.Name;
|
||||
const health = state.State.Health?.Status;
|
||||
const dataMount = state.Mounts?.find((mount) => mount.Destination === "/app/data/projects");
|
||||
|
||||
if (!state.State.Running) throw new Error("Production container is not running");
|
||||
if (health !== "healthy") throw new Error(`Production container health is ${health || "unavailable"}`);
|
||||
if (restartPolicy !== "unless-stopped") throw new Error(`Unexpected restart policy: ${restartPolicy || "none"}`);
|
||||
if (dataMount?.Type !== "volume" || dataMount.Name !== "rednote-tool-studio-data") {
|
||||
throw new Error("Persistent project data volume is not mounted correctly");
|
||||
}
|
||||
|
||||
console.log(`Persistent deployment verified: health=${health}, restart=${restartPolicy}, volume=${dataMount.Name}`);
|
||||
JS
|
||||
Reference in New Issue
Block a user