generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
111 changed files
with
2,005 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
brew "postgresql" | ||
brew "redis" | ||
brew "rbenv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,101 @@ | ||
# BUILD STAGE # | ||
FROM ruby:2.6.6 AS build | ||
# ------------------------------------------------------------------------------ | ||
# Base | ||
# ------------------------------------------------------------------------------ | ||
FROM ruby:2.6.6 as base | ||
MAINTAINER dxw <[email protected]> | ||
|
||
ENV INSTALL_PATH /srv/app | ||
ARG RAILS_ENV | ||
ENV RAILS_ENV=${RAILS_ENV:-production} | ||
ENV RACK_ENV=${RAILS_ENV:-production} | ||
|
||
WORKDIR $INSTALL_PATH | ||
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash | ||
RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - | ||
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list | ||
|
||
RUN apt-get update && apt-get install -qq -y \ | ||
build-essential \ | ||
libpq-dev \ | ||
--fix-missing --no-install-recommends | ||
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \ | ||
&& apt-get install -y nodejs | ||
|
||
COPY package.json ./package.json | ||
COPY package-lock.json ./package-lock.json | ||
ENV APP_HOME /srv/app | ||
ENV DEPS_HOME /deps | ||
|
||
RUN npm install | ||
ARG RAILS_ENV | ||
ENV RAILS_ENV ${RAILS_ENV:-production} | ||
ENV NODE_ENV ${RAILS_ENV:-production} | ||
|
||
COPY Gemfile* ./ | ||
RUN gem install bundler:2.1.4 --no-document | ||
# ------------------------------------------------------------------------------ | ||
# Dependencies | ||
# ------------------------------------------------------------------------------ | ||
FROM base AS dependencies | ||
|
||
ARG BUNDLE_EXTRA_GEM_GROUPS | ||
ENV BUNDLE_GEM_GROUPS=${BUNDLE_EXTRA_GEM_GROUPS:-"production"} | ||
RUN bundle config set no-cache "true" | ||
RUN bundle config set with $BUNDLE_GEM_GROUPS | ||
RUN bundle install --no-binstubs --retry=3 --jobs=4 | ||
RUN mkdir -p ${DEPS_HOME} | ||
WORKDIR $DEPS_HOME | ||
|
||
# Copy app code (sorted by vague frequency of change for caching) | ||
RUN mkdir -p ${INSTALL_PATH}/log | ||
RUN mkdir -p ${INSTALL_PATH}/tmp | ||
|
||
COPY config.ru ${INSTALL_PATH}/config.ru | ||
COPY Rakefile ${INSTALL_PATH}/Rakefile | ||
|
||
COPY public ${INSTALL_PATH}/public | ||
COPY vendor ${INSTALL_PATH}/vendor | ||
COPY bin ${INSTALL_PATH}/bin | ||
COPY lib ${INSTALL_PATH}/lib | ||
COPY config ${INSTALL_PATH}/config | ||
COPY db ${INSTALL_PATH}/db | ||
COPY script ${INSTALL_PATH}/script | ||
COPY spec ${INSTALL_PATH}/spec | ||
COPY app ${INSTALL_PATH}/app | ||
# End | ||
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \ | ||
&& apt-get install -y nodejs | ||
|
||
# RELEASE STAGE # | ||
FROM ruby:2.6.6 AS release | ||
# Install Javascript dependencies | ||
COPY package-lock.json $DEPS_HOME/package-lock.json | ||
COPY package.json $DEPS_HOME/package.json | ||
RUN npm install | ||
|
||
ENV INSTALL_PATH /srv/app | ||
ARG RAILS_ENV | ||
ENV RAILS_ENV=${RAILS_ENV:-production} | ||
ENV RACK_ENV=${RAILS_ENV:-production} | ||
# Install Ruby dependencies | ||
COPY Gemfile $DEPS_HOME/Gemfile | ||
COPY Gemfile.lock $DEPS_HOME/Gemfile.lock | ||
RUN gem update --system | ||
RUN gem install bundler -v 2.2.16 | ||
|
||
WORKDIR $INSTALL_PATH | ||
ENV BUNDLE_GEM_GROUPS=$RAILS_ENV | ||
RUN bundle config set frozen "true" | ||
RUN bundle config set no-cache "true" | ||
RUN bundle config set with $BUNDLE_GEM_GROUPS | ||
RUN bundle install --no-binstubs --retry=10 --jobs=4 | ||
|
||
RUN gem install bundler:2.1.4 --no-document | ||
# ------------------------------------------------------------------------------ | ||
# Web | ||
# ------------------------------------------------------------------------------ | ||
FROM dependencies AS web | ||
|
||
COPY --from=build /usr/local/bundle/ /usr/local/bundle/ | ||
COPY --from=build $INSTALL_PATH $INSTALL_PATH | ||
RUN mkdir -p ${APP_HOME} | ||
WORKDIR ${APP_HOME} | ||
|
||
# Copy app code (sorted by vague frequency of change for caching) | ||
RUN mkdir -p ${APP_HOME}/log | ||
RUN mkdir -p ${APP_HOME}/tmp | ||
|
||
COPY config.ru ${APP_HOME}/config.ru | ||
COPY Rakefile ${APP_HOME}/Rakefile | ||
|
||
COPY Gemfile $APP_HOME/Gemfile | ||
COPY Gemfile.lock $APP_HOME/Gemfile.lock | ||
|
||
COPY public ${APP_HOME}/public | ||
COPY vendor ${APP_HOME}/vendor | ||
COPY bin ${APP_HOME}/bin | ||
COPY lib ${APP_HOME}/lib | ||
COPY config ${APP_HOME}/config | ||
COPY db ${APP_HOME}/db | ||
COPY script ${APP_HOME}/script | ||
COPY app ${APP_HOME}/app | ||
# End | ||
|
||
# Compiling assets requires a key to exist: https://github.com/rails/rails/issues/32947 | ||
RUN if [ "$RAILS_ENV" = "production" ]; then \ | ||
RAILS_ENV=production SECRET_KEY_BASE="key" bundle exec rake assets:precompile; \ | ||
fi | ||
# Create tmp/pids | ||
RUN mkdir -p tmp/pids | ||
|
||
# This must be ordered before rake assets:precompile | ||
RUN cp -R $DEPS_HOME/node_modules $APP_HOME/node_modules | ||
RUN cp -R $DEPS_HOME/node_modules/govuk-frontend/govuk/assets $APP_HOME/app/assets | ||
|
||
RUN RAILS_ENV=production \ | ||
SECRET_KEY_BASE="key" \ | ||
APPLICATION_URL= \ | ||
CONTENTFUL_URL= \ | ||
CONTENTFUL_SPACE= \ | ||
CONTENTFUL_ENVIRONMENT= \ | ||
CONTENTFUL_ACCESS_TOKEN= \ | ||
CONTENTFUL_DEFAULT_CATEGORY_ENTRY_ID= \ | ||
CONTENTFUL_PREVIEW_APP= \ | ||
CONTENTFUL_ENTRY_CACHING= \ | ||
SUPPORT_EMAIL= \ | ||
REDIS_URL= \ | ||
bundle exec rake assets:precompile | ||
|
||
COPY ./docker-entrypoint.sh / | ||
RUN chmod +x /docker-entrypoint.sh | ||
|
@@ -75,3 +104,16 @@ ENTRYPOINT ["/docker-entrypoint.sh"] | |
EXPOSE 3000 | ||
|
||
CMD ["bundle", "exec", "rails", "server"] | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Test | ||
# ------------------------------------------------------------------------------ | ||
FROM web as test | ||
|
||
RUN apt-get install -qq -y shellcheck | ||
|
||
COPY package.json ${APP_HOME}/package.json | ||
COPY package-lock.json ${APP_HOME}/package-lock.json | ||
|
||
COPY .rspec ${APP_HOME}/.rspec | ||
COPY spec ${APP_HOME}/spec |
Oops, something went wrong.