fix(docker): serialize build stages + bump SSH timeout#46
Merged
alejandro-runner merged 2 commits intosynvya-stagingfrom Apr 29, 2026
Merged
fix(docker): serialize build stages + bump SSH timeout#46alejandro-runner merged 2 commits intosynvya-stagingfrom
alejandro-runner merged 2 commits intosynvya-stagingfrom
Conversation
The cold build on a t3.medium production host locked the box hard enough that SSH and SSM both became unresponsive. Root cause: BuildKit runs independent stages in parallel by default, so cargo release build (-j 2, ~3 GB RSS) and bun/vite build (NODE_OPTIONS 2 GB) ran simultaneously on a 4 GB instance. Even with 4 GB swap the system thrashed into a kernel lockup. Two changes: 1. Add a no-op `COPY --from=rust-builder /artifacts/keycast /tmp/.rust-builder-done` as the first instruction of web-builder. BuildKit sees the cross-stage dependency and only starts web-builder once rust-builder finishes, so cargo and bun never run concurrently. 2. Bump appleboy/ssh-action `command_timeout` from 30m to 60m across all four deploy/QA steps. A cold cargo + bun build on t3.medium with -j 2 takes ~45-55 min; the previous 30m killed the SSH session mid-build. Once cache mounts are populated by a successful cold build, warm builds return to a few minutes and stay well under the new timeout. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
When ec2-prepare-host.sh is invoked under sudo (e.g. while debugging on the host), $HOME resolves to /root and the cargo [build] jobs=2 config lands in /root/.cargo/config.toml. The deploy/QA workflow runs the script over SSH as ec2-user, so it never reads that config — defeating the limit. Detect SUDO_USER and write to that user's home instead, then chown the .cargo/ tree back to them so cargo can read/write it when running under their UID. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
5 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The cold build on production t3.medium locked the host hard enough that SSH and SSM both became unresponsive. Required a reboot to recover.
Root cause: BuildKit runs independent stages in parallel by default. The Dockerfile has `rust-builder` and `web-builder` as independent stages, so the cold build was running:
That blew past available memory + swap and the kernel locked.
Fix
Serialize the build stages. Add a no-op `COPY --from=rust-builder /artifacts/keycast /tmp/.rust-builder-done` as the first instruction of `web-builder`. BuildKit honors the cross-stage dependency and won't start web-builder until rust-builder finishes. Now the two heavy compilers run sequentially, never together.
Bump `command_timeout` from 30m to 60m on all four `appleboy/ssh-action` steps. A cold cargo + bun build on t3.medium with `-j 2` realistically takes 45-55 min. The previous 30m would kill the SSH session mid-build even on a healthy host.
After this lands
Test plan
Follow-up worth doing
This whole class of problem goes away if we stop building on the production host. Build the image on the GitHub-hosted runner (16 GB RAM) and push to a registry; production just `docker compose pull && up -d`. Standard prod deploy pattern. Worth scheduling as the real fix.