Skip to content

Commit

Permalink
Switch CI build process to use docker
Browse files Browse the repository at this point in the history
This also ensures that assets can be built properly so that UI tests
pass.
  • Loading branch information
timcowlishaw committed Dec 21, 2024
1 parent 076ba6f commit 20582bd
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 67 deletions.
76 changes: 15 additions & 61 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,26 @@ name: Ruby
on: [push]

jobs:
docker_build:
name: Build Dockerfile
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Build the Dockerfile
run: docker build -t app .
build:
name: The Build
name: Build and test
runs-on: ubuntu-latest

services:
redis:
image: redis:4
ports:
- 6379:6379
postgres:
image: postgres:10
env:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports: ["5432:5432"]
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/[email protected]
- uses: actions/checkout@v3
- name: Copy .env file
uses: canastro/copy-file-action@master
with:
source: "env.example"
target: ".env"

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Build the Stack
run: "docker compose build"

- name: Show available Ruby versions
run: |
ls $RUNNER_TOOL_CACHE/Ruby
uname -a
cat /etc/os-release
- name: Start dependencies
run: "docker compose up -d --no-deps db redis app"

- name: Install required packages
run: sudo apt-get install libpq-dev
- name: Run all tests
run: "docker compose exec app ./ci.sh"

- name: Test
run: |
RAILS_ENV=test bundle exec rails db:create
RAILS_ENV=test bundle exec rails db:schema:load
bundle exec rake
env:
#Note: DATABASE_URL does not work in TEST env.
TEST_DB_HOST: localhost
TEST_DB_USERNAME: postgres
TEST_DB_PASSWORD: postgres
TEST_DB_NAME: postgres
discourse_sso_secret: "secret"
discourse_endpoint: "https://example.com"
PG_PORT: ${{ job.services.postgres.ports['5432'] }}
- name: Teardown the stack
run: "docker compose down"

#- name: Deploy to server via SSH
#uses: appleboy/ssh-action@master
#with:
#host: ${{ secrets.HOST }}
#key: ${{ secrets.KEY }}
#port: ${{ secrets.PORT }}
#username: ${{ secrets.USERNAME }}
#script: |
#cd smartcitizen-api
#pwd
#./scripts/deploy.sh
#if: github.ref == 'refs/heads/master' && job.status == 'success'
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ARG BUNDLE_WITHOUT
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
RUN bundle install


COPY package.json yarn.lock /app/
RUN . $NVM_DIR/nvm.sh && nvm use default && yarn install

# Copy the Rails application into place
COPY . /app

Expand Down
13 changes: 13 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -ae
git config --global --add safe.directory /app
source $NVM_DIR/nvm.sh
nvm use default
yarn install
NODE_OPTIONS=--openssl-legacy-provider bundle exec bin/rake assets:precompile
bundle exec bin/rake db:create
bundle exec bin/rake db:schema:load
unset DATABASE_URL
RAILS_ENV=test bundle exec bin/rake db:create
RAILS_ENV=test bundle exec bin/rake db:schema:load
bundle exec bin/rake spec
2 changes: 0 additions & 2 deletions compose.override.local.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
services:
app:
build:
args: !reset []
restart: "no"
sidekiq:
restart: "no"
Expand Down
12 changes: 12 additions & 0 deletions compose.override.production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.3'
services:
app:
build:
args:
- BUNDLE_WITHOUT=test development
mqtt:
entrypoint: ["echo", "MQTT service disabled in production"]
cassandra-1:
entrypoint: ["echo", "Cassandra service disabled in production"]
kairos:
depends_on: !reset []
27 changes: 27 additions & 0 deletions compose.override.staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
services:
db:
deploy:
resources:
limits:
memory: 2gb
app:
build:
args:
- BUNDLE_WITHOUT=test development
mqtt:
entrypoint: ["echo", "MQTT service disabled on staging"]
mqtt-task-main-1:
environment:
MQTT_CLIENT_ID: smartcitizen-staging-api-main-1
mqtt-task-main-2:
environment:
MQTT_CLIENT_ID: smartcitizen-staging-api-main-2
mqtt-task-secondary:
environment:
MQTT_CLIENT_ID: "smartcitizen-staging-api-secondary"


# cassandra-1:
# entrypoint: ["echo", "Cassandra service disabled on staging"]
# kairos:
# depends_on: !reset []
4 changes: 0 additions & 4 deletions compose/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ services:
app:
build:
context: ../.
# Skip installing development & test gems in production, saves 20s build time.
# If developing with Docker, this line might need to be commented out.
args:
- BUNDLE_WITHOUT=test development
env_file: ../.env
ports:
- "3000:3000"
Expand Down
5 changes: 5 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ DATABASE_URL=postgresql://postgres:postgres@db/sc_dev

TEST_DB_HOST=db
TEST_DB_USERNAME=postgres
TEST_DB_PASSWORD=postgres

# Tell sidekiq to use hostname redis, not localhost
# If this var is set, Redis uses it by default. No config needed
Expand Down Expand Up @@ -44,3 +45,7 @@ PROMETHEUS_URL=
PROMETHEUS_USERNAME=
PROMETHEUS_PASSWORD=
PROMETHEUS_INSTANCE_LABEL=


discourse_sso_secret="InsertDiscourseSSOSecretHERE"
discourse_endpoint="http://example.com"

0 comments on commit 20582bd

Please sign in to comment.