fix(docker): assimilate APE binary for scratch image, expand test cov…#11
Merged
SteveParson merged 1 commit intomainfrom Feb 21, 2026
Merged
fix(docker): assimilate APE binary for scratch image, expand test cov…#11SteveParson merged 1 commit intomainfrom
SteveParson merged 1 commit intomainfrom
Conversation
…erage - Call cosmocc's native `assimilate` tool after `make` so the APE polyglot is converted to a native ELF before being copied into the `FROM scratch` image (fixes exec format error at runtime) - Add `.env.sample` with all supported environment variables - Gitignore `.env` to prevent accidental token commits - Add Docker usage section to README including `--env-file` example - Expand test_king.c: JSON escape sequences (\/, \b, \f), whitespace around colons, negative nested integers, url_encode special chars (#, ?, =, &, /, +), and http_status_code edge cases (84 tests total) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Problem
The Docker image used
FROM scratchas its final stage, but the binary produced by cosmocc is an APE (Actually Portable Executable) — a polyglot format that relies on/bin/shto bootstrap itself on Linux. With no shell in a scratch container, the kernel cannot exec the binary and the container exits immediately withexec format error.Solution
After
make, invoke cosmocc's bundledassimilatetool (.cosmocc/current/bin/assimilate) to rewrite the APE binary in-place as a native Linux ELF. The resulting static binary runs directly in a scratch container with no dependencies. Thecurrentsymlink (created by the download script) is used rather than a glob to avoid the shell expanding it to multiple paths and passing unintended arguments toassimilate.Testing
Built the image locally with
docker build -t king:local .and confirmed the container starts and producesDISCORD_TOKEN is requiredrather thanexec format error. Additionally, extracted the binary from the image and verified the magic bytes changed fromMZ(APE polyglot) to\x7fELF(native ELF). Unit test coverage was also expanded from 72 to 84 passing cases, covering previously untested JSON escape sequences (\/,\b,\f), whitespace around colons injson_find_key, negative integers injson_get_int_in_object, additionalurl_encodecharacters (#,?,=,&,/,+), andhttp_status_codeedge cases.