forked from sfreeman422/mocker
-
Notifications
You must be signed in to change notification settings - Fork 3
94 lines (82 loc) · 3.24 KB
/
deploy.yml
File metadata and controls
94 lines (82 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Deploy
on:
push:
branches: [master]
paths:
- 'packages/backend/**'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.base.json'
# GITHUB_TOKEN needs write access to push the image to GHCR.
permissions:
contents: read
packages: write
jobs:
deploy:
name: Build, Push & Deploy
runs-on: ubuntu-latest
# Scoping to a GitHub environment lets you add approval gates and
# view deployment history in the GitHub UI (Settings > Environments).
environment: production
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '24.14.1'
- name: Generate release metadata
run: |
PREVIOUS_RELEASE_SHA="${{ github.event.before }}" \
node packages/backend/scripts/write-release-metadata.js packages/backend/release-metadata.json
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: packages/backend/Dockerfile
push: true
# Always push :latest so the Linode deploy script can reference a stable tag.
# The SHA tag gives you an immutable rollback point.
tags: |
ghcr.io/${{ github.repository_owner }}/muzzle:latest
ghcr.io/${{ github.repository_owner }}/muzzle:${{ github.sha }}
- name: Deploy to Linode
uses: appleboy/ssh-action@v1
# The env block sets these variables on the runner, and `envs` passes
# them through to the remote shell — keeping the token off the command
# line and out of the remote process list.
env:
GHCR_TOKEN: ${{ secrets.GHCR_PAT }}
GHCR_USER: ${{ github.actor }}
IMAGE: ghcr.io/${{ github.repository_owner }}/muzzle:latest
with:
host: ${{ secrets.LINODE_HOST }}
username: ${{ secrets.LINODE_USER }}
password: ${{ secrets.LINODE_PASSWORD }}
envs: GHCR_TOKEN,GHCR_USER,IMAGE
script: |
# Authenticate and pull the freshly built image.
echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USER" --password-stdin
docker pull "$IMAGE"
# Tear down the named container (if any)
docker stop muzzle 2>/dev/null || true
docker rm -f muzzle 2>/dev/null || true
# Hand off to your existing startup script which handles volume
# mounts and env var injection.
# Update this path to wherever the script lives on your Linode.
bash -lc '/home/muzzle.lol/start-muzzle.sh'
# Validate that the service stayed up; if not, print diagnostics.
sleep 3
if ! docker ps --format '{{.Names}}' | grep -qx 'muzzle'; then
echo "Container 'muzzle' is not running after startup"
docker ps -a --filter name=^/muzzle$
docker logs --tail 200 muzzle 2>/dev/null || true
exit 1
fi