Skip to content

Commit

Permalink
Move to Fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
RISCfuture committed Jun 20, 2024
1 parent bd352b8 commit d1ae34d
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 136 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
38 changes: 38 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy

on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Runs when CI passes
workflow_run:
workflows: [CI]
branches: [master]
types: [completed]

# Allow one concurrent deployment
concurrency:
group: pages
cancel-in-progress: true

env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

jobs:
deploy:
name: Deploy to Fly.io
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up flyctl
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy to Fly.io
run: flyctl deploy --remote-only
- name: Notify Bugsnag
uses: psprings/[email protected]
with:
apiKey: ${{ secrets.BUGSNAG_API_KEY }}
appVersion: ${{ github.sha }}
releaseStage: production
37 changes: 0 additions & 37 deletions Capfile

This file was deleted.

65 changes: 65 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips

# 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

# Copy application code
COPY --link . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/


# 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 imagemagick libvips 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

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

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
9 changes: 1 addition & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ group :development do
gem "spring-watcher-listen"

# DEPLOYMENT
gem "bcrypt_pbkdf", require: false
gem "bugsnag-capistrano", require: false
gem "capistrano", require: false
gem "capistrano-bundler", require: false
gem "capistrano-nvm", require: false
gem "capistrano-rails", require: false
gem "capistrano-rvm", require: false
gem "ed25519", require: false
gem "dockerfile-rails"
end

group :test do
Expand Down
47 changes: 7 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.5.2)
sshkit (>= 1.6.1, != 1.7.0)
aws-eventstream (1.3.0)
aws-partitions (1.945.0)
aws-sdk-core (3.197.1)
Expand All @@ -109,8 +107,6 @@ GEM
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bcrypt (3.1.20)
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
bigdecimal (3.1.8)
binding_of_caller (1.0.1)
debug_inspector (>= 1.2.0)
Expand All @@ -119,23 +115,7 @@ GEM
msgpack (~> 1.2)
bugsnag (6.27.1)
concurrent-ruby (~> 1.0)
bugsnag-capistrano (2.1.0)
builder (3.3.0)
capistrano (3.18.1)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
capistrano-bundler (2.1.0)
capistrano (~> 3.1)
capistrano-nvm (0.0.7)
capistrano (~> 3.1)
capistrano-rails (1.6.3)
capistrano (~> 3.1)
capistrano-bundler (>= 1.1, < 3)
capistrano-rvm (0.1.2)
capistrano (~> 3.0)
sshkit (~> 1.2)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crack (1.0.0)
Expand All @@ -160,6 +140,8 @@ GEM
devise (~> 4.0)
warden-jwt_auth (~> 0.8)
diff-lcs (1.5.1)
dockerfile-rails (1.6.16)
rails (>= 3.0.0)
drb (2.2.1)
dry-auto_inject (1.0.1)
dry-core (~> 1.0)
Expand All @@ -170,14 +152,14 @@ GEM
dry-core (1.0.1)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
ed25519 (1.3.0)
erubi (1.13.0)
factory_bot (6.4.6)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
ffaker (2.23.0)
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
globalid (1.2.1)
Expand Down Expand Up @@ -224,14 +206,11 @@ GEM
net-protocol
net-protocol (0.2.2)
timeout
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
net-smtp (0.5.0)
net-protocol
net-ssh (7.2.3)
nio4r (2.7.3)
nokogiri (1.16.6-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.6-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
Expand Down Expand Up @@ -333,12 +312,6 @@ GEM
spring-watcher-listen (2.1.0)
listen (>= 2.7, < 4.0)
spring (>= 4)
sshkit (1.22.2)
base64
mutex_m
net-scp (>= 1.1.2)
net-sftp (>= 2.1.2)
net-ssh (>= 2.8.0)
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.1)
Expand All @@ -364,28 +337,22 @@ GEM
zeitwerk (2.6.16)

PLATFORMS
aarch64-linux
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
active_storage_validations
aws-sdk-s3
bcrypt_pbkdf
binding_of_caller
boolean
bootsnap
bugsnag
bugsnag-capistrano
capistrano
capistrano-bundler
capistrano-nvm
capistrano-rails
capistrano-rvm
database_cleaner
devise
devise-jwt
ed25519
dockerfile-rails
factory_bot_rails
ffaker
image_processing
Expand Down
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 "${@}"
45 changes: 0 additions & 45 deletions config/deploy.rb

This file was deleted.

5 changes: 0 additions & 5 deletions config/deploy/production.rb

This file was deleted.

9 changes: 9 additions & 0 deletions config/dockerfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# generated by dockerfile-rails

---
options:
label:
fly_launch_runtime: rails
postgresql: true
prepare: false
redis: true
Loading

0 comments on commit d1ae34d

Please sign in to comment.