Skip to content

Commit

Permalink
Run CI with docker compose
Browse files Browse the repository at this point in the history
Adds a healthcheack to the compose file
Also moves some setup steps to bin/setup which makes installation easier.
  • Loading branch information
Earlopain committed Jan 25, 2024
1 parent 25803af commit 0871588
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 41 deletions.
20 changes: 7 additions & 13 deletions .github/prepare-docker-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ runs:
with:
cache-from: type=gha
load: true
tags: reverser:test
tags: reverser

# It could be so easy. https://github.com/docker/compose/issues/7423
- name: Set up env
run: echo -e "CI=1\nREVERSER_DATA_PATH=${{ runner.temp }}/reverser" >> "$GITHUB_ENV"
shell: bash

- name: Set docker run command
run: >-
echo "DOCKER_RUN=docker run
--rm
--network host
-e POSTGRES_HOST=localhost
-e EXPOSED_VNC_PORT=7900
-e IQDB_URL=http://iqdb:5588
-e SELENIUM_URL=http://selenium:4444
-e RAILS_ENV=test
-e CI=true
-v $PWD:/app reverser:test
">> "$GITHUB_ENV"
run: echo "DOCKER_RUN=echo -e \"CI=$CI\nREVERSER_DATA_PATH=$REVERSER_DATA_PATH\" > .env && docker compose run" >> "$GITHUB_ENV"
shell: bash
24 changes: 4 additions & 20 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,21 @@ jobs:
with:
cache-from: type=gha
cache-to: type=gha,mode=max
tags: reverser:test
tags: reverser

tests:
runs-on: ubuntu-latest
needs: docker-build

services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: reverser
POSTGRES_DB: reverser_test
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--mount type=tmpfs,destination=/var/lib/postgresql/data
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: ./.github/prepare-docker-image

- name: Create DB
run: $DOCKER_RUN bin/rails db:schema:load
run: $DOCKER_RUN reverser bin/setup

- name: Run Tests
run: $DOCKER_RUN bundle exec rails test
run: $DOCKER_RUN tests

rubocop:
runs-on: ubuntu-latest
Expand All @@ -65,7 +49,7 @@ jobs:
- uses: ./.github/prepare-docker-image

- name: Run Rubocop
run: $DOCKER_RUN bundle exec rubocop --format github
run: $DOCKER_RUN rubocop

yamllint:
runs-on: ubuntu-latest
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ Install a WSL distribution, enable WSL2, and clone the project inside there. Exe
1. `cd` into the repo.
1. `cp .env.sample .env` and fill out the necessary environment variables.
1. Build the docker image with `docker compose build`.
1. Get inside the container with `docker compose run reverser sh`.
1. Run `RAILS_ENV=test bin/rails db:create` to create the test database.
1. Run `bin/rails db:schema:load` to finish setting up the database.
1. You can now exit the container with `exit`.
1. Run `docker compose run --rm reverser bin/setup`.
1. Run `docker compose up`. The container is now available at `http://localhost:9000`. A few config options are mandatory, you will be notified of them when accessing the site. See [Configuration](#configuration) on how to set them.

This project is only meant to run locally on your machine. You may host it somewhere and make it accessible to others, but be aware that there are no user accounts or fine grained permissions. Everyone can do anyhting.
Expand Down
7 changes: 7 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

puts "Creating test database..."
system("RAILS_ENV=test bin/rails db:create", exception: true)

puts "Loading db schema..."
system("bin/rails db:schema:load", exception: true)
17 changes: 13 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ services:
- build_assets:/app/public/build
- ${REVERSER_DATA_PATH:?}/active_storage:/app/public/storage
depends_on:
- postgres
- iqdb
- selenium
postgres:
condition: service_healthy
iqdb:
condition: service_started
selenium:
condition: service_started
ports:
- ${EXPOSED_SERVER_PORT:-9000}:${EXPOSED_SERVER_PORT:-9000}
command: foreman start --color
Expand All @@ -44,6 +47,11 @@ services:
shm_size: 256mb
ports:
- ${EXPOSED_POSTGRES_PORT:-34518}:5432
healthcheck:
test: [CMD-SHELL, pg_isready]
interval: 10s
timeout: 5s
retries: 5

iqdb:
image: ghcr.io/e621ng/iqdb:b988f000f17008677c7546c0c13623bc956b585d
Expand Down Expand Up @@ -80,7 +88,8 @@ services:
tmpfs:
- /app/tmp/storage
depends_on:
- postgres
postgres:
condition: service_healthy
profiles:
- tests

Expand Down

0 comments on commit 0871588

Please sign in to comment.