-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
4 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,68 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile | ||
ARG RUBY_VERSION=xxx | ||
FROM ruby:$RUBY_VERSION-slim as base | ||
|
||
# Rails app lives here | ||
WORKDIR /rails | ||
|
||
# Set production environment | ||
ENV BUNDLE_DEPLOYMENT="1" \ | ||
BUNDLE_PATH="/usr/local/bundle" \ | ||
BUNDLE_WITHOUT="development:test" \ | ||
RAILS_ENV="production" | ||
|
||
# Update gems and bundler | ||
RUN gem update --system --no-document && \ | ||
gem install -N bundler | ||
|
||
|
||
# Throw-away build stage to reduce size of final image | ||
FROM base as build | ||
|
||
# Install packages needed to build gems | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y build-essential libpq-dev | ||
|
||
# Install application gems | ||
COPY --link Gemfile Gemfile.lock ./ | ||
RUN bundle install && \ | ||
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=1 ./bin/rails assets:precompile | ||
|
||
|
||
# Final stage for app image | ||
FROM base | ||
|
||
# Install packages needed for deployment | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y curl postgresql-client && \ | ||
rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
|
||
# Copy built artifacts: gems, application | ||
COPY --from=build /usr/local/bundle /usr/local/bundle | ||
COPY --from=build /rails /rails | ||
|
||
# Run and own only the runtime files as a non-root user for security | ||
ARG UID=xxx \ | ||
GID=1000 | ||
RUN groupadd -f -g $GID rails && \ | ||
useradd -u $UID -g $GID rails --create-home --shell /bin/bash && \ | ||
chown -R rails:rails db log storage tmp | ||
USER rails:rails | ||
|
||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["/rails/bin/docker-entrypoint"] | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 |
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,44 @@ | ||
version: "3.8" | ||
services: | ||
web: | ||
build: | ||
context: . | ||
args: | ||
UID: ${UID:-1000} | ||
GID: ${GID:-${UID:-1000}} | ||
ports: | ||
- "3000:3000" | ||
environment: | ||
- RAILS_MASTER_KEY=$RAILS_MASTER_KEY | ||
- DATABASE_URL=postgres://root:password@postgres-db/ | ||
depends_on: | ||
postgres-db: | ||
condition: service_healthy | ||
|
||
postgres-db: | ||
image: postgres | ||
environment: | ||
POSTGRES_USER: root | ||
POSTGRES_PASSWORD: password | ||
volumes: | ||
- ./tmp/db:/var/lib/postgresql/data | ||
ports: | ||
- "5432:5432" | ||
healthcheck: | ||
test: pg_isready | ||
interval: 2s | ||
timeout: 5s | ||
retries: 30 | ||
|
||
solidq: | ||
build: . | ||
command: bundle exec rake solid_queue:start | ||
environment: | ||
- RAILS_MASTER_KEY=$RAILS_MASTER_KEY | ||
- REDIS_URL=redis://redis-db:6379 | ||
- DATABASE_URL=postgres://root:password@postgres-db/ | ||
depends_on: | ||
redis-db: | ||
condition: service_started | ||
postgres-db: | ||
condition: service_healthy |
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,4 @@ | ||
|
||
[processes] | ||
app = "./bin/rails server" | ||
solidq = "bundle exec rake solid_queue:start" |
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require "fileutils" | ||
|
||
require_relative "base" | ||
|
||
class TestSolidQueue < TestBase | ||
@rails_options = "--database=postgresql" | ||
@generate_options = "--compose" | ||
|
||
def app_setup | ||
system "bundle add solid_queue" | ||
FileUtils.touch "fly.toml" | ||
end | ||
|
||
def test_solidq | ||
check_dockerfile | ||
check_toml | ||
check_compose | ||
end | ||
end |