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 910d527 commit 30e7b61
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 160 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
bundler-cache: true
- name: Run Rubocop
run: |
gem install rubocop-rails rubocop-rspec rubocop-performance rubocop-md rubocop-rake rubocop-graphql rubocop-rspec_rails rubocop-sidekiq rubocop-yard
gem install rubocop-rails rubocop-rspec rubocop-performance rubocop-md rubocop-rake rubocop-graphql rubocop-rspec_rails rubocop-sidekiq rubocop-yard rubocop-factory_bot
git clone https://gist.github.com/65e21b9e8b0d1db285dcb4fc627b98fa.git .rubocop
cp .rubocop/.rubocop.yml .rubocop-ruby.yml
git clone https://gist.github.com/14cfa24d53c12bf385871e9b93b95c37.git .rubocop-rspec
Expand Down
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: [main]
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
40 changes: 0 additions & 40 deletions Capfile

This file was deleted.

61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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 libpq-dev libyaml-dev git

# Install application gems
COPY --link Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git

# Copy application code
COPY --link . .


# 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

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

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

ruby "3.3.3"
gem "net-pop", github: "ruby/net-pop" # 3.3.3 hack fix

# CORE
gem "puma"
Expand All @@ -30,17 +31,8 @@ group :development do
# ERRORS
gem "binding_of_caller"

# DEPLOYMENT
gem "bcrypt_pbkdf", require: false
gem "bugsnag-capistrano", require: false
gem "capistrano", require: false
gem "capistrano-bundler", require: false
gem "capistrano-git-with-submodules", require: false
gem "capistrano-nvm", require: false
gem "capistrano-rails", require: false
gem "capistrano-rvm", require: false
gem "capistrano-sidekiq", require: false
gem "ed25519", require: false
# FLY.IO
gem "dockerfile-rails"
end

group :doc do
Expand Down
63 changes: 14 additions & 49 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/ruby/net-pop.git
revision: e8d0afe2773b9eb6a23c39e9e437f6fc0fc7c733
specs:
net-pop (0.1.2)
net-protocol

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -77,40 +84,14 @@ 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)
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)
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-git-with-submodules (2.0.6)
capistrano (~> 3.7)
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)
capistrano-sidekiq (2.3.1)
capistrano (>= 3.9.0)
capistrano-bundler
sidekiq (>= 6.0)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crack (1.0.0)
Expand All @@ -135,6 +116,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 @@ -145,7 +128,6 @@ 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)
Expand Down Expand Up @@ -183,17 +165,13 @@ GEM
net-imap (0.4.13)
date
net-protocol
net-pop (0.1.2)
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 @@ -286,12 +264,6 @@ GEM
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.19.0)
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 @@ -317,30 +289,23 @@ GEM
zeitwerk (2.6.16)

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

DEPENDENCIES
bcrypt_pbkdf
binding_of_caller
bugsnag
bugsnag-capistrano
capistrano
capistrano-bundler
capistrano-git-with-submodules
capistrano-nvm
capistrano-rails
capistrano-rvm
capistrano-sidekiq
database_cleaner
devise
devise-jwt
ed25519
dockerfile-rails
factory_bot_rails
ffaker
jbuilder
json_expressions
net-pop!
pg
puma
rack-cors
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ End-to-end testing is documented in the readme for the front-end.

#### Deployment

The back-end is deployed using Capistrano. The front-end is a static site that
is compiled and deployed using a simple shell script with `rsync`.
The back-end and front-end are both deployed using Fly.io. A GitHub Action,
defined in the `deploy.yml` workflow, runs after CI is complete.

## Architecture

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 "${@}"
Loading

0 comments on commit 30e7b61

Please sign in to comment.