From b35c1a575f7c2d229e66dcb8ff06ef5eec09c1be Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Mon, 31 Jan 2022 09:22:38 -0600 Subject: [PATCH] Add a minimal test database setup to the docker-compose file (#16305) This provides a test environment database for anyone using a docker based development environment. Expose, rather than bind, the db port (you won't be able to connect to the db externally, only from the container). Add tmpfs storage (this alleviates an issue seen with carrierwave attachments when trying to write to the tmp directory in the image). Upgrade db versions from 11 to 13 (this is a breaking change for anyone using this who had already provisioned the db, since no attempt to upgrade has been provided, users may either downgrade to the 11-alpine image or recreate their storage volume). This is separable (the `db` container was preexisting so is the only upgrade conflict for users, the `testdb` container is newly created in a newly added volume, and should not rely on persistence). It's possible no volume is needed for the test db (only the schema would normally be persisted, since data is truncated after normal test completion). --- docker-compose.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a440ba3f3..58be68b15 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,9 +11,11 @@ services: - db - redis - yarn + - testdb environment: RAILS_ENV: development DATABASE_URL: postgresql://forem:forem@db:5432/PracticalDeveloper_development + DATABASE_URL_TEST: postgresql://forem:forem@testdb:5432/Forem_test REDIS_SESSIONS_URL: redis://redis:6379 REDIS_SIDEKIQ_URL: redis://redis:6379 REDIS_URL: redis://redis:6379 @@ -21,6 +23,8 @@ services: RACK_TIMEOUT_SERVICE_TIMEOUT: 10000 STATEMENT_TIMEOUT: 10000 APP_DOMAIN: localhost:3000 + tmpfs: + - /tmp volumes: - .:/opt/apps/forem:delegated entrypoint: ["dockerize", "-wait", "tcp://db:5432", "-wait", "tcp://redis:6379", "-wait", "file:///opt/apps/forem/vendor/bundle/.bundle_finished", "-timeout", "2700s", "-wait-retry-interval", "10s"] @@ -112,7 +116,7 @@ services: command: ["bundle", "exec", "sidekiq","-c","2"] db: - image: postgres:11-alpine + image: postgres:13-alpine container_name: forem_postgresql environment: POSTGRES_USER: forem @@ -123,6 +127,18 @@ services: volumes: - db_data:/var/lib/postgresql/data:delegated + testdb: + image: postgres:13-alpine + container_name: forem_postgresql_test + environment: + POSTGRES_USER: forem + POSTGRES_PASSWORD: forem + POSTGRES_DB: Forem_test + expose: + - "5432" + volumes: + - testdb_data:/var/lib/postgresql/data:delegated + redis: image: redis:6.0.9-alpine container_name: forem_redis @@ -131,3 +147,4 @@ services: volumes: db_data: + testdb_data: