From 407c19a83bfb5edaf5e8499ff51c4229c5d03619 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 4 Feb 2022 17:04:40 +0000 Subject: [PATCH] Make docker-compose actually useful --- Dockerfile | 2 +- Dockerfile_dev | 33 +++++++++++++++++++++++++++++++++ Gemfile.lock | 4 ++-- config/database.yml | 4 ++-- docker-compose.yml | 8 +++----- 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 Dockerfile_dev diff --git a/Dockerfile b/Dockerfile index b9bfae502..c6bc9d990 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN apk add --no-cache build-base yarn postgresql-dev git # Install bundler to run bundle exec # This should be the same version as the Gemfile.lock -RUN gem install bundler:2.2.3 --no-document +RUN gem install bundler:2.3.4 --no-document # Install gems defined in Gemfile COPY .ruby-version Gemfile Gemfile.lock /app/ diff --git a/Dockerfile_dev b/Dockerfile_dev new file mode 100644 index 000000000..aac15d8c6 --- /dev/null +++ b/Dockerfile_dev @@ -0,0 +1,33 @@ +# Build compilation image +FROM ruby:3.0.3-alpine3.14 as builder + +# The application runs from /app +WORKDIR /app + +# Add the timezone as it's not configured by default in Alpine +RUN apk add --update --no-cache tzdata && cp /usr/share/zoneinfo/Europe/London /etc/localtime && echo "Europe/London" > /etc/timezone + +RUN apk add --no-cache build-base yarn postgresql-dev git bash + +# Install bundler to run bundle exec +# This should be the same version as the Gemfile.lock +RUN gem install bundler:2.3.4 --no-document + +# Install gems defined in Gemfile +COPY .ruby-version Gemfile Gemfile.lock /app/ + +ARG BUNDLE_FLAGS="--jobs=4 --no-binstubs --no-cache" +RUN bundle install ${BUNDLE_FLAGS} + +# Install node packages defined in package.json, including webpack +COPY package.json yarn.lock /app/ +RUN yarn install --frozen-lockfile + +# Copy all files to /app (except what is defined in .dockerignore) +COPY . /app/ + +ENV PORT=8080 + +EXPOSE ${PORT} + +CMD RAILS_ENV=${RAILS_ENV} bundle exec rake db:migrate && bundle exec rails s -e ${RAILS_ENV} -p ${PORT} --binding=0.0.0.0 diff --git a/Gemfile.lock b/Gemfile.lock index b985f123e..a4c12148f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT GIT remote: https://github.com/baarkerlounger/devise.git - revision: ac956cc2a58daa57e071202967a212a1dac08053 + revision: 6d0b6b52a9d0e87ae6d9f9acb562169751623078 branch: dluhc-fixes specs: devise (4.8.1) @@ -31,7 +31,7 @@ GIT GIT remote: https://github.com/tagliala/activeadmin.git - revision: d1492c54e76871d95f3a7ff20e445b48f455d4cb + revision: 920f14393bcf56cea9dc155276d20bcd10f4fa85 branch: feature/railties-7 specs: activeadmin (2.9.0) diff --git a/config/database.yml b/config/database.yml index f04b2a776..fae2ddfee 100644 --- a/config/database.yml +++ b/config/database.yml @@ -28,8 +28,8 @@ default: &default development: <<: *default - database: data_collector_development - host: localhost + database: <%= ENV['DB_DATABASE'] || data_collector_development %> + host: <%= ENV['DB_HOST'] || localhost %> staging: <<: *default diff --git a/docker-compose.yml b/docker-compose.yml index 0ca8930a1..fc50f354e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ volumes: services: db: - image: postgres:13.3-alpine + image: postgres:13.5-alpine restart: always # To preserve data between runs of docker-compose, we mount a folder from the host machine. volumes: @@ -20,9 +20,7 @@ services: app: build: context: . - dockerfile: ./Dockerfile - args: - GIT_COMMIT_SHA: DOCKER_COMPOSE_GIT_COMMIT_SHA + dockerfile: ./Dockerfile_dev ports: - 8080:8080 depends_on: @@ -32,7 +30,7 @@ services: - DB_DATABASE=data_collector - DB_USERNAME=postgres - DB_PASSWORD=password - - RAILS_ENV=production + - RAILS_ENV=development - RAILS_SERVE_STATIC_FILES=true - RAILS_LOG_TO_STDOUT=true - SECRET_KEY_BASE=abcd1234