diff --git a/Dockerfile b/Dockerfile index b76ba61dc..f5aa00829 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,29 +9,17 @@ RUN apt-get update -qq && \ default-jre-headless \ unison \ sudo graphviz --no-install-recommends \ - sudo libfile-mimeinfo-perl && \ + libfile-mimeinfo-perl && \ rm -rf /var/lib/apt/lists/* # heroku tools RUN wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh -# install gems -COPY Gemfile* /tmp/ -COPY addons /tmp/addons -WORKDIR /tmp -RUN bundle install -RUN rm -rf addons +ENV BUNDLE_PATH /usr/local/bundle/ # create app directory ENV APP_HOME /usr/src/app RUN mkdir $APP_HOME WORKDIR $APP_HOME -RUN mkdir addons -RUN ln -s $(readlink -f addons) /tmp - -# container user -RUN groupadd scinote -RUN useradd -ms /bin/bash -g scinote scinote -USER scinote CMD rails s -b 0.0.0.0 diff --git a/Dockerfile.production b/Dockerfile.production index 63bc9f0da..5b82281e2 100644 --- a/Dockerfile.production +++ b/Dockerfile.production @@ -9,12 +9,15 @@ RUN apt-get update -qq && \ netcat \ default-jre-headless \ sudo graphviz --no-install-recommends \ - sudo libfile-mimeinfo-perl && \ + libfile-mimeinfo-perl && \ rm -rf /var/lib/apt/lists/* +ENV RAILS_ENV production + # install gems -COPY Gemfile* /tmp/ -WORKDIR /tmp +COPY Gemfile* /usr/src/bundle/ +COPY addons /usr/src/bundle/addons +WORKDIR /usr/src/bundle RUN bundle install # create app directory @@ -24,12 +27,10 @@ WORKDIR $APP_HOME COPY . . RUN rm -f $APP_HOME/config/application.yml $APP_HOME/production.env -ENV RAILS_ENV=production \ - DATABASE_URL=postgresql://postgres@db/scinote_production \ +RUN 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" + DEFACE_ENABLED=true \ + bash -c "rake assets:precompile && rake deface:precompile" CMD rails s -b 0.0.0.0 diff --git a/Makefile b/Makefile index d145451c7..946f44e0a 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ ENABLE_TUTORIAL=true ENABLE_RECAPTCHA=false ENABLE_USER_CONFIRMATION=false ENABLE_USER_REGISTRATION=true +DEFACE_ENABLED=false endef export PRODUCTION_CONFIG_BODY @@ -44,6 +45,9 @@ database: 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'" +deface: + @$(MAKE) rails cmd="rake deface:precompile" + rails: @docker-compose run --rm web $(cmd) @@ -53,7 +57,7 @@ rails-production: run: rm tmp/pids/server.pid || true @docker-compose up -d - @docker attach $(shell docker-compose ps web | grep "rails s" | awk '{ print $$1; }') + @docker attach scinote_web_development start: @docker-compose start diff --git a/docker-compose.production.yml b/docker-compose.production.yml index 44365731d..f1fdb456c 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -1,4 +1,4 @@ -version: '2.1' +version: '2' services: db: container_name: scinote_db_production diff --git a/docker-compose.yml b/docker-compose.yml index 435dff1d7..e2429d0ef 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,35 @@ +version: '2' +services: + db: + container_name: scinote_db_development + image: postgres:9.4 + volumes: + - scinote_development_postgres:/var/lib/postgresql/data -dbdata: - image: busybox - volumes: - - /var/lib/postgresql - command: "true" + web: + build: + context: . + dockerfile: Dockerfile + image: scinote_web_development + container_name: scinote_web_development + stdin_open: true + tty: true + depends_on: + - db + ports: + - "3000:3000" + command: > + bash -c "rm -f /usr/src/app/tmp/pids/server.pid && + (bundle check || bundle install) && + bundle exec rails s -b 0.0.0.0" + environment: + - RAILS_ENV=development + volumes: + - .:/usr/src/app + - scinote_development_bundler:/usr/local/bundle/ + - scinote_development_files:/usr/src/app/public/system -db: - image: postgres:9.4 - volumes_from: - - dbdata - -web: - build: . - stdin_open: true - tty: true - ports: - - "3000:3000" - volumes: - - .:/usr/src/app - links: - - db +volumes: + scinote_development_postgres: + scinote_development_bundler: + scinote_development_files: