Skip to content

Commit 784f601

Browse files
authored
Merge pull request #1 from lu-jim/update-24
Update deployment
2 parents d7710f2 + 5accdd7 commit 784f601

11 files changed

+195
-7
lines changed

.dockerignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2+
3+
# Ignore git directory.
4+
/.git/
5+
6+
# Ignore bundler config.
7+
/.bundle
8+
9+
# Ignore all environment files (except templates).
10+
/.env*
11+
!/.env*.erb
12+
13+
# Ignore all default key files.
14+
/config/master.key
15+
/config/credentials/*.key
16+
17+
# Ignore all logfiles and tempfiles.
18+
/log/*
19+
/tmp/*
20+
!/log/.keep
21+
!/tmp/.keep
22+
23+
# Ignore pidfiles, but keep the directory.
24+
/tmp/pids/*
25+
!/tmp/pids/.keep
26+
27+
# Ignore storage (uploaded files in development and any SQLite databases).
28+
/storage/*
29+
!/storage/.keep
30+
/tmp/storage/*
31+
!/tmp/storage/.keep
32+
33+
# Ignore assets.
34+
/node_modules/
35+
/app/assets/builds/*
36+
!/app/assets/builds/.keep
37+
/public/assets

.github/workflows/fly-deploy.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl deploy --remote-only
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.16.0

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.1
1+
3.3.3

Dockerfile

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4+
ARG RUBY_VERSION=3.3.3
5+
FROM ruby:$RUBY_VERSION-slim as base
6+
7+
LABEL fly_launch_runtime="rails"
8+
9+
# Rails app lives here
10+
WORKDIR /rails
11+
12+
# Set production environment
13+
ENV BUNDLE_DEPLOYMENT="1" \
14+
BUNDLE_PATH="/usr/local/bundle" \
15+
BUNDLE_WITHOUT="development:test" \
16+
RAILS_ENV="production"
17+
18+
# Update gems and bundler
19+
RUN gem update --system --no-document && \
20+
gem install -N bundler
21+
22+
23+
# Throw-away build stage to reduce size of final image
24+
FROM base as build
25+
26+
# Install packages needed to build gems and node modules
27+
RUN apt-get update -qq && \
28+
apt-get install --no-install-recommends -y build-essential curl libpq-dev node-gyp pkg-config python-is-python3
29+
30+
# Install Node.js
31+
ARG NODE_VERSION=20.16.0
32+
ENV PATH=/usr/local/node/bin:$PATH
33+
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
34+
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
35+
rm -rf /tmp/node-build-master
36+
37+
# Install application gems
38+
COPY --link Gemfile Gemfile.lock ./
39+
RUN bundle install && \
40+
bundle exec bootsnap precompile --gemfile && \
41+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
42+
43+
# Install node modules
44+
COPY --link package.json package-lock.json ./
45+
RUN npm install
46+
47+
# Copy application code
48+
COPY --link . .
49+
50+
# Precompile bootsnap code for faster boot times
51+
RUN bundle exec bootsnap precompile app/ lib/
52+
53+
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
54+
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
55+
56+
57+
# Final stage for app image
58+
FROM base
59+
60+
# Install packages needed for deployment
61+
RUN apt-get update -qq && \
62+
apt-get install --no-install-recommends -y curl postgresql-client && \
63+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
64+
65+
# Copy built artifacts: gems, application
66+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
67+
COPY --from=build /rails /rails
68+
69+
# Run and own only the runtime files as a non-root user for security
70+
RUN groupadd --system --gid 1000 rails && \
71+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
72+
chown -R 1000:1000 db log storage tmp
73+
USER 1000:1000
74+
75+
# Deployment options
76+
ENV RAILS_LOG_TO_STDOUT="1" \
77+
RAILS_SERVE_STATIC_FILES="true"
78+
79+
# Entrypoint sets up the container.
80+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
81+
82+
# Start the server by default, this can be overwritten at runtime
83+
EXPOSE 3000
84+
CMD ["./bin/rails", "server"]

Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source 'https://rubygems.org'
44
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

6-
ruby '3.1.1'
6+
ruby '3.3.3'
77

88
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
99
gem 'rails', '~> 7.0.2', '>= 7.0.2.2'
@@ -77,3 +77,5 @@ end
7777
gem 'tailwindcss-rails', '~> 2.0'
7878

7979
gem 'devise', '~> 4.8'
80+
81+
gem "dockerfile-rails", ">= 1.6", :group => :development

Gemfile.lock

+7-4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ GEM
9696
warden (~> 1.2.3)
9797
diff-lcs (1.5.0)
9898
digest (3.1.0)
99+
dockerfile-rails (1.6.17)
100+
rails (>= 3.0.0)
99101
erubi (1.10.0)
100102
globalid (1.0.0)
101103
activesupport (>= 5.0)
@@ -120,6 +122,7 @@ GEM
120122
matrix (0.4.2)
121123
method_source (1.0.0)
122124
mini_mime (1.1.2)
125+
mini_portile2 (2.8.7)
123126
minitest (5.15.0)
124127
msgpack (1.4.5)
125128
net-imap (0.2.3)
@@ -138,9 +141,8 @@ GEM
138141
net-protocol
139142
timeout
140143
nio4r (2.5.8)
141-
nokogiri (1.13.3-arm64-darwin)
142-
racc (~> 1.4)
143-
nokogiri (1.13.3-x86_64-linux)
144+
nokogiri (1.13.3)
145+
mini_portile2 (~> 2.8.0)
144146
racc (~> 1.4)
145147
orm_adapter (0.5.0)
146148
pg (1.3.4)
@@ -255,6 +257,7 @@ DEPENDENCIES
255257
capybara
256258
debug
257259
devise (~> 4.8)
260+
dockerfile-rails (>= 1.6)
258261
importmap-rails
259262
jbuilder
260263
pg (~> 1.1)
@@ -271,7 +274,7 @@ DEPENDENCIES
271274
webdrivers
272275

273276
RUBY VERSION
274-
ruby 3.1.1p18
277+
ruby 3.3.3p89
275278

276279
BUNDLED WITH
277280
2.3.8

bin/docker-entrypoint

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash -e
2+
3+
# Add any container initialization steps here
4+
5+
exec "${@}"

config/credentials.yml.enc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
LPzzigNE+zbnmkfPZxeVP7HM17kggKDAZVev0RyXzXtddszSPIMgpqSUHmzhZmujq5yrPtphBoWeUH5qzsuLnK46Bck0i/C4R+TPvSKXOf4xC5wq0rutk0ftAQCrjOtpqNbTr9TX1oLJS4mszHA/9burfNxbJq0KD+Wu3rE5t9iA+T8ySRwAYvAgyhLytnqkqnYVSd2H5EqNiWURcIbA340+hl1d5kJgt0CTUwmuVAzadSKVWoMtX3+6xo+mJgBIHAF7VgP/EuOH3CtTDf6/fwUnbAOQGmvxk3m+JCEMQ4wgy0JzgItcssOPeeapJd6NHKf7pbu9Xu1IPgla5jZeiy/6hnNYLulWC3ijWr2aQq7wKHJ0C5grHp6vPouc3gVV+9RfYw7qE9sMUXP/aOOt7ZTZAqswFKK46E3n--xIJiVNuEqyeziE5o--LD0AzAgRk0E8YoQ7JZHuoA==
1+
I5tgLqyQK8SGPyrAlC/ZIcFV6riBc6tGuAdDUAJVt0C7+NXekOSJS1uD3XZBFtKF3GyUurgO9ere42Q2Rp4wr0KQsNSoRaIwqXXvmQZAN5IkDYLD9lqiXt09dnbF5yUhd3CNIavQ55QK97Ezyly7xtL8L52IfpTdTEVg9E7z6t+rDoZkFL/ftbLnW+q7WCzc1c899lDT5SxCiB38lB57VOlO3S+805ONb4Q/QyZVSm2Fyq3KkJErtyAVrbEMnoyM8ddbD/mnlvyeLLi9vK+AWiH3KXRvCNaCvY2jYiKw9S7YNwGRqywjQAe2ZaVeAjAxX0NVMVb97Y3p7BcHE2nZ7kg2HnOhUMyfimpICCho375VXs5VCsvGlMmjnTnzz8YAfqI2kZtN1wufx6q0/KN+8ithd+srzQjfiIAf--fGvimv/mtjq1887j--PITshC1Zhp0B527dFHVvCg==

config/dockerfile.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# generated by dockerfile-rails
2+
3+
---
4+
options:
5+
label:
6+
fly_launch_runtime: rails
7+
postgresql: true
8+
prepare: false

fly.toml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# fly.toml app configuration file generated for recipes-on-rails on 2024-08-05T21:37:02+02:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'recipes-on-rails'
7+
primary_region = 'mad'
8+
console_command = '/rails/bin/rails console'
9+
10+
[build]
11+
12+
[deploy]
13+
release_command = './bin/rails db:prepare'
14+
15+
[http_service]
16+
internal_port = 3000
17+
force_https = true
18+
auto_stop_machines = 'stop'
19+
auto_start_machines = true
20+
min_machines_running = 0
21+
processes = ['app']
22+
23+
[[vm]]
24+
memory = '1gb'
25+
cpu_kind = 'shared'
26+
cpus = 1
27+
28+
[[statics]]
29+
guest_path = '/rails/public'
30+
url_prefix = '/'

0 commit comments

Comments
 (0)