From e50da9b3e2dcdc432d7919692e2a4865e68124f9 Mon Sep 17 00:00:00 2001 From: Juan Rodriguez Date: Sun, 13 Jun 2021 20:36:39 -0500 Subject: [PATCH] chore: :wrench: docker entrypoint for init db docker-compose.test removed, create testing and dev databases on init db --- .env.dev | 4 ---- Dockerfile.db | 3 +++ Gemfile.lock | 21 --------------------- README.md | 8 ++------ config/database.yml | 13 ++++++++----- docker-compose.test.yml | 31 ------------------------------- docker-compose.yml | 13 ++++++++----- docker-entrypoint-initdb.sql | 5 +++++ 8 files changed, 26 insertions(+), 72 deletions(-) delete mode 100644 .env.dev create mode 100644 Dockerfile.db delete mode 100644 docker-compose.test.yml create mode 100644 docker-entrypoint-initdb.sql diff --git a/.env.dev b/.env.dev deleted file mode 100644 index f62639d..0000000 --- a/.env.dev +++ /dev/null @@ -1,4 +0,0 @@ -RAILS_ENV=development -HOSTNAME=0.0.0.0 -RAILS_PORT=3000 -DATABASE_URL=postgres://user:user_12345@db:5432/url_shortener diff --git a/Dockerfile.db b/Dockerfile.db new file mode 100644 index 0000000..b4d0d6a --- /dev/null +++ b/Dockerfile.db @@ -0,0 +1,3 @@ +FROM postgres:12.5-alpine + +COPY docker-entrypoint-initdb.sql /docker-entrypoint-initdb.d/ \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 1ae0c82..316d0e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,13 +59,6 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) childprocess (3.0.0) - coffee-rails (4.2.2) - coffee-script (>= 2.2.0) - railties (>= 4.0.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) concurrent-ruby (1.1.9) crass (1.0.6) docile (1.4.0) @@ -154,17 +147,6 @@ GEM regexp_parser (2.1.1) ruby_dep (1.5.0) rubyzip (2.3.0) - sass (3.7.4) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.1.0) - railties (>= 5.2.0) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) @@ -189,7 +171,6 @@ GEM thor (1.1.0) thread_safe (0.3.6) thread_safe (0.3.6-java) - tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) @@ -230,13 +211,11 @@ DEPENDENCIES bootsnap (>= 1.1.0) byebug capybara (>= 2.15) - coffee-rails (~> 4.2) jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) puma (~> 4.3.8) rails (~> 5.2.6) - sass-rails (~> 5.0) selenium-webdriver simplecov spring diff --git a/README.md b/README.md index a4d2693..f724b0f 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,9 @@ docker-compose up ``` ### Testing -- Run database in background -```bash -docker-compose -f docker-compose.test.yml up -d db -``` - Run tests ```bash -docker-compose -f docker-compose.test.yml run --rm app bundle exec rails test +docker-compose run --rm app bundle exec rails test ``` ### Rubocop @@ -34,7 +30,7 @@ docker-compose run --rm app rubocop - [x] Generate unique slug - [x] Link unit tests - [x] Stimulus setup -- [ ] Link controller (handle redirection) +- [x] Link controller (handle redirection) - [ ] Main page with input box - [ ] Create user model - [ ] User unit tests diff --git a/config/database.yml b/config/database.yml index 32742d4..8128221 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,7 +23,10 @@ default: &default development: <<: *default - database: app_development + host: db + database: url_shortener + username: app_user + password: secure_12345 # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. @@ -57,7 +60,10 @@ development: # Do not set this db to the same as development or production. test: <<: *default - database: app_test + host: db + database: test_url_shortener + username: app_user + password: secure_12345 # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is @@ -80,6 +86,3 @@ test: # production: <<: *default - database: app_production - username: app - password: <%= ENV['APP_DATABASE_PASSWORD'] %> diff --git a/docker-compose.test.yml b/docker-compose.test.yml deleted file mode 100644 index 152ba15..0000000 --- a/docker-compose.test.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: '3' - -services: - db: - image: postgres:12.5-alpine - volumes: - - test_db_data:/var/lib/postgresql/data - environment: - POSTGRES_USER: user - POSTGRES_PASSWORD: user_12345 - POSTGRES_DB: test_url_shortener - ports: - - 5432:5432 - app: - build: - context: . - dockerfile: Dockerfile.dev - volumes: - - .:/usr/src/app - - gem_cache:/usr/local/bundle/gems - command: bundle exec rails test - environment: - RAILS_ENV: test - HOSTNAME: 0.0.0.0 - PORT: 3000 - DATABASE_URL: postgres://user:user_12345@db:5432/test_url_shortener - depends_on: - - db -volumes: - gem_cache: - test_db_data: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index fb69d71..b87ed9b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,13 +2,14 @@ version: '3' services: db: - image: postgres:12.5-alpine + build: + context: . + dockerfile: Dockerfile.db volumes: - db_data:/var/lib/postgresql/data environment: - POSTGRES_USER: user - POSTGRES_PASSWORD: user_12345 - POSTGRES_DB: url_shortener + POSTGRES_USER: app_user + POSTGRES_PASSWORD: secure_12345 ports: - 5432:5432 app: @@ -20,7 +21,9 @@ services: - gem_cache:/usr/local/bundle/gems command: bundle exec rails s -b '0.0.0.0' tty: true - env_file: .env.dev + environment: + RAILS_ENV: development + HOSTNAME: 0.0.0.0 ports: - 3000:3000 depends_on: diff --git a/docker-entrypoint-initdb.sql b/docker-entrypoint-initdb.sql new file mode 100644 index 0000000..3a15b6a --- /dev/null +++ b/docker-entrypoint-initdb.sql @@ -0,0 +1,5 @@ +CREATE DATABASE url_shortener; +CREATE DATABASE test_url_shortener; + +GRANT ALL PRIVILEGES ON DATABASE url_shortener TO app_user; +GRANT ALL PRIVILEGES ON DATABASE test_url_shortener TO app_user;