Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
**/*Dockerfile
.dockerignore
.docker/
docker-compose.yml
.git
.gitignore
README.md
VERSION

/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
/storage/*
!/storage/.keep
/node_modules
/yarn-error.log
/public/uploads
/public/assets
.byebug_history
.idea/
.env
77 changes: 77 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# syntax=docker/dockerfile:1

FROM ruby:2.7.4-slim-buster AS Builder

ARG RAILS_ENV=production

ENV RAILS_ENV=${RAILS_ENV} \
APP_HOME=/home/app

RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends curl git make gcc libpq-dev g++ shared-mime-info tzdata vim xz-utils automake pkg-config libtool libffi-dev libssl-dev libgmp-dev python-dev gnupg gnupg2

WORKDIR $APP_HOME
COPY Gemfile Gemfile.lock $APP_HOME/

RUN gem update bundler --no-document
RUN if [ "$RAILS_ENV" = "production" ]; then bundle config set --local without 'development:test:deploy'; fi
RUN bundle config set --local system 'true' \
&& bundle install --jobs=$(nproc) \
&& bundle binstubs --all

FROM Builder AS App
# By default image is built using RAILS_ENV=production.
# You may want to customize it:
#
# --build-arg RAILS_ENV=development
#
# See https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg
#
ARG RAILS_ENV=production

# Devise requires secret key to be set during image build or it raises an error
# preventing from running any scripts.
# Users should override this variable by passing environment variable on container start.
ENV RAILS_ENV=${RAILS_ENV} \
APP_HOME=/home/app

# Create group "app" and user "app".
RUN addgroup --gid 1000 --system app \
&& adduser --system --home ${APP_HOME} --shell /sbin/nologin --ingroup app --uid 1000 app

RUN curl -sS 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 curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs
RUN apt-get update -qq && apt-get install -y build-essential yarn

WORKDIR $APP_HOME
COPY Gemfile Gemfile.lock $APP_HOME/

# Install dependencies
RUN if [ "$RAILS_ENV" = "production" ]; then bundle config set --local without 'development:test:deploy'; fi
RUN bundle config set --local system 'true' \
&& bundle install --jobs=$(nproc) \
&& bundle binstubs --all

RUN apt-get remove -yq git gcc g++ \
&& chown -R app:app $APP_HOME

USER app

# Copy the main application.
COPY --chown=app:app . $APP_HOME

RUN yarn install --check-files
RUN if [ "$RAILS_ENV" = "production" ]; then SECRET_KEY_BASE=secret SKIP_MANAGEMENT_API=true bundle exec rake assets:precompile; fi

# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000

# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
# COPY --chown=app:app config/docker/docker-entrypoint.sh /
# RUN chmod +x /docker-entrypoint.sh
# ENTRYPOINT ["/docker-entrypoint.sh"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby File.read('.ruby-version')
ruby '2.7.4'

gem 'dotenv-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
Expand Down