Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize civic-server #704

Merged
merged 17 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
.git
.github
public
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ruby:2

RUN apt-get update
RUN apt-get install -y rbenv libxml2 libxslt-dev openssl nodejs postgresql-client
RUN gem install bundler

#RUN mkdir /civic-server
#RUN cd /civic-server && bundle install

COPY Gemfile /civic-server/Gemfile
COPY Gemfile.lock /civic-server/Gemfile.lock

RUN cd /civic-server && bundle update --bundler && rbenv rehash && bundle install

COPY $PWD /civic-server
WORKDIR /civic-server

ENTRYPOINT ["/civic-server/docker-entrypoint.sh"]
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ group :development do
gem 'capistrano-rbenv', '~> 2.0'
gem 'capistrano-passenger', '~> 0.2.0'
end

group :production do
gem 'puma', '~> 5.6.4'
end
4 changes: 3 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ default: &default
adapter: postgresql
pool: 5
encoding: unicode
host: localhost
host: <%= ENV['DATABASE_HOST'] %>
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>

development:
<<: *default
Expand Down
5 changes: 4 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@

# `config.assets.precompile` has moved to config/initializers/assets.rb

#run background tasks syncronously
config.active_job.queue_adapter = :inline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason, if this is not set, the deployment returns HTTP 500 for any api call...not sure why.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @acoffman can comment on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely due to the default production background jobs queue requiring redis in production. Setting it to inline will cause any background tasks (delivering notifications, analytics, generating data dumps, etc) to trigger during the request/response cycle rather than being queued for later processing.

For a smaller installation, that's probably fine, but if you notice performance issues, that could be a culprit.


# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
#config.force_ssl = true
Comment on lines +39 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was needed because our deployment is behind reverse proxy


# Set to :debug to see everything in the log.
config.log_level = :info
Expand Down
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'

services:
civic:
build: .
ports:
- "3000:3000"
environment:
RAILS_ENV: production
SECRET_KEY_BASE: production_key_eretred547568
DATABASE_HOST: db
DATABASE_USER: postgres
DATABASE_PASSWORD: psw
depends_on:
- db
db:
image: postgres:13.5
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: psw
healthcheck:
test: "PASSWORD=psw pg_isready -U postgres"
interval: 10s
timeout: 5s
retries: 5
32 changes: 32 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e
set -u # unset variables throw error
set -o pipefail # pipes fail when partial command fails

bundle update --bundler

# Note: make sure env $DATABASE_* items are set!

# Attempt connect to db and if
# it fails, then assume db does not exist and
# db creation should be executed:
if PGPASSWORD=$DATABASE_PASSWORD psql -lqt -U$DATABASE_USER -h$DATABASE_HOST | cut -d \| -f 1 | grep -q civic; then
echo "civic database already exists. Skipping database initialisation."
else
echo "Creating civic database"
rake db:create

echo "Initializing civic database"
rake db:structure:load

echo "Loading a recent database backup"
# unpack ./db/data.sql.gz (required before loading data dump):
gunzip ./db/data.sql.gz
# load the sanitized version of a recent database backup found in ./db:
rake civic:load[force]
echo "Done"
fi

echo "Starting server now. You can test it with e.g. http://localhost:3000/api/genes/3845?identifier_type=entrez_id"
rails server -b 0.0.0.0