Better Docker config: Use entrypoint to setup the environment, run in production mode by default, defaults for all config values

This commit is contained in:
Jyri-Petteri Paloposki 2020-07-19 16:12:57 +03:00
parent 67012821e6
commit 3f22c8a036
6 changed files with 42 additions and 59 deletions

View file

@ -17,9 +17,11 @@ COPY . /app/
COPY config/database.docker.yml /app/config/database.yml
COPY config/site.docker.yml /app/config/site.yml
COPY docker-startserver.sh /
RUN RAILS_ENV=production bundle exec rake assets:precompile
COPY docker-entrypoint.sh /
ENTRYPOINT ["./docker-entrypoint.sh"]
EXPOSE 3000
#CMD ["rails", "server", "-e", "production", "-b", "0.0.0.0"]
CMD ["./docker-startserver.sh"]
CMD ["rails", "server", "-b", "0.0.0.0"]

View file

@ -1,44 +1,24 @@
#development:
# adapter: mysql2
# database: tracks_dev
# # set this if you are storing utf8 in your mysql database to handle strings
# # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode
# # encoding: utf8
# host: docker
# port: 3307
# username: tracks_dev
# password: FqUKMWPz5mh8UPhypZvq
#development:
# adapter: postgresql
# database: tracks_dev
# # set this if you are storing utf8 in your mysql database to handle strings
# # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode
# # encoding: utf8
# host: docker
# port: 5432
# username: tracks_dev
# password: password
#development:
# adapter: sqlite3
# database: db.sqlite
#test:
# adapter: mysql2
# database: tracks_test
# # set this if you are storing utf8 in your mysql database to handle strings
# # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode
# # encoding: utf8
# host: docker
# port: 3307
# username: tracks_tst
# password: 9rMNV4y6RVcqmJTo2QoR
# Production config is disabled by default
#
development:
test:
adapter: <%= ENV.fetch('DATABASE_TYPE') %>
encoding: <%= ENV.fetch('DATABASE_ENCODING') %>
database: <%= ENV.fetch('DATABASE_NAME') %>
host: <%= ENV.fetch('DATABASE_HOST') %>
port: <%= ENV.fetch('DATABASE_PORT') %>
username: <%= ENV.fetch('DATABASE_USERNAME') %>
password: <%= ENV.fetch('DATABASE_PASSWORD') %>
development:
adapter: <%= ENV.fetch('DATABASE_TYPE') %>
encoding: <%= ENV.fetch('DATABASE_ENCODING') %>
database: <%= ENV.fetch('DATABASE_NAME') %>
host: <%= ENV.fetch('DATABASE_HOST') %>
port: <%= ENV.fetch('DATABASE_PORT') %>
username: <%= ENV.fetch('DATABASE_USERNAME') %>
password: <%= ENV.fetch('DATABASE_PASSWORD') %>
production:
adapter: <%= ENV.fetch('DATABASE_TYPE') %>
encoding: <%= ENV.fetch('DATABASE_ENCODING') %>
database: <%= ENV.fetch('DATABASE_NAME') %>
host: <%= ENV.fetch('DATABASE_HOST') %>
port: <%= ENV.fetch('DATABASE_PORT') %>

View file

@ -25,12 +25,6 @@ secret_token: "secret"
# Set to true when your application is running with https
force_ssl: false
# Configure how static assets (images, stylesheets, etc.) will be served.
# The best practice is to have a proxying web server such as Apache or Nginx
# serve static assets (images, stylesheets, javascript) for you. Change
# this to 'true' if you want Rails to be responsible for serving the static assets
# serve_static_assets: false
# Uncomment if you want to dispatch todos that come from email based on the To:
# address rather than the From: address.
# email_dispatch: 'to'

View file

@ -28,12 +28,6 @@ secret_token: "change-me"
# Set to true when your application is running with https
force_ssl: false
# Configure how static assets (images, stylesheets, etc.) will be served.
# The best practice is to have a proxying web server such as Apache or Nginx
# serve static assets (images, stylesheets, javascript) for you. Change
# this to 'true' if you want Rails to be responsible for serving the static assets
# serve_static_assets: false
# Uncomment if you want to dispatch todos that come from email based on the To:
# address rather than the From: address.
# email_dispatch: 'to'

17
docker-entrypoint.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
export RAILS_ENV=${RAILS_ENV:-production}
export DATABASE_NAME=${DATABASE_NAME:-tracks}
export DATABASE_HOST=${DATABASE_HOST:-db}
export DATABASE_PORT=${DATABASE_PORT:-3306}
export DATABASE_USERNAME=${DATABASE_USERNAME:-tracks}
export DATABASE_PASSWORD=${DATABASE_PASSWORD:-password}
export DATABASE_TYPE=${DATABASE_TYPE:-mysql2}
export DATABASE_ENCODING=${DATABASE_ENCODING:-utf8}
export RAILS_SERVE_STATIC_FILES=TRUE
export RAILS_LOG_TO_STDOUT=TRUE
rails db:migrate
exec "$@"

View file

@ -1,4 +0,0 @@
#!/bin/sh
rails db:migrate
rails server -b 0.0.0.0