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

WIP / Docker setup #153

Open
wants to merge 4 commits into
base: master
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
23 changes: 18 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
/log/*
/tmp/*
/node_modules
/.bundle
/public/assets
.byebug_history
.env*
.git
.gitignore
.dockerignore
.github/*
Brewfile
Procfile*
docker-compose.*
Dockerfile
coverage/*
log/*
node_modules/*
public/assets/*
storage/*
public/packs/*
public/packs-test/*
tmp/*
Empty file added .yarnclean
Empty file.
88 changes: 77 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,84 @@
FROM ruby:2.6.3-alpine
######################
# Stage: Builder
FROM ruby:2.6.5-alpine as Builder

RUN apk add --update --no-cache bash build-base nodejs sqlite-dev tzdata postgresql-dev yarn git
ARG FOLDERS_TO_REMOVE
ARG BUNDLE_WITHOUT
ARG RAILS_ENV

RUN gem install bundler:2.0.2
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
ENV RAILS_ENV ${RAILS_ENV}
ENV SECRET_KEY_BASE=foo
ENV RAILS_SERVE_STATIC_FILES=true

WORKDIR /usr/src/app
RUN apk add --update --no-cache \
build-base \
postgresql-dev \
git \
imagemagick \
nodejs \
yarn \
tzdata

COPY package.json yarn.lock ./
RUN yarn install --check-files
WORKDIR /app

COPY Gemfile* ./
RUN bundle install
# Install gems
ADD Gemfile* /app/
RUN bundle config --global frozen 1 \
&& bundle install -j4 --retry 3 \
# Remove unneeded files (cached *.gem, *.o, *.c)
&& rm -rf /usr/local/bundle/cache/*.gem \
&& find /usr/local/bundle/gems/ -name "*.c" -delete \
&& find /usr/local/bundle/gems/ -name "*.o" -delete

COPY . .
# Install yarn packages
COPY package.json yarn.lock .yarnclean /app/
RUN yarn install

ENV PATH=./bin:$PATH
CMD ["rails", "console"]
# Add the Rails app
ADD . /app

# Precompile assets
RUN bundle exec rake assets:precompile

# Remove folders not needed in resulting image
RUN rm -rf $FOLDERS_TO_REMOVE

###############################
# Stage Final
FROM ruby:2.6.5-alpine
LABEL maintainer="[email protected]"

ARG ADDITIONAL_PACKAGES

# Add Alpine packages
RUN apk add --update --no-cache \
postgresql-client \
imagemagick \
$ADDITIONAL_PACKAGES \
tzdata \
file

# Add user
RUN addgroup -g 1000 -S app \
&& adduser -u 1000 -S app -G app
USER app

# Copy app with gems from former build stage
COPY --from=Builder /usr/local/bundle/ /usr/local/bundle/
COPY --from=Builder --chown=app:app /app /app

# Set Rails env
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_SERVE_STATIC_FILES true

WORKDIR /app

# Expose Puma port
EXPOSE 3000

# Save timestamp of image building
RUN date -u > BUILD_TIME

# Start up
CMD ["docker/startup.sh"]
21 changes: 11 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'
ruby '~> 2.6'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
gem 'puma', '~> 4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
gem 'webpacker', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
gem 'redis', '~> 4.1'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

Expand All @@ -32,10 +30,11 @@ gem 'awesome_print'
gem 'devise', '~> 4.7'
gem 'ffaker'
gem 'gettext_i18n_rails'
gem 'rack-cors'
gem 'rack'
gem 'rack-cors', require: 'rack/cors'
gem 'rest-client'
gem 'sentry-raven'
gem 'sidekiq', '5.2.7'
gem 'sidekiq'
gem 'simple_form', '~> 5.0'
gem 'slim', '~> 4.0'
gem 'validates_email_format_of'
Expand All @@ -53,12 +52,13 @@ gem 'blind_index'
gem 'logstop'

group :development, :test do
# Security Audit for installed Gems
gem 'bundler-audit'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'database_cleaner'
gem 'dotenv-rails'
gem 'factory_bot_rails'
gem 'ffaker'
gem 'rspec-rails'
end

Expand All @@ -68,12 +68,13 @@ group :development do
gem 'gettext', '>=3.0.2', require: false
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'listen', '>= 3.0.5', '< 3.3'
# Find translations inside haml/slim files
gem 'ruby_parser', require: false
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'spring-commands-rspec'
end

group :test do
Expand Down
Loading