-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (83 loc) · 2.33 KB
/
deploy.yml
File metadata and controls
99 lines (83 loc) · 2.33 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
95
96
97
98
99
name: Rails CI/CD Deploy
on:
push:
branches:
- main
paths:
- "config/specs/**"
- "app/**"
- "config/**"
- "db/**"
- "lib/**"
- "Gemfile"
- "Gemfile.lock"
- "Dockerfile"
- "config/deploy.yml"
- ".github/workflows/deploy.yml"
workflow_dispatch:
jobs:
test:
name: Validate and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Validate business spec
run: bundle exec rake specs:validate
- name: Run tests
run: bundle exec rails test
env:
RAILS_ENV: test
deploy:
name: Deploy to Lightsail
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.LIGHTSAIL_SSH_KEY }}" > ~/.ssh/lightsail_key
chmod 600 ~/.ssh/lightsail_key
ssh-keygen -R "${{ vars.LIGHTSAIL_HOST }}" || true
ssh-keyscan "${{ vars.LIGHTSAIL_HOST }}" >> ~/.ssh/known_hosts
cat > ~/.ssh/config <<EOF
Host ${{ vars.LIGHTSAIL_HOST }}
User ubuntu
IdentityFile ~/.ssh/lightsail_key
IdentitiesOnly yes
StrictHostKeyChecking yes
EOF
chmod 600 ~/.ssh/config
- name: Start ssh-agent
run: |
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/lightsail_key
- name: Write Kamal secrets
run: |
mkdir -p .kamal
cat > .kamal/secrets <<EOF
RAILS_MASTER_KEY=${{ secrets.RAILS_MASTER_KEY }}
KAMAL_REGISTRY_PASSWORD=${{ secrets.GHCR_TOKEN }}
EOF
- name: Deploy with Kamal
run: bundle exec kamal deploy