-
Notifications
You must be signed in to change notification settings - Fork 19
83 lines (69 loc) · 2.49 KB
/
deploy.yml
File metadata and controls
83 lines (69 loc) · 2.49 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
# Kamal deployment workflow
# Deploys to production after CI workflow passes on main branch
name: Deploy
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
workflow_dispatch: # Allow manual deployment
jobs:
deploy:
name: Deploy to production
runs-on: ubuntu-latest
environment: Production
# Only run if CI passed (or manual trigger)
if: >
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/zainfathoni/kelas.rumahberbagi.com:${{ github.sha }}
ghcr.io/zainfathoni/kelas.rumahberbagi.com:latest
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
- name: Set up Ruby for Kamal
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
- name: Install Kamal
run: gem install kamal
- name: Set up SSH agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add VPS to known hosts
run: ssh-keyscan -t rsa,ecdsa,ed25519 103.235.75.227 >> ~/.ssh/known_hosts
- name: Test SSH connection
run: ssh -o StrictHostKeyChecking=no root@103.235.75.227 "echo SSH connection successful"
- name: Create Kamal secrets file
run: |
mkdir -p .kamal
cat > .kamal/secrets << EOF
KAMAL_REGISTRY_PASSWORD=${{ secrets.KAMAL_REGISTRY_PASSWORD }}
SESSION_SECRET=${{ secrets.SESSION_SECRET }}
MAGIC_LINK_SECRET=${{ secrets.MAGIC_LINK_SECRET }}
MAILGUN_SENDING_KEY=${{ secrets.MAILGUN_SENDING_KEY }}
MAILGUN_DOMAIN=${{ secrets.MAILGUN_DOMAIN }}
EOF
- name: Deploy with Kamal
run: kamal deploy --skip-push --version ${{ github.sha }}
env:
KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}