-
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.
Build procfile for solidq/sqlite3 combination
- Loading branch information
Showing
9 changed files
with
150 additions
and
6 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,82 @@ | ||
# 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 pkg-config | ||
|
||
# Install application gems | ||
COPY 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 . . | ||
|
||
# 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 libsqlite3-0 ruby-foreman && \ | ||
rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
|
||
RUN gem install foreman | ||
|
||
# Copy built artifacts: gems, application | ||
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" | ||
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 && \ | ||
mkdir /data && \ | ||
chown -R rails:rails db log storage tmp /data | ||
USER rails:rails | ||
|
||
# Deployment options | ||
ENV DATABASE_URL="sqlite3:///data/production.sqlite3" | ||
|
||
# Entrypoint prepares the database. | ||
ENTRYPOINT ["/rails/bin/docker-entrypoint"] | ||
|
||
# Build a Procfile for production use | ||
COPY <<-"EOF" /rails/Procfile.prod | ||
rails: ./bin/rails server | ||
solidq: bundle exec rake solid_queue:start | ||
EOF | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
VOLUME /data | ||
CMD ["foreman", "start", "--procfile=Procfile.prod"] |
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,22 @@ | ||
version: "3.8" | ||
|
||
services: | ||
web: | ||
build: | ||
context: . | ||
args: | ||
UID: ${UID:-1000} | ||
GID: ${GID:-${UID:-1000}} | ||
volumes: | ||
- ./log:/rails/log | ||
- ./storage:/rails/storage | ||
ports: | ||
- "3000:3000" | ||
environment: | ||
secrets: | ||
- source: master_key | ||
target: /rails/config/master.key | ||
|
||
secrets: | ||
master_key: | ||
file: ./config/master.key |
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,8 @@ | ||
[mounts] | ||
source="data" | ||
destination="/data" | ||
|
||
[[statics]] | ||
guest_path = "/rails/public" | ||
url_prefix = "/" | ||
|
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "fileutils" | ||
|
||
require_relative "base" | ||
|
||
class TestSolidQueueSqlite3 < TestBase | ||
@rails_options = "--database=sqlite3" | ||
@generate_options = "--compose" | ||
|
||
def app_setup | ||
system "bundle add solid_queue" | ||
FileUtils.touch "fly.toml" | ||
IO.write "app/jobs/DummyJob.rb", "class DummyJob < ApplicationJob; end" | ||
end | ||
|
||
def test_solidq | ||
check_dockerfile | ||
check_toml | ||
check_compose | ||
end | ||
end |