Skip to content

Commit 7ac4d92

Browse files
committed
add fly config
1 parent 101fe06 commit 7ac4d92

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.git
2+
tmp
3+
!tmp/pids
4+
log
5+
public/assets
6+
public/packs
7+
.bundle
8+
9+
db/*.sqlite3
10+
db/*.sqlite3-*
11+
12+
storage
13+
config/master.key
14+
config/credentials/*.key
15+
16+
node_modules

Dockerfile

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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}

fly.toml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# fly.toml file generated for ruby-docs on 2022-12-04T08:18:39+01:00
2+
3+
app = "ruby-docs"
4+
kill_signal = "SIGINT"
5+
kill_timeout = 5
6+
processes = []
7+
8+
[build]
9+
[build.args]
10+
BUILD_COMMAND = "bin/rails fly:build"
11+
SERVER_COMMAND = "bin/rails fly:server"
12+
13+
[deploy]
14+
release_command = "bin/rails fly:release"
15+
16+
[env]
17+
PORT = "8080"
18+
19+
[experimental]
20+
allowed_public_ports = []
21+
auto_rollback = true
22+
23+
[[services]]
24+
http_checks = []
25+
internal_port = 8080
26+
processes = ["app"]
27+
protocol = "tcp"
28+
script_checks = []
29+
[services.concurrency]
30+
hard_limit = 25
31+
soft_limit = 20
32+
type = "connections"
33+
34+
[[services.ports]]
35+
force_https = true
36+
handlers = ["http"]
37+
port = 80
38+
39+
[[services.ports]]
40+
handlers = ["tls", "http"]
41+
port = 443
42+
43+
[[services.tcp_checks]]
44+
grace_period = "1s"
45+
interval = "15s"
46+
restart_limit = 0
47+
timeout = "2s"
48+
49+
[[statics]]
50+
guest_path = "/app/public"
51+
url_prefix = "/"

lib/tasks/fly.rake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# commands used to deploy a Rails application
2+
namespace :fly do
3+
# BUILD step:
4+
# - changes to the filesystem made here DO get deployed
5+
# - NO access to secrets, volumes, databases
6+
# - Failures here prevent deployment
7+
task :build => 'assets:precompile'
8+
9+
# RELEASE step:
10+
# - changes to the filesystem made here are DISCARDED
11+
# - full access to secrets, databases
12+
# - failures here prevent deployment
13+
task :release => 'db:migrate'
14+
15+
# SERVER step:
16+
# - changes to the filesystem made here are deployed
17+
# - full access to secrets, databases
18+
# - failures here result in VM being stated, shutdown, and rolled back
19+
# to last successful deploy (if any).
20+
task :server => :swapfile do
21+
sh 'bin/rails server'
22+
end
23+
24+
# optional SWAPFILE task:
25+
# - adjust fallocate size as needed
26+
# - performance critical applications should scale memory to the
27+
# point where swap is rarely used. 'fly scale help' for details.
28+
# - disable by removing dependency on the :server task, thus:
29+
# task :server do
30+
task :swapfile do
31+
sh 'fallocate -l 512M /swapfile'
32+
sh 'chmod 0600 /swapfile'
33+
sh 'mkswap /swapfile'
34+
sh 'echo 10 > /proc/sys/vm/swappiness'
35+
sh 'swapon /swapfile'
36+
end
37+
end

0 commit comments

Comments
 (0)