-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
308 changed files
with
5,179 additions
and
2,535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
:position: before | ||
:position_in_additional_file_patterns: before | ||
:position_in_class: before | ||
:position_in_factory: before | ||
:position_in_fixture: before | ||
:position_in_routes: before | ||
:position_in_serializer: before | ||
:position_in_test: before | ||
:classified_sort: true | ||
:exclude_controllers: true | ||
:exclude_factories: true | ||
:exclude_fixtures: true | ||
:exclude_helpers: true | ||
:exclude_scaffolds: true | ||
:exclude_serializers: false | ||
:exclude_sti_subclasses: false | ||
:exclude_tests: true | ||
:force: false | ||
:format_markdown: false | ||
:format_rdoc: false | ||
:format_yard: false | ||
:frozen: false | ||
:ignore_model_sub_dir: false | ||
:ignore_unknown_models: false | ||
:include_version: false | ||
:show_check_constraints: false | ||
:show_complete_foreign_keys: false | ||
:show_foreign_keys: true | ||
:show_indexes: true | ||
:simple_indexes: false | ||
:sort: false | ||
:timestamp: false | ||
:trace: false | ||
:with_comment: true | ||
:with_column_comments: true | ||
:with_table_comments: true | ||
:active_admin: false | ||
:command: | ||
:debug: false | ||
:hide_default_column_types: '' | ||
:hide_limit_column_types: '' | ||
:ignore_columns: | ||
:ignore_routes: | ||
:models: true | ||
:routes: false | ||
:skip_on_db_migrate: false | ||
:target_action: :do_annotations | ||
:wrapper: | ||
:wrapper_close: | ||
:wrapper_open: | ||
:classes_default_to_s: [] | ||
:additional_file_patterns: [] | ||
:model_dir: | ||
- app/models | ||
:require: [] | ||
:root_dir: | ||
- '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Kamal Deployment | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 21 * * 2" # runs Tuesdays at 21:00 UTC | ||
|
||
jobs: | ||
check_latest_commit: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
commit_sha: ${{ env.SHA }} | ||
|
||
steps: | ||
- name: Checkout the latest commit on main | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: main | ||
|
||
- name: Get the latest commit SHA | ||
run: echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV | ||
|
||
- name: Confirm all checks passed | ||
run: | | ||
# Returns json data on all checks that were run | ||
response=$(curl -L \ | ||
-H "Accept: application/vnd.github+json" \ | ||
"https://api.github.com/repos/${{ github.repository }}/commits/${{ env.SHA }}/check-runs") | ||
# Check the conclusion of eash check for pass/fail | ||
for conclusion in $(echo "$response" | jq -r '.check_runs[] | select(.name != "deploy" and .name != "check_latest_commit") | .conclusion'); do | ||
if [ "$conclusion" != "success" ]; then | ||
echo "Commit "${{ env.SHA }}" has failed checks." | ||
exit 1 | ||
fi | ||
done | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: check_latest_commit | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: main | ||
|
||
- name: Install Ruby and gems | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
|
||
- name: Install Kamal | ||
run: gem install kamal | ||
|
||
- name: Set up SSH | ||
env: | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/homewardtails.pem | ||
echo "$RAILS_MASTER_KEY" > config/credentials/production.key | ||
chmod 600 ~/.ssh/homewardtails.pem | ||
ssh-keyscan homewardtails.org >> ~/.ssh/known_hosts || echo "failed" | ||
- name: Check if latest commit is running in production | ||
run: | | ||
RUNNING_APP_SHA=$(kamal app version | grep . | tail -n 1) | ||
# Compare the current running SHA to the latest commit SHA | ||
if [ "$RUNNING_APP_SHA" == "${{ needs.check_latest_commit.outputs.commit_sha }}" ]; then | ||
echo "Running version is up to date, skipping deployment." | ||
exit 0 | ||
fi | ||
- name: Kamal Deploy | ||
run: kamal deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,8 @@ | |
|
||
# OS | ||
.DS_Store | ||
|
||
/config/credentials/production.key | ||
|
||
# LazyVim config file | ||
.lazy.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
echo "Docker set up on $KAMAL_HOSTS..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
echo "Rebooted kamal-proxy on $KAMAL_HOSTS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] |
Oops, something went wrong.