Browse Source

feat: update docker files

pull/1804/head
Chirag Bhatti 3 years ago committed by Sam Seed
parent
commit
adf1e9dbe1
  1. 63
      Dockerfile
  2. 41
      Dockerfile_dev
  3. 3
      docker-compose.yml

63
Dockerfile

@ -1,71 +1,50 @@
# Build compilation image FROM ruby:3.1.4-alpine3.18 as base
FROM ruby:3.1.4-alpine as builder
# The application runs from /app
WORKDIR /app WORKDIR /app
# Add the timezone as it's not configured by default in Alpine # Add the timezone as its not configured by default in Alpine
RUN apk add --update --no-cache tzdata && \ RUN apk add --update --no-cache tzdata && \
cp /usr/share/zoneinfo/Europe/London /etc/localtime && \ cp /usr/share/zoneinfo/Europe/London /etc/localtime && \
echo "Europe/London" > /etc/timezone echo "Europe/London" > /etc/timezone
# build-base: complication tools for bundle # build-base: compilation tools for bundle
# yarn: node package manager # yarn: node package manager
# postgresql-dev: postgres driver and libraries # postgresql-dev: postgres driver and libraries
RUN apk add --no-cache build-base yarn postgresql-dev git RUN apk add --no-cache build-base yarn postgresql-dev git bash
# Install bundler to run bundle exec # Bundler version should be the same version as what the Gemfile.lock was bundled with
# This should be the same version as the Gemfile.lock
RUN gem install bundler:2.3.14 --no-document RUN gem install bundler:2.3.14 --no-document
# Install gems defined in Gemfile
COPY .ruby-version Gemfile Gemfile.lock /app/ COPY .ruby-version Gemfile Gemfile.lock /app/
RUN bundle install --jobs=4 --no-binstubs --no-cache
RUN bundle config set without "development test"
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/ COPY package.json yarn.lock /app/
RUN yarn install --frozen-lockfile RUN yarn install --frozen-lockfile
# Copy all files to /app (except what is defined in .dockerignore)
COPY . /app/ COPY . /app/
# Compile assets and run webpack. We set a dummy secret key. RUN bundle exec rake assets:precompile
RUN RAILS_ENV=production bundle exec rails SECRET_KEY_BASE=pickasecuretoken assets:precompile
# Cleanup to save space in the production image ENV PORT=8080
RUN rm -rf node_modules log tmp && \
rm -rf /usr/local/bundle/cache && \
rm -rf .env && \
find /usr/local/bundle/gems -name "*.c" -delete && \
find /usr/local/bundle/gems -name "*.h" -delete && \
find /usr/local/bundle/gems -name "*.o" -delete && \
find /usr/local/bundle/gems -name "*.html" -delete
# Build runtime image EXPOSE ${PORT}
FROM ruby:3.1.4-alpine as production
# The application runs from /app FROM base as development
WORKDIR /app
# Add postgres driver library # Install gecko driver for Capybara tests
# Add the timezone as it's not configured by default in Alpine RUN apk add firefox
RUN apk add --update --no-cache libpq tzdata && \ RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.31.0/geckodriver-v0.31.0-linux64.tar.gz \
cp /usr/share/zoneinfo/Europe/London /etc/localtime && \ && tar -xvzf geckodriver-v0.31.0-linux64.tar.gz \
echo "Europe/London" > /etc/timezone && rm geckodriver-v0.31.0-linux64.tar.gz \
&& chmod +x geckodriver \
&& mv geckodriver /usr/local/bin/
# Copy files generated in the builder image CMD RAILS_ENV=${RAILS_ENV} bundle exec rake db:migrate && bundle exec rails s -e ${RAILS_ENV} -p ${PORT} --binding=0.0.0.0
COPY --from=builder /app /app
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
ARG GIT_COMMIT_SHA="UNKNOWN" FROM base as staging
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
RUN echo ${GIT_COMMIT_SHA} > ./GIT_COMMIT_SHA
ENV PORT=8080 CMD RAILS_ENV=${RAILS_ENV} bundle exec rake db:migrate && bundle exec rails s -e ${RAILS_ENV} -p ${PORT} --binding=0.0.0.0
EXPOSE ${PORT} FROM base as production
CMD RAILS_ENV=${RAILS_ENV} bundle exec rake db:migrate && bundle exec rails s -e ${RAILS_ENV} -p ${PORT} --binding=0.0.0.0 CMD RAILS_ENV=${RAILS_ENV} bundle exec rake db:migrate && bundle exec rails s -e ${RAILS_ENV} -p ${PORT} --binding=0.0.0.0

41
Dockerfile_dev

@ -1,41 +0,0 @@
# Build compilation image
FROM ruby:3.1.4-alpine
# 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.14 --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
# Install gecko driver for Capybara tests
RUN apk add firefox
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.31.0/geckodriver-v0.31.0-linux64.tar.gz \
&& tar -xvzf geckodriver-v0.31.0-linux64.tar.gz \
&& rm geckodriver-v0.31.0-linux64.tar.gz \
&& chmod +x geckodriver \
&& mv geckodriver /usr/local/bin/
# 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

3
docker-compose.yml

@ -20,7 +20,8 @@ services:
app: app:
build: build:
context: . context: .
dockerfile: ./Dockerfile_dev dockerfile: ./Dockerfile
target: development
ports: ports:
- 8080:8080 - 8080:8080
depends_on: depends_on:

Loading…
Cancel
Save