diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d1688b2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Gemfile.lock +tmp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00a3072..e606eed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,42 +14,54 @@ jobs: test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: ruby-version: [2.6, 2.7, 3.0] services: postgres: - image: postgres:12.1-alpine + image: postgres:13-alpine ports: - 5432:5432 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + POSTGRES_HOST_AUTH_METHOD: trust + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - name: Checkout Project - uses: actions/checkout@v3 - + uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - - name: Install Library Dependencies - run: sudo apt-get install libpq-dev - + run: sudo apt update && sudo apt install -y postgresql-client - name: Setup Database run: | - cp config/database.yml.github-actions config/database.yml - env: - RAILS_ENV: test - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - + mkdir -p config + cat < config/database.yml + test: + adapter: postgresql + encoding: unicode + pool: 20 + database: prodder_test + EOF - name: Test with RSpec env: - RAILS_ENV: "test" - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - run: | - bundle exec rspec + PGHOST: localhost + PGPORT: 5432 + PGUSER: postgres + PGPASSWORD: postgres + run: bundle exec rspec + # - name: Test with Cucumber + # env: + # PGHOST: localhost + # PGPORT: 5432 + # PGUSER: postgres + # PGPASSWORD: postgres + # run: bundle exec cucumber diff --git a/.gitignore b/.gitignore index 0600562..d1688b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,2 @@ Gemfile.lock -*.gem -*.rbc -.bundle -.config -coverage -InstalledFiles -lib/bundler/man -pkg -rdoc -spec/reports -test/tmp -test/version_tmp tmp - -# YARD artifacts -.yardoc -_yardoc -doc/ - -nc.yml -prodder-workspace/ -features/support/blog.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1dc70c3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +ARG RUBY_VERSION=3.0 + +FROM ruby:${RUBY_VERSION} + +WORKDIR /app + +RUN apt update && \ + apt install -y git postgresql-client && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +ENV BUNDLER_VERSION 2.4.22 + +RUN gem install bundler -v $BUNDLER_VERSION + +COPY Gemfile ./ + +RUN bundle install -j $(nproc) + +COPY . . + +ENTRYPOINT ["entrypoints/entry.sh"] +CMD ["bin/prodder"] diff --git a/README.md b/README.md index 6ed4039..1d99db0 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Things that really matter: created. Those initial seeds should have included your production app's `schema_migrations` table contents. This means only those migrations that have not yet run in production will need to be run locally. -3. If you configred to have 3 users in your `#config/database.yml` file and have a `permissions.sql` file present, +3. If you configured to have 3 users in your `#config/database.yml` file and have a `permissions.sql` file present, all your `db:*` commands will be run in the context of the user it makes the most sense to run as, mimicking our production environment. For instance(s), to reset the database (god forbid we do this in production), it will run as `superuser`, to run a migration, as the `migration_user` and your application will connect to the database diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..872f074 --- /dev/null +++ b/compose.yml @@ -0,0 +1,54 @@ +services: + postgres: + image: postgres:13-alpine + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - 5432:5432 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust + healthcheck: + test: ["CMD", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 + restart: on-failure:5 + + prodder: + platform: linux/arm64 + build: + context: . + dockerfile: Dockerfile + args: + RUBY_VERSION: 3.0 + volumes: + - .:/app + - /app/config + depends_on: + postgres: + condition: service_healthy + environment: + PGHOST: localhost + PGPORT: "5432" + PGUSER: postgres + PGPASSWORD: postgres + network_mode: host + + rspec: + profiles: + - test + extends: + service: prodder + command: bundle exec rspec + + cucumber: + profiles: + - test + extends: + service: prodder + command: bundle exec cucumber + +volumes: + postgres_data: diff --git a/config/database.yml.github-actions b/config/database.yml.github-actions deleted file mode 100644 index 0724691..0000000 --- a/config/database.yml.github-actions +++ /dev/null @@ -1,8 +0,0 @@ -test: - adapter: postgresql - host: localhost - encoding: unicode - database: github-actions - pool: 20 - username: <%= ENV["POSTGRES_USER"] %> - password: <%= ENV["POSTGRES_PASSWORD"] %> diff --git a/entrypoints/entry.sh b/entrypoints/entry.sh new file mode 100755 index 0000000..e2b0cb3 --- /dev/null +++ b/entrypoints/entry.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euo pipefail + +cmd=("$@") + +mkdir -p config +cat < config/database.yml +test: + adapter: postgresql + encoding: unicode + pool: 20 + database: prodder_test +EOF + +exec "${cmd[@]}"