-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6c2bb30
WIP: start dockerizing civic-server
eb8bced
adding entrypoint to initialize DB when necessary
pieterlukasse 61f3230
Merge pull request #1 from pieterlukasse/entrypoint_for_docker
ruslan-forostianov 6dea642
Use the docker entry point
0348b6d
skipping big folders to avoid sending them to docker context
pieterlukasse af1a340
removed runtime ENV from Dockerfile
pieterlukasse a6a0926
set RAILS_ENV to dev; simplified db depends_on; downgraded postgres t…
pieterlukasse fe82950
removed TODO notes for parts that are implemented; made grep check mo…
pieterlukasse c21bd24
exposing civic port
pieterlukasse 4467970
Merge pull request #2 from pieterlukasse/continue_dockerize
ruslan-forostianov be53281
fix to ensure the server is really listening
pieterlukasse 18f0966
Merge pull request #3 from pieterlukasse/fix_rails_port
ruslan-forostianov 19434f1
Start civic in production envirounment
fb78601
Use puma if it is production
d71d54b
change to production config to get it working again
pieterlukasse c479dea
Merge pull request #4 from pieterlukasse/fix_puma
ruslan-forostianov 63d762c
Initialize database instead of full-blown migration
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Dockerfile | ||
.git | ||
.github | ||
public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.