From b8b3bc3846aa87798bc9d3564ea832fc36df2159 Mon Sep 17 00:00:00 2001 From: Houston Knight Date: Sat, 19 Jun 2021 10:58:01 -0500 Subject: [PATCH] Adds support to run migrations in docker build/up --- Dockerfile | 13 ++++++++++--- docker-compose.yml | 29 ++++++++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index f796b6d..1e73f0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,14 @@ RUN apt-get update && apt-get install -y \ ENV APP_HOME /srv/app ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \ - BUNDLE_JOBS=8 \ - BUNDLE_PATH=/bundle_cache + BUNDLE_JOBS=8 -WORKDIR $APP_HOME +ENV PATH=$APP_HOME/test/dummy/bin:$PATH + +RUN gem install bundler + +COPY . $APP_HOME/ +RUN bundle check || bundle install + +WORKDIR $APP_HOME/test/dummy +RUN rails db:create db:migrate diff --git a/docker-compose.yml b/docker-compose.yml index ab900fa..9befbcd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,16 @@ -app: - container_name: planter_app - build: . - dockerfile: Dockerfile - volumes: - - .:/srv/app - volumes_from: - - bundle_cache -bundle_cache: - container_name: planter_bundle_cache - image: busybox - volumes: - - /bundle_cache +version: '3' + +volumes: + bundle_cache: + +services: + app: + container_name: planter_app + build: + context: . + command: > + bash -c "bin/rails db:create && + bin/rails db:migrate" + volumes: + - .:/srv/app + - bundle_cache:/usr/local/lib