Add additional targets to Makefile and optimize docker files [SCI-1096]

This commit is contained in:
Oleksii Kriuchykhin 2017-03-29 16:00:11 +02:00
parent 29621781d6
commit 982612a61a
5 changed files with 39 additions and 28 deletions

1
.gitignore vendored
View file

@ -46,6 +46,7 @@ tags
# Ignore application configuration
/config/application.yml
/production.env
# Ignore rubocop cache files
rubocop_cache

View file

@ -6,6 +6,7 @@ RUN apt-get update -qq && \
apt-get install -y \
nodejs \
postgresql-client \
netcat \
default-jre-headless \
sudo graphviz --no-install-recommends \
sudo libfile-mimeinfo-perl && \
@ -21,11 +22,14 @@ ENV APP_HOME /usr/src/app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
COPY . .
RUN rm -f $APP_HOME/config/application.yml
RUN rm -f $APP_HOME/production.env
RUN rm -f $APP_HOME/config/application.yml $APP_HOME/production.env
ENV RAILS_ENV production
ENV DATABASE_URL=postgresql://postgres@db/scinote_production
RUN bash -c "PAPERCLIP_HASH_SECRET=$(openssl rand -base64 128 | tr -d '\n') SECRET_KEY_BASE=$(openssl rand -hex 64) rake assets:precompile"
ENV RAILS_ENV=production \
DATABASE_URL=postgresql://postgres@db/scinote_production \
PAPERCLIP_HASH_SECRET=dummy \
SECRET_KEY_BASE=dummy \
DEFACE_ENABLED=true
RUN bash -c "rake assets:precompile && rake deface:precompile"
CMD rails s -b 0.0.0.0

View file

@ -1,6 +1,18 @@
APP_HOME="/usr/src/app"
DB_IP=$(shell docker inspect web_db_1 | grep -m 1 "\"IPAddress\": " | awk '{ match($$0, /"IPAddress": "([0-9\.]*)",/, a); print a[1] }')
define PRODUCTION_CONFIG_BODY
SECRET_KEY_BASE=$(shell openssl rand -hex 64)
PAPERCLIP_HASH_SECRET=$(shell openssl rand -base64 128 | tr -d '\n')
DATABASE_URL=postgresql://postgres@db/scinote_production
PAPERCLIP_STORAGE=filesystem
ENABLE_TUTORIAL=true
ENABLE_RECAPTCHA=false
ENABLE_USER_CONFIRMATION=false
ENABLE_USER_REGISTRATION=true
endef
export PRODUCTION_CONFIG_BODY
all: docker database
heroku:
@ -14,6 +26,12 @@ docker:
docker-production:
@docker-compose -f docker-compose.production.yml build
config-production:
ifeq (production.env,$(wildcard production.env))
$(error File production.env already exists!)
endif
@echo "$$PRODUCTION_CONFIG_BODY" > production.env ;
db-cli:
@$(MAKE) rails cmd="rails db"
@ -23,6 +41,9 @@ db-load-dump:
database:
@$(MAKE) rails cmd="rake db:create db:setup db:migrate"
database-production:
@$(MAKE) rails-production cmd="bash -c 'while ! nc -z db 5432; do sleep 1; done; rake db:create && rake db:migrate && rake db:seed'"
rails:
@docker-compose run --rm web $(cmd)
@ -55,6 +76,9 @@ tests:
console:
@$(MAKE) rails cmd="rails console"
console-production:
@$(MAKE) rails-production cmd="rails console"
log:
@docker-compose web log

View file

@ -1,6 +1,7 @@
version: '2.1'
services:
db:
container_name: scinote_db_production
image: postgres:9.4
volumes:
- scinote_production_postgres:/var/lib/postgresql/data
@ -9,7 +10,8 @@ services:
build:
context: .
dockerfile: Dockerfile.production
image: scinote_web:production
image: scinote_web_production
container_name: scinote_web_production
stdin_open: true
env_file: ./production.env
tty: true
@ -24,7 +26,8 @@ services:
- scinote_production_files:/usr/src/app/public/system
jobs:
image: scinote_web:production
image: scinote_web_production
container_name: scinote_jobs_production
tty: true
depends_on:
- db

View file

@ -1,21 +0,0 @@
SECRET_KEY_BASE=""
PAPERCLIP_HASH_SECRET=""
DATABASE_URL=postgresql://postgres@db/scinote_production
MAIL_FROM=""
MAIL_REPLYTO=""
SMTP_ADDRESS=""
SMTP_PORT=""
SMTP_DOMAIN=""
SMTP_USERNAME=""
SMTP_PASSWORD=""
MAIL_SERVER_URL=""
PAPERCLIP_STORAGE="filesystem"
ENABLE_TUTORIAL=true
ENABLE_RECAPTCHA=false
ENABLE_USER_CONFIRMATION="false"
ENABLE_USER_REGISTRATION="true"