Skip to content

Commit

Permalink
Merge pull request #1 from lu-jim/update-24
Browse files Browse the repository at this point in the history
Update deployment
  • Loading branch information
lu-jim authored Aug 6, 2024
2 parents d7710f2 + 5accdd7 commit 784f601
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 7 deletions.
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.

# Ignore git directory.
/.git/

# Ignore bundler config.
/.bundle

# Ignore all environment files (except templates).
/.env*
!/.env*.erb

# Ignore all default key files.
/config/master.key
/config/credentials/*.key

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/.keep

# Ignore assets.
/node_modules/
/app/assets/builds/*
!/app/assets/builds/.keep
/public/assets
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.16.0
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1
3.3.3
84 changes: 84 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.3
FROM ruby:$RUBY_VERSION-slim as base

LABEL fly_launch_runtime="rails"

# 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 and node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential curl libpq-dev node-gyp pkg-config python-is-python3

# Install Node.js
ARG NODE_VERSION=20.16.0
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
rm -rf /tmp/node-build-master

# 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

# Install node modules
COPY --link package.json package-lock.json ./
RUN npm install

# 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 ./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 "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R 1000:1000 db log storage tmp
USER 1000:1000

# Deployment options
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true"

# Entrypoint sets up the container.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.1'
ruby '3.3.3'

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

gem 'devise', '~> 4.8'

gem "dockerfile-rails", ">= 1.6", :group => :development
11 changes: 7 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.5.0)
digest (3.1.0)
dockerfile-rails (1.6.17)
rails (>= 3.0.0)
erubi (1.10.0)
globalid (1.0.0)
activesupport (>= 5.0)
Expand All @@ -120,6 +122,7 @@ GEM
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.8.7)
minitest (5.15.0)
msgpack (1.4.5)
net-imap (0.2.3)
Expand All @@ -138,9 +141,8 @@ GEM
net-protocol
timeout
nio4r (2.5.8)
nokogiri (1.13.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.3-x86_64-linux)
nokogiri (1.13.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
orm_adapter (0.5.0)
pg (1.3.4)
Expand Down Expand Up @@ -255,6 +257,7 @@ DEPENDENCIES
capybara
debug
devise (~> 4.8)
dockerfile-rails (>= 1.6)
importmap-rails
jbuilder
pg (~> 1.1)
Expand All @@ -271,7 +274,7 @@ DEPENDENCIES
webdrivers

RUBY VERSION
ruby 3.1.1p18
ruby 3.3.3p89

BUNDLED WITH
2.3.8
5 changes: 5 additions & 0 deletions bin/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e

# Add any container initialization steps here

exec "${@}"
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LPzzigNE+zbnmkfPZxeVP7HM17kggKDAZVev0RyXzXtddszSPIMgpqSUHmzhZmujq5yrPtphBoWeUH5qzsuLnK46Bck0i/C4R+TPvSKXOf4xC5wq0rutk0ftAQCrjOtpqNbTr9TX1oLJS4mszHA/9burfNxbJq0KD+Wu3rE5t9iA+T8ySRwAYvAgyhLytnqkqnYVSd2H5EqNiWURcIbA340+hl1d5kJgt0CTUwmuVAzadSKVWoMtX3+6xo+mJgBIHAF7VgP/EuOH3CtTDf6/fwUnbAOQGmvxk3m+JCEMQ4wgy0JzgItcssOPeeapJd6NHKf7pbu9Xu1IPgla5jZeiy/6hnNYLulWC3ijWr2aQq7wKHJ0C5grHp6vPouc3gVV+9RfYw7qE9sMUXP/aOOt7ZTZAqswFKK46E3n--xIJiVNuEqyeziE5o--LD0AzAgRk0E8YoQ7JZHuoA==
I5tgLqyQK8SGPyrAlC/ZIcFV6riBc6tGuAdDUAJVt0C7+NXekOSJS1uD3XZBFtKF3GyUurgO9ere42Q2Rp4wr0KQsNSoRaIwqXXvmQZAN5IkDYLD9lqiXt09dnbF5yUhd3CNIavQ55QK97Ezyly7xtL8L52IfpTdTEVg9E7z6t+rDoZkFL/ftbLnW+q7WCzc1c899lDT5SxCiB38lB57VOlO3S+805ONb4Q/QyZVSm2Fyq3KkJErtyAVrbEMnoyM8ddbD/mnlvyeLLi9vK+AWiH3KXRvCNaCvY2jYiKw9S7YNwGRqywjQAe2ZaVeAjAxX0NVMVb97Y3p7BcHE2nZ7kg2HnOhUMyfimpICCho375VXs5VCsvGlMmjnTnzz8YAfqI2kZtN1wufx6q0/KN+8ithd+srzQjfiIAf--fGvimv/mtjq1887j--PITshC1Zhp0B527dFHVvCg==
8 changes: 8 additions & 0 deletions config/dockerfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# generated by dockerfile-rails

---
options:
label:
fly_launch_runtime: rails
postgresql: true
prepare: false
30 changes: 30 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# fly.toml app configuration file generated for recipes-on-rails on 2024-08-05T21:37:02+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'recipes-on-rails'
primary_region = 'mad'
console_command = '/rails/bin/rails console'

[build]

[deploy]
release_command = './bin/rails db:prepare'

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

[[statics]]
guest_path = '/rails/public'
url_prefix = '/'

0 comments on commit 784f601

Please sign in to comment.