|
| 1 | +# syntax = docker/dockerfile:experimental |
| 2 | + |
| 3 | +# Dockerfile used to build a deployable image for a Rails application. |
| 4 | +# Adjust as required. |
| 5 | +# |
| 6 | +# Common adjustments you may need to make over time: |
| 7 | +# * Modify version numbers for Ruby, Bundler, and other products. |
| 8 | +# * Add library packages needed at build time for your gems, node modules. |
| 9 | +# * Add deployment packages needed by your application |
| 10 | +# * Add (often fake) secrets needed to compile your assets |
| 11 | + |
| 12 | +####################################################################### |
| 13 | + |
| 14 | +# Learn more about the chosen Ruby stack, Fullstaq Ruby, here: |
| 15 | +# https://github.com/evilmartians/fullstaq-ruby-docker. |
| 16 | +# |
| 17 | +# We recommend using the highest patch level for better security and |
| 18 | +# performance. |
| 19 | + |
| 20 | +ARG RUBY_VERSION=3.1.2 |
| 21 | +ARG VARIANT=jemalloc-bullseye-slim |
| 22 | +FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base |
| 23 | + |
| 24 | +LABEL fly_launch_runtime="rails" |
| 25 | + |
| 26 | +ARG BUNDLER_VERSION=2.3.26 |
| 27 | + |
| 28 | +ARG RAILS_ENV=production |
| 29 | +ENV RAILS_ENV=${RAILS_ENV} |
| 30 | + |
| 31 | +ENV RAILS_SERVE_STATIC_FILES true |
| 32 | +ENV RAILS_LOG_TO_STDOUT true |
| 33 | + |
| 34 | +ARG BUNDLE_WITHOUT=development:test |
| 35 | +ARG BUNDLE_PATH=vendor/bundle |
| 36 | +ENV BUNDLE_PATH ${BUNDLE_PATH} |
| 37 | +ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT} |
| 38 | + |
| 39 | +RUN mkdir /app |
| 40 | +WORKDIR /app |
| 41 | +RUN mkdir -p tmp/pids |
| 42 | + |
| 43 | +RUN gem update --system --no-document && \ |
| 44 | + gem install -N bundler -v ${BUNDLER_VERSION} |
| 45 | + |
| 46 | +####################################################################### |
| 47 | + |
| 48 | +# install packages only needed at build time |
| 49 | + |
| 50 | +FROM base as build_deps |
| 51 | + |
| 52 | +ARG BUILD_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev" |
| 53 | +ENV BUILD_PACKAGES ${BUILD_PACKAGES} |
| 54 | + |
| 55 | +RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \ |
| 56 | + --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \ |
| 57 | + apt-get update -qq && \ |
| 58 | + apt-get install --no-install-recommends -y ${BUILD_PACKAGES} && \ |
| 59 | + rm -rf /var/lib/apt/lists /var/cache/apt/archives |
| 60 | + |
| 61 | +####################################################################### |
| 62 | + |
| 63 | +# install gems |
| 64 | + |
| 65 | +FROM build_deps as gems |
| 66 | + |
| 67 | +COPY Gemfile* ./ |
| 68 | +RUN bundle install && rm -rf vendor/bundle/ruby/*/cache |
| 69 | + |
| 70 | +####################################################################### |
| 71 | + |
| 72 | +# install deployment packages |
| 73 | + |
| 74 | +FROM base |
| 75 | + |
| 76 | +ARG DEPLOY_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0" |
| 77 | +ENV DEPLOY_PACKAGES=${DEPLOY_PACKAGES} |
| 78 | + |
| 79 | +RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \ |
| 80 | + --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \ |
| 81 | + apt-get update -qq && \ |
| 82 | + apt-get install --no-install-recommends -y ${DEPLOY_PACKAGES} && \ |
| 83 | + rm -rf /var/lib/apt/lists /var/cache/apt/archives |
| 84 | + |
| 85 | +# copy installed gems |
| 86 | +COPY --from=gems /app /app |
| 87 | +COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions |
| 88 | +COPY --from=gems /usr/local/bundle /usr/local/bundle |
| 89 | + |
| 90 | +####################################################################### |
| 91 | + |
| 92 | +# Deploy your application |
| 93 | +COPY . . |
| 94 | + |
| 95 | +# Adjust binstubs to run on Linux and set current working directory |
| 96 | +RUN chmod +x /app/bin/* && \ |
| 97 | + sed -i 's/ruby.exe\r*/ruby/' /app/bin/* && \ |
| 98 | + sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/* |
| 99 | + |
| 100 | +# The following enable assets to precompile on the build server. Adjust |
| 101 | +# as necessary. If no combination works for you, see: |
| 102 | +# https://fly.io/docs/rails/getting-started/existing/#access-to-environment-variables-at-build-time |
| 103 | +ENV SECRET_KEY_BASE 1 |
| 104 | +# ENV AWS_ACCESS_KEY_ID=1 |
| 105 | +# ENV AWS_SECRET_ACCESS_KEY=1 |
| 106 | + |
| 107 | +# Run build task defined in lib/tasks/fly.rake |
| 108 | +ARG BUILD_COMMAND="bin/rails fly:build" |
| 109 | +RUN ${BUILD_COMMAND} |
| 110 | + |
| 111 | +# Default server start instructions. Generally Overridden by fly.toml. |
| 112 | +ENV PORT 8080 |
| 113 | +ARG SERVER_COMMAND="bin/rails fly:server" |
| 114 | +ENV SERVER_COMMAND ${SERVER_COMMAND} |
| 115 | +CMD ${SERVER_COMMAND} |
0 commit comments