Skip to content

Commit 5149012

Browse files
committed
cd: add build workflow
1 parent 147b1cc commit 5149012

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Deploy
1+
name: Build
22

33
on:
44
workflow_dispatch:

.github/workflows/deploy.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Deploy
2+
3+
on:
4+
workflow_run:
5+
workflows: ["build.yml"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
deploy:
11+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set deployment variables
19+
id: vars
20+
# set to feature/continuous for now, must be staging
21+
run: |
22+
if [[ "${{ github.event.workflow_run.head_branch }}" == "feature/continuous" ]]; then
23+
echo "target_dir=~/ladder-staging-new" >> "$GITHUB_OUTPUT"
24+
echo "compose_file=docker-compose.yml" >> "$GITHUB_OUTPUT"
25+
elif [[ "${{ github.event.workflow_run.head_branch }}" == "main" ]]; then
26+
echo "target_dir=~/ladder" >> "$GITHUB_OUTPUT"
27+
echo "compose_file=docker-compose.yml" >> "$GITHUB_OUTPUT"
28+
else
29+
echo "Unsupported branch"
30+
exit 1
31+
fi
32+
33+
- name: Copy compose file to server
34+
uses: appleboy/scp-action@v0.1.7
35+
with:
36+
host: ${{ secrets.SSH_HOST }}
37+
username: ${{ secrets.SSH_USER }}
38+
key: ${{ secrets.SSH_PRIVATE_KEY }}
39+
source: ${{ steps.vars.outputs.compose_file }}
40+
target: ${{ steps.vars.outputs.target_dir }}
41+
42+
- name: Stop and start app on server
43+
uses: appleboy/ssh-action@v1.2.1
44+
with:
45+
host: ${{ secrets.SSH_HOST }}
46+
username: ${{ secrets.SSH_USER }}
47+
key: ${{ secrets.SSH_PRIVATE_KEY }}
48+
script: |
49+
cd ${{ steps.vars.outputs.target_dir }}
50+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
51+
docker compose -f ${{ steps.vars.outputs.compose_file }} down
52+
docker compose -f ${{ steps.vars.outputs.compose_file }} pull
53+
docker compose -f ${{ steps.vars.outputs.compose_file }} up -d

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ services:
99
XDG_CONFIG_HOME: /app/.config
1010
XDG_DATA_HOME: /app/.data
1111
volumes:
12-
- caddy_data:/data
13-
- caddy_config:/config
14-
- ./cncnet-api/storage:/app/storage
12+
- ./caddy/data:/data
13+
- ./caddy/config:/config
14+
- ./storage:/app/storage
1515
ports:
1616
- '${APP_PORT:-3000}:8000'
1717
depends_on:

0 commit comments

Comments
 (0)