Skip to content

Commit

Permalink
Upgrade to Rails 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Sep 30, 2024
0 parents commit ba6cc7b
Show file tree
Hide file tree
Showing 125 changed files with 9,022 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for
# more about ignoring files.

# Ignore bundler configuration.
/.bundle

# Ignore Docker-related files.
/.dockerignore
/Dockerfile*

# Ignore all environment files.
/.env*

# Ignore git directory and files.
/.git/
/.gitattributes
/.gitignore

# Ignore GitHub files.
/.github

# Ignore Ruby-related files.
/.rubocop.yml
/.ruby-lsp/

# Ignore any asset builds.
/app/assets/builds/*
!/app/assets/builds/.keep

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

# Ignore all logs and temporary files.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore any development and test files.
/node_modules
/spec
/.yarn
.erb-lint.yml
.stylelintignore
.stylelintrc.json
.yarnrc.yml
Procfile.dev
README.md
babel.config.cjs
eslint.config.cjs
package.json
yarn.lock

# Ignore any pre-compiled assets.
/public/assets

# Ignore any SQLite databases.
/storage/*
!/storage/.keep

# Ignore PID files.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage for uploaded files in development.
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep
18 changes: 18 additions & 0 deletions .erb-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
glob: "**/*.erb"
exclude:
- "**/vendor/**/*"
linters:
PartialInstanceVariable:
enabled: true
Rubocop:
enabled: true
rubocop_config:
inherit_from:
- .rubocop.yml
Layout/InitialIndentation:
Enabled: false
Layout/TrailingEmptyLines:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See https://git-scm.com/docs/gitattributes for more about git
# attribute files.

# Mark the Bundler lock file as having been generated.
Gemfile.lock linguist-generated=true

# Customize the difference command for the Rails credentials.
config/credentials/*.yml.enc diff=rails_credentials
config/credentials.yml.enc diff=rails_credentials

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: bundler
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
96 changes: 96 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: CI

on: [push, pull_request]

jobs:
Ruby:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install Node
uses: actions/setup-node@v4
with:
cache: "yarn"
- name: Install the Node dependencies
run: yarn install
- name: Run the Ruby tests
env:
COVERAGE: true
RAILS_ENV: test
run: bin/rails db:setup ruby:test

JavaScript:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
cache: "yarn"
- name: Install the Node dependencies
run: yarn install
- name: Run the JavaScript tests
run: yarn test:coverage

Linting:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install Node
uses: actions/setup-node@v4
with:
cache: "yarn"
- name: Install the Node dependencies
run: yarn install
- name: Lint the ERB
run: bundle exec erblint .
- name: Lint the Ruby
run: bin/rubocop --format github --parallel
- name: Lint the JavaScript
run: yarn lint
- name: Lint the CSS
run: yarn lint:css

Docker:
runs-on: ubuntu-latest

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- name: Build the image
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
push: false

Vulnerabilities:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Scan for vulnerabilities
run: bin/brakeman --format github --no-pager
- name: Scan for vulnerabilities in JavaScript dependencies
run: bin/importmap audit
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Ignore all environment files.
/.env*

# Ignore Yarn files.
/.yarn

# Ignore any asset builds.
/app/assets/builds/*
!/app/assets/builds/.keep

# Ignore master key for decrypting credentials and more.
/config/master.key

# Ignore all logs and temporary files.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore any development dependencies.
/node_modules

# Ignore any pre-compiled assets.
/public/assets

# Ignore any SQLite databases.
/storage/*
!/storage/.keep

# Ignore PID files.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage for uploaded files in development.
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep
13 changes: 13 additions & 0 deletions .kamal/hooks/docker-setup.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby

# A sample docker-setup hook
#
# Sets up a Docker network on defined hosts which can then be used by the application’s containers

hosts = ENV["KAMAL_HOSTS"].split(",")

hosts.each do |ip|
destination = "root@#{ip}"
puts "Creating a Docker network \"kamal\" on #{destination}"
`ssh #{destination} docker network create kamal`
end
14 changes: 14 additions & 0 deletions .kamal/hooks/post-deploy.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# A sample post-deploy hook
#
# These environment variables are available:
# KAMAL_RECORDED_AT
# KAMAL_PERFORMER
# KAMAL_VERSION
# KAMAL_HOSTS
# KAMAL_ROLE (if set)
# KAMAL_DESTINATION (if set)
# KAMAL_RUNTIME

echo "$KAMAL_PERFORMER deployed $KAMAL_VERSION to $KAMAL_DESTINATION in $KAMAL_RUNTIME seconds"
3 changes: 3 additions & 0 deletions .kamal/hooks/post-proxy-reboot.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "Rebooted kamal-proxy on $KAMAL_HOSTS"
51 changes: 51 additions & 0 deletions .kamal/hooks/pre-build.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

# A sample pre-build hook
#
# Checks:
# 1. We have a clean checkout
# 2. A remote is configured
# 3. The branch has been pushed to the remote
# 4. The version we are deploying matches the remote
#
# These environment variables are available:
# KAMAL_RECORDED_AT
# KAMAL_PERFORMER
# KAMAL_VERSION
# KAMAL_HOSTS
# KAMAL_ROLE (if set)
# KAMAL_DESTINATION (if set)

if [ -n "$(git status --porcelain)" ]; then
echo "Git checkout is not clean, aborting..." >&2
git status --porcelain >&2
exit 1
fi

first_remote=$(git remote)

if [ -z "$first_remote" ]; then
echo "No git remote set, aborting..." >&2
exit 1
fi

current_branch=$(git branch --show-current)

if [ -z "$current_branch" ]; then
echo "Not on a git branch, aborting..." >&2
exit 1
fi

remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1)

if [ -z "$remote_head" ]; then
echo "Branch not pushed to remote, aborting..." >&2
exit 1
fi

if [ "$KAMAL_VERSION" != "$remote_head" ]; then
echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2
exit 1
fi

exit 0
47 changes: 47 additions & 0 deletions .kamal/hooks/pre-connect.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env ruby

# A sample pre-connect check
#
# Warms DNS before connecting to hosts in parallel
#
# These environment variables are available:
# KAMAL_RECORDED_AT
# KAMAL_PERFORMER
# KAMAL_VERSION
# KAMAL_HOSTS
# KAMAL_ROLE (if set)
# KAMAL_DESTINATION (if set)
# KAMAL_RUNTIME

hosts = ENV["KAMAL_HOSTS"].split(",")
results = nil
max = 3

elapsed = Benchmark.realtime do
results = hosts.map do |host|
Thread.new do
tries = 1

begin
Socket.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)
rescue SocketError
if tries < max
puts "Retrying DNS warmup: #{host}"
tries += 1
sleep rand
retry
else
puts "DNS warmup failed: #{host}"
host
end
end

tries
end
end.map(&:value)
end

retries = results.sum - hosts.size
nopes = results.count { |r| r == max }

puts "Prewarmed %d DNS lookups in %.2f sec: %d retries, %d failures" % [ hosts.size, elapsed, retries, nopes ]
Loading

0 comments on commit ba6cc7b

Please sign in to comment.