8000 Add a repeatable origin/main production deploy by leminh0796 · Pull Request #1 · leminh0796/fizzy · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@
# Ignore master key for decrypting credentials and more.
/config/master.key

# Production deploy secrets and local release notes. Never commit these.
/.kamal/production.env
/.kamal/release-history
/.kamal/cutover-started
/.kamal/deploy.lock

/config/credentials/*.key
.DS_Store
46 changes: 46 additions & 0 deletions .kamal/hooks/pre-app-boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Runs locally while `kamal app boot` holds the deploy lock, before the new
# container is created. The published port 127.0.0.1:3006 cannot be shared, so
# the current web container is stopped here. Volumes are not removed.

set -euo pipefail
set +o xtrace
unset RAILS_MASTER_KEY SECRET_KEY_BASE VAPID_PUBLIC_KEY VAPID_PRIVATE_KEY \
AWS_SES_SMTP_USERNAME AWS_SES_SMTP_PASSWORD SMTP_USERNAME SMTP_PASSWORD \
KAMAL_REGISTRY_PASSWORD

host=${FIZZY_DEPLOY_HOST:-}
user=${FIZZY_DEPLOY_USER:-}
service=${FIZZY_SERVICE:-fizzy}
mark=${FIZZY_CUTOVER_MARK:-}

if ! printf '%s' "$host" | grep -Eq '^[0-9A-Za-z.-]+$'; then
printf 'pre-app-boot: missing or unsafe FIZZY_DEPLOY_HOST\n' >&2
exit 1
fi
if ! printf '%s' "$user" | grep -Eq '^[A-Za-z0-9._-]+$'; then
printf 'pre-app-boot: missing or unsafe FIZZY_DEPLOY_USER\n' >&2
exit 1
fi
if ! printf '%s' "$service" | grep -Eq '^[A-Za-z0-9_-]+$'; then
printf 'pre-app-boot: unsafe FIZZY_SERVICE\n' >&2
exit 1
fi

ssh \
-o BatchMode=yes \
-o ConnectTimeout=15 \
-o StrictHostKeyChecking=accept-new \
"${user}@${host}" \
"bash -s" <<EOF
set -eu
ids=\$(docker ps -aq --filter label=service=${service} --filter label=role=web --filter status=running --filter status=restarting)
if [ -n "\$ids" ]; then
docker stop -t 30 \$ids
fi
EOF

if [ -n "$mark" ]; then
mkdir -p "$(dirname "$mark")"
: > "$mark"
fi
22 changes: 22 additions & 0 deletions .kamal/production.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copy to .kamal/production.env and restrict it before editing:
# cp .kamal/production.env.example .kamal/production.env
# chmod 600 .kamal/production.env
#
# bin/deploy reads that copy. It is gitignored. Do not commit real values.
# bin/deploy --import-secrets can fill a missing file from the running
# production container. An existing file is never overwritten.
#
# .kamal/secrets maps SECRET_KEY_BASE from RAILS_MASTER_KEY. Keep that mapping.
# Store the value currently injected as SECRET_KEY_BASE in RAILS_MASTER_KEY.
# Do not generate a new value here.
#
# Values are literal text after the first "=". They are not shell-expanded.
# KAMAL_REGISTRY_PASSWORD is optional: config/deploy.yml uses the local
# registry and does not reference a registry password.

RAILS_MASTER_KEY=
VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=
AWS_SES_SMTP_USERNAME=
AWS_SES_SMTP_PASSWORD=
KAMAL_REGISTRY_PASSWORD=
5 changes: 4 additions & 1 deletion .kamal/secrets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
# and accessories/*/env/secret in config/deploy.yml. All secrets should be pulled from either
# password manager, ENV, or a file. DO NOT ENTER RAW CREDENTIALS HERE! This file needs to be safe for git.

# Option 1: Read secrets from the environment
# Option 1: Read secrets from the environment.
# bin/deploy loads .kamal/production.env itself. Keep SECRET_KEY_BASE derived
# from RAILS_MASTER_KEY; that is the application secret already in production,
# not a separate Rails encryption master key.
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
RAILS_MASTER_KEY=$RAILS_MASTER_KEY
SECRET_KEY_BASE=$RAILS_MASTER_KEY
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ diff before calling it done.
Default branch: `main`

Self-hosted deploys run Kamal against `config/deploy.yml` — see `docs/kamal-deployment.md`.
This installation's repeatable production command is `bin/deploy`, documented in `docs/production-deploy.md`.

## SaaS mode

Expand Down
Loading
Loading
0