Remove DATABASE_URL from docker dev envs

Fixes: CCI-347

This will allow connecting to the test environment again.
Copy over the updated config/docker-compose.override.yml (or delete the
relevant line from your existing docker-compose.override.yml). Also copy
over the restored and modified config/database.yml.example.

    $ cp -iv config/docker-compose.override.yml.example \
      docker-compose.override.yml
    $ cp -iv docker-compose/,}config/database.yml

If you have existing databases that don't match the naming scheme of
"canvas_<ENV>" then you'll need to do a custom configuration for your
database names in config/database.yml or rename your databases in
postgres.

Test Plan
- update your override config and database.yml:

    $ cp -iv config/docker-compose.override.yml.example \
      docker-compose.override.yml
    $ cp -iv {docker-compose/,}config/database.yml

- make sure your postgres image is up to date from earlier patchset
  (this will remove all your data):

    $ docker-compose down --volumes
    $ docker-compose build --no-cache postgres

- boot the app, bundle, and wait for postgres to be available (for
  internal start up scripts to run):

    $ docker-compose run --rm web bundle \
      && docker-compose run --rm web build/new-jenkins/wait-for-it \
      postgres:5432 -t 30

- test that connctions to both development and test databases work:
  - developement:

    $ docker-compose run --rm web bin/rails runner \
      'puts ActiveRecord::Base.connection.current_database'
    => 'canvas_development'

  - test:

    $ docker-compose run --rm -e RAILS_ENV=test web bin/rails runner \
      'puts ActiveRecord::Base.connection.current_database'
    => 'canvas_test'

- set a custom database name:

    $ docker-compose run --rm \
      -e RAILS_ENV=test \
      -e CANVAS_DATABASE_TEST=canvas_rails3_ \
      web bin/rails runner \
      'Rails.application.load_tasks; \
        Rake::Task["db:create"].invoke; \
        puts ActiveRecord::Base.connection.current_database'
    => 'canvas_rails3_'

flag = none

Change-Id: Ia19038586508dc91c6a4d4386d812752e00a4ad6
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/235642
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Rex Fleischer <rfleischer@instructure.com>
Reviewed-by: James Butters <jbutters@instructure.com>
Reviewed-by: Augusto Callejas <acallejas@instructure.com>
QA-Review: James Butters <jbutters@instructure.com>
Product-Review: Derek Bender <djbender@instructure.com>
This commit is contained in:
Derek Bender 2020-04-29 10:04:42 -05:00
parent c3bbc262a4
commit e1bf14466f
4 changed files with 30 additions and 5 deletions

View File

@ -44,7 +44,6 @@ services:
- yardoc:/usr/src/app/.yardoc
- yarn-cache:/home/docker/.cache/yarn
environment: &BASE-ENV
DATABASE_URL: postgres://postgres:sekret@postgres/canvas_development
ENCRYPTION_KEY: facdd3a131ddd8988b14f6e4e01039c93cfa0160
RAILS_ENV: development

View File

@ -8,9 +8,7 @@ services:
- postgres
- redis
environment:
# by default, app runs in production mode unless docker-compose.override.yml
# is also present, then DATABASE_URL is overwriten there.
DATABASE_URL: postgres://postgres:sekret@postgres/canvas_production
POSTGRES_PASSWORD: sekret
jobs:
<<: *WEB

View File

@ -0,0 +1,28 @@
common: &common
adapter: postgresql
host: <%= ENV.fetch('CANVAS_DATABASE_HOST', 'postgres') %>
password: <%= ENV.fetch('POSTGRES_PASSWORD') %>
encoding: utf8
username: <%= ENV.fetch('CANVAS_DATABASE_USERNAME', 'postgres') %>
timeout: 5000
prepared_statements: false
use_qualified_names: true
shard_name: public
schema_search_path: "''"
production:
<<: *common
database: <%= ENV.fetch('CANVAS_DATABASE_PRODUCTION', 'canvas_production') %>
development:
<<: *common
database: <%= ENV.fetch('CANVAS_DATABASE_DEVELOPMENT', 'canvas_development') %>
test:
<<: *common
database: canvas_test
database: <%= ENV.fetch('CANVAS_DATABASE_TEST', 'canvas_development') %>
shard1: canvas_test_shard_1
shard2: canvas_test_shard_2
test_shard_1: canvas_test_shard_1
test_shard_2: canvas_test_shard_2

View File

@ -10,7 +10,7 @@ psql -v ON_ERROR_STOP=1 --username postgres -d template1 <<SQL
CREATE EXTENSION IF NOT EXISTS pg_collkey SCHEMA public;
SQL
for environment in test development produciton; do
for environment in test development production; do
psql -v ON_ERROR_STOP=1 --username postgres <<SQL
CREATE DATABASE canvas_${environment};
SQL