Skip to content

Commit

Permalink
Use production Dockerfile for local docker.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlittman committed Oct 12, 2022
1 parent 533b435 commit 0f3e8f7
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 93 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ group :development, :test do
end

group :development do
gem 'faker'
gem 'listen', '~> 3.2'
gem 'multi_json', require: false # needed to update RBIs after adding reform-rails
gem 'spring'
Expand All @@ -41,7 +40,7 @@ end
group :deployment do
gem 'capistrano-maintenance', '~> 1.2', require: false
gem 'capistrano-rails', require: false
gem 'dlss-capistrano-docker', github: 'sul-dlss/dlss-capistrano-docker', branch: 'initial', require: false
gem 'dlss-capistrano-docker', github: 'sul-dlss/dlss-capistrano-docker', branch: 't2-rollback', require: false
end

gem 'action_policy', '~> 0.5.3'
Expand All @@ -55,6 +54,7 @@ gem 'devise-remote-user', '~> 1.0'
gem 'druid-tools'
gem 'dry-types'
gem 'edtf'
gem 'faker'
gem 'faraday', '~> 2.0'
gem 'honeybadger', '~> 4.0'
gem 'jbuilder'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: https://github.com/sul-dlss/dlss-capistrano-docker.git
revision: f180a5fc7329c506b0ad89bd0f8f821972a04fa6
branch: initial
revision: 6db0ad1335507359f32b6a40ce8cd56e8be42be9
branch: t2-rollback
specs:
dlss-capistrano-docker (0.0.1)
dlss-capistrano-docker (1.0.0)
capistrano (~> 3.0)
capistrano-one_time_key
capistrano-shared_configs
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ Then run tests with `bundle exec rspec`. If you also want to do style checks & l

### Integration

Spin up all docker compose services for local development and in-browser testing:
Spin up all docker compose services for local testing:

```shell
$ docker compose up # use -d to run in background
```

This will spin up the H2 web application, its background workers, and all service dependencies declared in docker-compose.yml.
This will spin up the H2 web application, its background workers, and all service dependencies declared in docker-compose.yml. H2 will be running in production mode.

### Cypress
Cypress is primarily used to test features implemented with JS/Stimulus. Cypress tests are located in `cypress/spec`.
Expand Down
13 changes: 10 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ def groups_from_request_env
session['groups'] = begin
raw_header = request.env[Settings.authorization_group_header]
roles = ENV.fetch('ROLES', nil) # rubocop:disable Rails/EnvironmentVariableAccess
raw_header = roles if Rails.env.development?
# This test setting is for cypress.
raw_header = roles if Rails.env.test? && roles
raw_header = roles if use_roles?(roles)
logger.debug("Roles are #{raw_header}")
raw_header&.split(';') || []
end
end

def use_roles?(roles)
return true if Rails.env.development?
# This test setting is for cypress.
return true if Rails.env.test? && roles
return true if ENV.fetch('LOCAL_DOCKER', nil) && roles # rubocop:disable Rails/EnvironmentVariableAccess

false
end

def deny_access
flash[:warning] = 'You are not authorized to perform the requested action'
redirect_to :root
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise_remote_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DeviseRemoteUser.configure do |config|
config.env_key = lambda do |env|
remote_user = ENV.fetch('REMOTE_USER', nil)
if (Rails.env.development? || Rails.env.test?) && remote_user
if (Rails.env.development? || Rails.env.test? || ENV.fetch('LOCAL_DOCKER', false)) && remote_user
remote_user
else
# Return the first non-blank value of a remote user header, or return nil (unauthenticated)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
app:
build: &build
context: .
dockerfile: docker/app-prod/Dockerfile
dockerfile: docker/Dockerfile
args:
- GID=${H2_GID-1000}
- UID=${H2_UID-1000}
Expand Down
33 changes: 13 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,35 @@ version: '3.6'

services:
app:
build:
build: &build
context: .
dockerfile: docker/app/Dockerfile
environment:
dockerfile: docker/Dockerfile
args:
SECRET_KEY_BASE: 2e4f669b6529a0bcec468d9b5329e2fe7e7f6a4d7915370862d6d4f2b6907f1fabc505a681aaa13b3858f02588602fd0b721ca783bdac37fe70ea83b8f123456
environment: &environment
DATABASE_NAME: h2
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOSTNAME: db
RAILS_LOG_TO_STDOUT: 'true'
RAILS_SERVE_STATIC_FILES: 'true'
REDIS_URL: redis://redis:6379/ # for ActionCable
REMOTE_USER: sdr.user@stanford.edu
volumes:
- .:/app
working_dir: /app
REMOTE_USER: auser@stanford.edu
ROLES: dlss:hydrus-app-administrators
LOCAL_DOCKER: 'true'
ports:
- 3000:3000
depends_on:
- db
- redis
- workers
command: "./docker/invoke-app.sh"
workers:
build:
context: .
dockerfile: docker/workers/Dockerfile
environment:
DATABASE_NAME: h2
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOSTNAME: db
REDIS_URL: redis://redis:6379/ # for Sidekiq
volumes:
- .:/app
working_dir: /app
build: *build
environment: *environment
depends_on:
- db
- redis
command: "./docker/invoke-worker.sh"
db:
image: postgres:12
environment:
Expand Down
7 changes: 5 additions & 2 deletions docker/app-prod/Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM ruby:3.1-alpine

# curl is to install supercronic
# postgresql-client and redis is required for invoke.sh
RUN apk add --update --no-cache \
build-base \
postgresql-dev \
postgresql-client \
tzdata \
yarn \
git \
curl
curl \
redis

ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.1/supercronic-linux-amd64
ENV SUPERCRONIC=supercronic-linux-amd64
Expand Down Expand Up @@ -43,6 +45,7 @@ ENV NODE_ENV=production
RUN bundle install
RUN yarn install

RUN chown -R h2:h2 /app
COPY --chown=h2:h2 . .
USER h2:h2

Expand Down
30 changes: 0 additions & 30 deletions docker/app/Dockerfile

This file was deleted.

3 changes: 3 additions & 0 deletions docker/app/invoke.sh → docker/invoke-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ set -e
echo "Migrating db"
bin/rails db:migrate

echo "Seeding db"
bin/rails db:seed

echo "Running server"
exec bin/puma -C config/puma.rb config.ru
File renamed without changes.
27 changes: 0 additions & 27 deletions docker/workers/Dockerfile

This file was deleted.

8 changes: 6 additions & 2 deletions lib/tasks/deposit.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

desc 'Complete deposit of works and collections (only for development)'
task complete_deposits: :environment do
abort 'ERROR: This task only runs in the development environment!' unless Rails.env.development?
abort 'ERROR: This task only runs in the development environment!' unless can_run?

objects_awaiting_deposit.each do |object_version|
deposit_completer = DepositCompleter.new(object_version:)
Expand All @@ -15,7 +15,7 @@ end

desc 'Complete the assignment of a druid to purl reservation works that need one'
task assign_pids: :environment do
abort 'ERROR: This task only runs in the development environment!' unless Rails.env.development?
abort 'ERROR: This task only runs in the development environment!' unless can_run?

WorkVersion.with_state('reserving_purl').each do |object|
druid = random_druid
Expand All @@ -39,3 +39,7 @@ def random_druid
# => "{druid:,}qj078cn5200"
"druid:#{Faker::Base.regexify(DruidTools::Druid.strict_glob).last(11)}"
end

def can_run?
Rails.env.development? || ENV.fetch('LOCAL_DOCKER', false)
end

0 comments on commit 0f3e8f7

Please sign in to comment.