Skip to content

Commit

Permalink
chore: add local dev setup and fix ci db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisen-san committed Nov 22, 2024
1 parent 16ee170 commit df44505
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Gemfile.lock
tmp
48 changes: 30 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > 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
21 changes: 0 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -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:
8 changes: 0 additions & 8 deletions config/database.yml.github-actions

This file was deleted.

15 changes: 15 additions & 0 deletions entrypoints/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -euo pipefail

cmd=("$@")

mkdir -p config
cat <<EOF > config/database.yml
test:
adapter: postgresql
encoding: unicode
pool: 20
database: prodder_test
EOF

exec "${cmd[@]}"

0 comments on commit df44505

Please sign in to comment.