Deploy automatically when changes land in main #18
Loading…
Reference in a new issue
No description provided.
Delete branch "armin-bot/impress:claude/deploy-on-merge"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Deploys
mainautomatically: when a change lands and its specs pass, CI runs the existingdeploy/deploy.ymlplaybook as a newdeploy-botuser. Deploys now run database migrations too, with an escape hatch for migrations that need a person.How it works
CI (
.forgejo/workflows/test.yml→ci.yml): a newdeployjob,needs: rspec, runs only on pushes tomain.DEPLOY_SSH_KEY, and only the "Set up SSH" step sees it.mainqueue instead of cancelling. That's theconcurrencyblock. Without it, Forgejo cancels older runs on every push (ConfigureActionRunConcurrencyinservices/actions/workflows.go), which could kill a deploy mid-migration. PR runs still cancel stale ones.main, and skips itself if not. So a queued older run, or a re-run from the Actions page, can't roll production back.deploy/files/known_hosts, which is committed, so reviewers see any change.Migrations (
deploy/deploy.yml) run afterbundle installand before thecurrentsymlink switches. If one fails, the deploy stops and the old version keeps serving.# deploy: run manually.bin/rails deploy:check_migrations, backed bylib/manual_migrations.rb. It uses the same Active Record helpers asdb:migrate:status, and the spec covers both databases, so a Rails upgrade that changes those helpers fails loudly.bin/deploy -e skip_migrations=yesskips migrations for a manual deploy.bin/deployandbin/deploy:pushnow pass extra arguments through to Ansible.Server (
deploy/setup.yml): adeploy-botuser inimpress-deployers, so it has the same permissions as a person deploying. Its key only works fromcode.openneo.net(from=in authorized_keys; job containers have no IPv6, so they always connect over IPv4), and port, agent and X11 forwarding are off.Fixes to the existing playbook:
synchronizedefaulted toverify_host: false, which skips host key checking on the rsync connection. It now verifies.vendor/bundle, where CI keeps its gems. Without that, about 110MB of compiled gems would ship with every deploy.Docs:
docs/database-migrations.md. The rules (compatible with the running code and Impress 2020, fast, safe to re-run, quick to give up on locks), plus the escape hatch.docs/deployment-setup.md, which covers automatic deploys, howdeploy-botworks, and rotating its key.Setup checklist (before merging)
ssh-keygen -t ed25519 -N '' -C deploy-bot@code.openneo.net -f deploy-bot. Commitdeploy-bot.pubasdeploy/files/deploy-bot-ssh-key.pub; Armin can do this if you send it over.DEPLOY_SSH_KEY, then delete both key files locally.deploy/files/known_hostswithssh-keyscan -t ed25519 impress.openneo.net, after checking the fingerprint.bin/deploy:setupto createdeploy-bot.bin/rails db:migrate:statusasimpress). The first automatic deploy will run them.20261108120000_add_user_lookup_indexesmay be one of them; it's written to be safe online (algorithm: :inplace, a 10-second lock wait).Testing
Specs: 416 examples, 0 failures, including the new
spec/lib/manual_migrations_spec.rb.Asset build: precompile succeeds in a clean checkout with only the placeholder env.
Playbooks:
--syntax-checkpasses fordeploy.ymlandsetup.yml, on current Ansible and on Ansible 7 / core 2.14, which is what CI's Debian bookworm installs.Migration gating: probed on Ansible 2.14, with all four outcomes correct:
skip_migrationsRake task: exercised end to end against real migration files.
rsync rules: checked that they ship
public/assets(with the sprockets manifest), but notvendor/bundle,node_modulesor.bundle.Forgejo behavior: confirmed in source that it evaluates expressions in
concurrency, and thatsynchronize+ become becomessudo -u impress rsync, which the existing sudoers rule allows.Fresh-eyes review:
🤖 Generated with Claude Code
https://claude.ai/code/session_014PWWczf6WkuBDdUASWtRcZ
b5bfd248294055084d20