Skip to content

Commit edd8e8b

Browse files
Uriel AlonsoUriel Alonso
authored andcommitted
Add deploy workflow and fix specs task
1 parent 02768e6 commit edd8e8b

File tree

3 files changed

+98
-11
lines changed

3 files changed

+98
-11
lines changed

.github/workflows/deploy.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Rails CI/CD Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "config/specs/**"
9+
- "app/**"
10+
- "config/**"
11+
- "db/**"
12+
- "lib/**"
13+
- "Gemfile"
14+
- "Gemfile.lock"
15+
- "Dockerfile"
16+
- "config/deploy.yml"
17+
- ".github/workflows/deploy.yml"
18+
workflow_dispatch:
19+
20+
jobs:
21+
test:
22+
name: Validate and Test
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Ruby
30+
uses: ruby/setup-ruby@v1
31+
with:
32+
bundler-cache: true
33+
34+
- name: Validate business spec
35+
run: bundle exec rake specs:validate
36+
37+
- name: Run tests
38+
run: bundle exec rails test
39+
env:
40+
RAILS_ENV: test
41+
42+
deploy:
43+
name: Deploy to Lightsail
44+
runs-on: ubuntu-latest
45+
needs: test
46+
if: github.ref == 'refs/heads/main'
47+
environment: production
48+
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v4
52+
53+
- name: Set up Ruby
54+
uses: ruby/setup-ruby@v1
55+
with:
56+
bundler-cache: true
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
61+
- name: Log in to GHCR
62+
uses: docker/login-action@v3
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.repository_owner }}
66+
password: ${{ secrets.GHCR_TOKEN }}
67+
68+
- name: Set up SSH key
69+
run: |
70+
mkdir -p ~/.ssh
71+
echo "${{ secrets.LIGHTSAIL_SSH_KEY }}" > ~/.ssh/lightsail_key
72+
chmod 600 ~/.ssh/lightsail_key
73+
ssh-keyscan -H ${{ vars.LIGHTSAIL_HOST }} >> ~/.ssh/known_hosts
74+
75+
- name: Start ssh-agent
76+
run: |
77+
eval "$(ssh-agent -s)"
78+
ssh-add ~/.ssh/lightsail_key
79+
80+
- name: Write Kamal secrets
81+
run: |
82+
mkdir -p .kamal
83+
cat > .kamal/secrets <<EOF
84+
RAILS_MASTER_KEY=${{ secrets.RAILS_MASTER_KEY }}
85+
KAMAL_REGISTRY_PASSWORD=${{ secrets.GHCR_TOKEN }}
86+
EOF
87+
88+
- name: Run spec sync
89+
run: bundle exec rails specs:sync
90+
env:
91+
RAILS_ENV: production
92+
93+
- name: Deploy with Kamal
94+
run: bundle exec kamal deploy

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
# Ignore key files for decrypting credentials and more.
3434
/config/*.key
3535

36+
.DS_Store
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
require "yaml"
2+
13
namespace :specs do
24
desc "Validate business spec files"
35
task validate: :environment do
4-
require "yaml"
5-
66
spec_file = Rails.root.join("config/specs/business.yml")
77
data = YAML.load_file(spec_file)
88

@@ -16,18 +16,10 @@ namespace :specs do
1616

1717
desc "Sync business spec into app state"
1818
task sync: :environment do
19-
require "yaml"
20-
2119
spec_file = Rails.root.join("config/specs/business.yml")
22-
data = YAML.load_file(spec_file)
20+
YAML.load_file(spec_file)
2321

2422
puts "Applying business spec..."
25-
26-
# Example placeholders:
27-
# Setting.set("headline", data.dig("site", "headline"))
28-
# Setting.set("primary_cta_label", data.dig("site", "primary_cta_label"))
29-
# Setting.set("plan_name", data.dig("pricing", "plan_name"))
30-
3123
puts "Business spec applied"
3224
end
3325
end

0 commit comments

Comments
 (0)