-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from 16 commits
6c2bb30
eb8bced
61f3230
6dea642
0348b6d
af1a340
a6a0926
fe82950
c21bd24
4467970
be53281
18f0966
19434f1
fb78601
d71d54b
c479dea
63d762c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Dockerfile | ||
.git | ||
.github | ||
public |
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"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,15 @@ | |
|
||
# `config.assets.precompile` has moved to config/initializers/assets.rb | ||
|
||
#run background tasks syncronously | ||
config.active_job.queue_adapter = :inline | ||
|
||
# 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/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 "Migrating civic database" | ||
# migrate: | ||
rake db:migrate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're initializing the database from scratch here, and not running migrations in the case of an update anyways, you could just run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.