diff --git a/.github/prepare-docker-image/action.yml b/.github/prepare-docker-image/action.yml index 9ca386cd..7a92bcde 100644 --- a/.github/prepare-docker-image/action.yml +++ b/.github/prepare-docker-image/action.yml @@ -12,19 +12,17 @@ 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 + env: + ENV_FILE: | + CI=1 + REVERSER_DATA_PATH=${{ runner.temp }}/reverser + run: echo "ENV_FILE=$ENV_FILE" >> "$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 $ENV_FILE > .env && docker compose run" >> "$GITHUB_ENV" shell: bash diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index cf325fce..3decc817 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -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 @@ -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 diff --git a/README.md b/README.md index bf5756f8..9d8ae056 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bin/setup b/bin/setup new file mode 100755 index 00000000..d881a9f4 --- /dev/null +++ b/bin/setup @@ -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) diff --git a/docker-compose.yml b/docker-compose.yml index 075d1318..0aded66d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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 @@ -80,7 +88,8 @@ services: tmpfs: - /app/tmp/storage depends_on: - - postgres + postgres: + condition: service_healthy profiles: - tests