Skip to content

Commit 0f9dfdb

Browse files
committed
Minimal production test on github
This commit splits up the existing ci.yml into multiple files, and adds a new test that tries to bring up the production webserver from scratch to make sure that it works.
1 parent c41507f commit 0f9dfdb

5 files changed

Lines changed: 81 additions & 19 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Docker Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
docker-build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Docker Buildx
15+
uses: docker/setup-buildx-action@v3
16+
- name: Build app image
17+
uses: docker/build-push-action@v5
18+
with:
19+
context: .
20+
file: Dockerfile
21+
push: false
22+
tags: hackorum:test

.github/workflows/prod-boot.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Prod Boot
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
prod-boot:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 25
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Prepare deploy env file
17+
run: |
18+
cp deploy/.env.example deploy/.env
19+
# Override secrets/SSL for CI boot
20+
ruby -e "require 'securerandom'; puts \"SECRET_KEY_BASE=#{SecureRandom.hex(64)}\"" >> deploy/.env
21+
echo "FORCE_SSL=false" >> deploy/.env
22+
echo "APP_HOST=localhost" >> deploy/.env
23+
# Copy Postgres config template and shrink memory settings
24+
cp deploy/postgres/postgresql.conf.example deploy/postgres/postgresql.conf
25+
sed -i 's/^shared_buffers = .*/shared_buffers = 128MB/' deploy/postgres/postgresql.conf
26+
sed -i 's/^effective_cache_size = .*/effective_cache_size = 256MB/' deploy/postgres/postgresql.conf
27+
sed -i 's/^work_mem = .*/work_mem = 4MB/' deploy/postgres/postgresql.conf
28+
sed -i 's/^maintenance_work_mem = .*/maintenance_work_mem = 64MB/' deploy/postgres/postgresql.conf
29+
30+
- name: Start database
31+
run: docker compose -f deploy/docker-compose.yml up -d db
32+
33+
- name: Prepare database (migrations)
34+
run: docker compose -f deploy/docker-compose.yml run --rm web bin/rails db:prepare
35+
36+
- name: Start web
37+
run: docker compose -f deploy/docker-compose.yml up -d web
38+
39+
- name: Verify web healthcheck
40+
run: |
41+
for i in {1..30}; do
42+
if docker compose -f deploy/docker-compose.yml exec web sh -lc "curl -fs http://localhost:3000/up"; then
43+
exit 0
44+
fi
45+
sleep 5
46+
done
47+
docker compose -f deploy/docker-compose.yml logs --tail=200 web db
48+
exit 1
49+
50+
- name: Teardown
51+
if: always()
52+
run: docker compose -f deploy/docker-compose.yml down -v
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Tests
22

33
on:
44
push:
@@ -46,17 +46,3 @@ jobs:
4646

4747
- name: Run specs
4848
run: bundle exec rspec
49-
50-
docker-build:
51-
runs-on: ubuntu-latest
52-
steps:
53-
- uses: actions/checkout@v4
54-
- name: Set up Docker Buildx
55-
uses: docker/setup-buildx-action@v3
56-
- name: Build app image
57-
uses: docker/build-push-action@v5
58-
with:
59-
context: .
60-
file: Dockerfile
61-
push: false
62-
tags: hackorum:test

config/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test:
6565
production:
6666
primary: &primary_production
6767
<<: *default
68-
database: hackorum_production
68+
database: hackorum
6969
username: hackorum
7070
password: <%= ENV["HACKORUM_DATABASE_PASSWORD"] %>
7171
cache:

deploy/.env.example

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ RAILS_SERVE_STATIC_FILES=1
66
SECRET_KEY_BASE=change-me
77

88
# Database (used by DATABASE_URL below)
9-
POSTGRES_USER=postgres
10-
POSTGRES_PASSWORD=postgres
9+
POSTGRES_USER=hackorum
10+
POSTGRES_PASSWORD=hackorum
1111
POSTGRES_DB=hackorum
12-
DATABASE_URL=postgresql://postgres:postgres@db:5432/hackorum
12+
# Keep it in sync with the above parameters!
13+
DATABASE_URL=postgresql://hackorum:hackorum@db:5432/hackorum
14+
HACKORUM_DATABASE_PASSWORD=hackorum
1315

1416
# IMAP ingestion
1517
IMAP_USERNAME=you@example.com

0 commit comments

Comments
 (0)