-
Notifications
You must be signed in to change notification settings - Fork 130
Dockerfile setup improvements #732
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
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
3a80017
WIP
JulianPasquale cd8b02a
WIP: Improve dockerfile, add version for node, yarn
PerezIgnacio a458d08
bundler changes
smerlo 10789f7
Add ENTRYPOINT to dockerfile
guillermoap fa1c8d2
Fix tests with docker
PerezIgnacio e51fee7
Update docker-compose. Do we need to precomiple assets to access the …
JulianPasquale 2169cd7
Merge branch 'main' into improve-dev-docker
PerezIgnacio 271ca0f
Revert "Upgrade to Ruby 3.3 (#571)"
PerezIgnacio 8f5518f
Add support for capybara tests with docker
PerezIgnacio de3c6d7
Change depends_on to web service in compose
PerezIgnacio 9e1f93c
docker compose capybara config
smerlo 775c5ed
Config in spec_helper
PerezIgnacio 73ae605
Merge branch 'main' into improve-dev-docker
JulianPasquale 917d96d
Start with prod Dockerfile
JulianPasquale b999a3f
Improve prod docker file
PerezIgnacio 9f455e3
Progress reducing final image size
JulianPasquale 41cbedd
Use slim image, remove spring, fixes in dockerfile
PerezIgnacio f7d7861
Remove bloated floders from docker build
guillermoap 8103466
add jemalloc to dockerfile.prod
smerlo 618164a
change docker compose
smerlo 458f168
Add back ruby 3.3.0
PerezIgnacio 4f7dc3b
Fix dev dockerfile
PerezIgnacio 10463ec
Merge branch 'main' into improve-dev-docker
PerezIgnacio 825967c
Use bin/dev in docker-compose
PerezIgnacio aec76c5
Fixes
PerezIgnacio d0a1713
Add docs
PerezIgnacio 1c2f6c0
Use watch in docker-compose
JulianPasquale 0c4e291
Separate chrome server to different dockercompose
PerezIgnacio 7903097
Update bin files to execute tests without running the server
axelpontetto ad9db6b
Remove compose dependency + add -rm option to rspec command
JulianPasquale 7c8616f
Fix rspec bin command
JulianPasquale c77ba8f
Merge branch 'main' into improve-dev-docker
JulianPasquale 83b22a4
Docs WIP
JulianPasquale 54f20ff
Update docker.md
smerlo 1457396
Update docker.md
PerezIgnacio ba928cc
Update docker.md
JulianPasquale badeec9
Update command for dev Dockerfile and compose
JulianPasquale 96d4ebd
Merge branch 'main' into improve-dev-docker
PerezIgnacio a21a89b
Fix linters
PerezIgnacio e1ed754
Setup node on GHA
JulianPasquale 1fedd3f
Update yarn version to not include patch number
JulianPasquale 9d6f2cb
Add yarn version && remove compose version
axelpontetto 0797cbd
Fix pr comments
smerlo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,35 +1,46 @@ | ||
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. | ||
|
||
.git | ||
.gitignore | ||
.github | ||
|
||
# Ignore bundler config. | ||
/.bundle | ||
.bundle | ||
|
||
# Ignore all default key files | ||
config/master.key | ||
config/credentials/*.key | ||
|
||
# Ignore all logfiles and tempfiles. | ||
/log/* | ||
/tmp/* | ||
!/log/.keep | ||
!/tmp/.keep | ||
log/* | ||
tmp/* | ||
!log/.keep | ||
!tmp/.keep | ||
|
||
# Ignore pidfiles, but keep the directory. | ||
/tmp/pids/* | ||
!/tmp/pids/ | ||
!/tmp/pids/.keep | ||
tmp/pids/* | ||
!tmp/pids/ | ||
!tmp/pids/.keep | ||
|
||
# Ignore storage (uploaded files in development and any SQLite databases). | ||
/storage/* | ||
!/storage/.keep | ||
/tmp/storage/* | ||
!/tmp/storage/ | ||
!/tmp/storage/.keep | ||
storage/* | ||
!storage/.keep | ||
tmp/storage/* | ||
!tmp/storage/ | ||
!tmp/storage/.keep | ||
|
||
public/assets | ||
|
||
/public/assets | ||
coverage | ||
|
||
# Ignore node_modules | ||
/node_modules | ||
node_modules | ||
|
||
# Ignore .env files | ||
!.env.test | ||
.env* | ||
!.env.test | ||
|
||
.DS_Store | ||
.byebug_history | ||
|
||
vendor/bundle |
This file contains hidden or 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 hidden or 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 @@ | ||
20.10.0 |
This file contains hidden or 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,45 +1,88 @@ | ||
FROM ruby:3.3.1 | ||
ARG RUBY_VERSION=3.3.1 | ||
ARG NODE_VERSION=20.10.0 | ||
ARG YARN_VERSION=1.22.19 | ||
|
||
RUN apt-get update -qq && \ | ||
apt-get install -y build-essential libssl-dev libpq-dev less vim nano libsasl2-dev | ||
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 mkdir -p /etc/apt/keyrings | ||
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg | ||
|
||
ENV NODE_MAJOR=18 | ||
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list | ||
# Use Node image so we can pull the binaries from here. | ||
FROM node:$NODE_VERSION as node | ||
|
||
RUN apt update && apt install -y yarn nodejs | ||
# Ruby build image. | ||
FROM ruby:${RUBY_VERSION}-slim as base | ||
|
||
# Setup environment variables. | ||
ENV WORK_ROOT /src | ||
ENV APP_HOME $WORK_ROOT/myapp/ | ||
ENV APP_HOME $WORK_ROOT/app | ||
ENV LANG C.UTF-8 | ||
ENV GEM_HOME $WORK_ROOT/bundle | ||
ENV BUNDLE_BIN $GEM_HOME/gems/bin | ||
ENV PATH $GEM_HOME/bin:$BUNDLE_BIN:$PATH | ||
ENV BUNDLE_PATH $APP_HOME/vendor/bundle | ||
|
||
# Set prod environment to avoid installing dev dependencies | ||
ENV BUNDLE_WITHOUT development:test | ||
ENV BUNDLE_DEPLOYMENT 1 | ||
ENV RAILS_ENV production | ||
ENV NODE_ENV production | ||
smerlo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Throw-away build stage to reduce size of final image | ||
FROM base as builder | ||
|
||
RUN gem install bundler | ||
RUN apt-get update -qq && \ | ||
apt-get install -y build-essential libssl-dev libpq-dev git libsasl2-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy node binaries from node image. | ||
COPY --from=node /usr/local /usr/local | ||
COPY --from=node /opt /opt | ||
|
||
# Create app directory. | ||
RUN mkdir -p $APP_HOME | ||
|
||
RUN bundle config --path=$GEM_HOME | ||
# Setup work directory. | ||
WORKDIR $APP_HOME | ||
|
||
# Copy dependencies files and install libraries. | ||
COPY --link Gemfile Gemfile.lock package.json yarn.lock ./ | ||
|
||
RUN gem install bundler && bundle install -j 4 && yarn install --frozen-lockfile && \ | ||
bundle exec bootsnap precompile --gemfile && \ | ||
rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git | ||
|
||
# Copy application code | ||
COPY --link . . | ||
|
||
# Precompile bootsnap code for faster boot times | ||
RUN bundle exec bootsnap precompile app/ lib/ | ||
|
||
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY | ||
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile | ||
|
||
# Build runtime image. | ||
FROM base | ||
|
||
# Install packages needed for deployment | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y curl libpq-dev libvips libjemalloc2 && \ | ||
apt-get clean | ||
|
||
# Create app directory. | ||
RUN mkdir -p $APP_HOME | ||
|
||
# Setup work directory. | ||
WORKDIR $APP_HOME | ||
|
||
ADD Gemfile ./ | ||
ADD Gemfile.lock ./ | ||
RUN bundle update --bundler | ||
RUN bundle install | ||
# Copy everything from the builder image | ||
COPY --link . . | ||
COPY --from=builder $APP_HOME/public/ $APP_HOME/public/ | ||
COPY --from=builder $APP_HOME/tmp/ $APP_HOME/tmp/ | ||
COPY --from=builder $APP_HOME/vendor/ $APP_HOME/vendor/ | ||
|
||
ADD package.json ./ | ||
ADD yarn.lock ./ | ||
RUN ln -s /usr/lib/*-linux-gnu/libjemalloc.so.2 /usr/lib/libjemalloc.so.2 | ||
|
||
RUN yarn install | ||
# Deployment options | ||
ENV RAILS_LOG_TO_STDOUT true | ||
ENV RAILS_SERVE_STATIC_FILES true | ||
ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2 | ||
|
||
ADD . $APP_HOME | ||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["./bin/docker-entrypoint"] | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
|
||
ENTRYPOINT bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -b 0.0.0.0 -p 3000" | ||
CMD ["./bin/rails", "server"] |
This file contains hidden or 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,47 @@ | ||
ARG RUBY_VERSION=3.3.1 | ||
ARG NODE_VERSION=20.10.0 | ||
ARG YARN_VERSION=1.22.19 | ||
|
||
# Use Node image so we can pull the binaries from here. | ||
FROM node:$NODE_VERSION as node | ||
|
||
# Ruby build image. | ||
FROM ruby:${RUBY_VERSION}-slim | ||
|
||
RUN apt-get update -qq && \ | ||
apt-get install -y build-essential libssl-dev libpq-dev vim git libsasl2-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
smerlo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Copy node binaries from node image. | ||
COPY --from=node /usr/local /usr/local | ||
COPY --from=node /opt /opt | ||
|
||
# Setup environment variables. | ||
ENV WORK_ROOT /src | ||
ENV APP_HOME $WORK_ROOT/app/ | ||
ENV LANG C.UTF-8 | ||
ENV BUNDLE_PATH $WORK_ROOT/bundle | ||
|
||
# Create app directory. | ||
RUN mkdir -p $APP_HOME | ||
|
||
# Setup work directory. | ||
WORKDIR $APP_HOME | ||
|
||
RUN gem install foreman bundler | ||
|
||
# Copy dependencies files and install libraries. | ||
COPY --link package.json yarn.lock ./ | ||
RUN yarn install --frozen-lockfile | ||
|
||
COPY --link Gemfile Gemfile.lock ./ | ||
RUN bundle install -j 4 | ||
|
||
COPY --link . . | ||
|
||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["./bin/docker-entrypoint"] | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
CMD ["./bin/dev"] |
This file contains hidden or 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 |
---|---|---|
|
@@ -669,7 +669,7 @@ DEPENDENCIES | |
yaaf (~> 2.2) | ||
|
||
RUBY VERSION | ||
ruby 3.3.1p55 | ||
ruby 3.3.1p55 | ||
|
||
BUNDLED WITH | ||
2.5.10 | ||
2.5.10 |
This file contains hidden or 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,2 +1,2 @@ | ||
web: bin/rails server -p3000 | ||
web: ./bin/rails server -p 3000 -b 0.0.0.0 | ||
js: yarn build --watch |
This file contains hidden or 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,12 @@ | ||
#!/bin/bash -e | ||
|
||
santib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# If running the rails server then create or migrate existing database | ||
if ([ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]) || [ "${1}" == "./bin/dev" ]; then | ||
./bin/rails db:prepare | ||
fi | ||
|
||
if [ "${1}" == "./bin/rspec" ]; then | ||
./bin/rails db:test:prepare | ||
fi | ||
|
||
exec "${@}" |
This file contains hidden or 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 hidden or 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 hidden or 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,10 +1,26 @@ | ||
#!/usr/bin/env ruby | ||
require 'shellwords' | ||
require_relative 'helpers' | ||
require 'optparse' | ||
|
||
options = {} | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: ./bin/rspec [options]" | ||
|
||
opts.on("-rm", "--remove-containers", "If provided, all services will be stopped after the test is completed.") do | ||
options[:remove_containers] = true | ||
end | ||
end.parse! | ||
|
||
if running_with_docker? | ||
exec "bin/web 'ITERATIONS=#{ENV['ITERATIONS']} bin/rspec #{Shellwords.join(ARGV)}'" | ||
compose_command = "docker compose -f docker-compose.test.yml run --build web ./bin/rspec #{Shellwords.join(ARGV)}" | ||
|
||
if options[:remove_containers] | ||
compose_command += '&& docker compose -f docker-compose.test.yml down' | ||
end | ||
|
||
exec "ITERATIONS=#{ENV['ITERATIONS']} #{compose_command}" | ||
else | ||
require 'bundler/setup' | ||
load Gem.bin_path('rspec-core', 'rspec') | ||
load(Gem.bin_path('rspec-core', 'rspec')) | ||
end |
This file contains hidden or 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 hidden or 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,32 @@ | ||
name: 'tests' | ||
|
||
services: | ||
chrome-server: | ||
image: seleniarm/standalone-chromium | ||
ports: | ||
- 4444:4444 | ||
- 7900:7900 | ||
- 5900:5900 | ||
web: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.dev | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_HOST: db | ||
SELENIUM_BROWSER: remote | ||
SELENIUM_BROWSER_HOST: http://chrome-server:4444 | ||
HEADLESS: true | ||
tty: true | ||
stdin_open: true | ||
depends_on: | ||
- db | ||
- chrome-server | ||
links: | ||
- db:db | ||
- chrome-server:chrome-server | ||
db: | ||
image: postgres:15 | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_HOST_AUTH_METHOD: trust |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.