Repository navigation
feat(cli): Publish the CLI Docker image as getsentry/sentry-cli #2513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sentry-junior
wants to merge
4
commits into
main
Choose a base branch
from
feat/cli-docker-image
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6b375ad
feat(cli): Publish the CLI Docker image as getsentry/sentry-cli
sentry-junior[bot] bcb7d46
feat(cli): build the Docker image on distroless
sentry-junior[bot] a625635
ref(cli): pin the Docker base images and smoke-test git through sentry
sentry-junior[bot] b09a89c
Merge remote-tracking branch 'origin/main' into feat/cli-docker-image
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ** | ||
| !dist-bin/sentry-linux-amd64 | ||
| !dist-bin/sentry-linux-arm64 | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # The getsentry/sentry-cli image: the standalone Linux binary on distroless. | ||
| # cli-build.yml builds it from this directory after copying in | ||
| # dist-bin/sentry-linux-amd64 and dist-bin/sentry-linux-arm64 (the | ||
| # `script/build.ts` outputs, renamed from x64 to Docker's amd64). | ||
|
|
||
| # distroless has no package manager, so take the extra files from Debian 12, | ||
| # which distroless/cc-debian12 is built from. The Node runtime in the binary | ||
| # links libatomic. `release set-commits --auto`, `release propose-version`, and | ||
| # `code-mappings upload` read the mounted checkout with git, which needs | ||
| # libpcre2 and zlib. A checkout mounted from the host belongs to another user, | ||
| # so git must trust the /work mount point. | ||
| FROM debian:bookworm-slim@sha256:e67eeead736ff7bbe258ef088bff683635c561b1fcfefad0806c1df4ab49ce0e AS deps | ||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends git libatomic1 \ | ||
| && git config --system --add safe.directory /work \ | ||
| && mkdir /deps \ | ||
| && cp -L --parents /etc/gitconfig /usr/bin/git \ | ||
| /usr/lib/*-linux-gnu/libatomic.so.1 \ | ||
| /lib/*-linux-gnu/libpcre2-8.so.0 \ | ||
| /lib/*-linux-gnu/libz.so.1 \ | ||
| /deps/ | ||
|
|
||
| FROM gcr.io/distroless/cc-debian12@sha256:e5d81ddde149641e2a9ba55be4545bc125c67de07508b03ba4c22e6eb0ded5aa | ||
|
|
||
| LABEL org.opencontainers.image.source="https://github.com/getsentry/toolkit" \ | ||
| org.opencontainers.image.description="Sentry CLI" \ | ||
| org.opencontainers.image.licenses="FSL-1.1-Apache-2.0" | ||
|
|
||
| COPY --from=deps /deps/ / | ||
|
|
||
| ARG TARGETARCH | ||
| COPY --chmod=555 dist-bin/sentry-linux-$TARGETARCH /usr/local/bin/sentry | ||
|
|
||
| # A container can't upgrade its own image; pull a newer tag instead. | ||
| ENV SENTRY_CLI_NO_UPDATE_CHECK=1 | ||
|
|
||
| # Same as the v3 image: mount the project at /work. | ||
| WORKDIR /work | ||
| ENTRYPOINT ["/usr/local/bin/sentry"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * Smoke-tests the CLI Docker image that cli-build.yml pushes. On each platform | ||
| * the CLI starts, and `release propose-version` reads the commit through the | ||
| * git copied into the image from the checkout mounted at /work, the image's | ||
| * working directory. Run it from the repository root: | ||
| * | ||
| * node scripts/cli-docker-smoke-test.mjs <image> <platform>[,<platform>...] | ||
| */ | ||
| import { execFileSync } from "node:child_process"; | ||
| import { pathToFileURL } from "node:url"; | ||
|
|
||
| /** | ||
| * Throws when the image fails a check on any platform. | ||
| * | ||
| * @param {object} options | ||
| * @param {string} options.image - Image reference to run. | ||
| * @param {string[]} options.platforms - Platforms to run it on, such as | ||
| * `linux/arm64`. | ||
| * @param {string} options.checkout - Host checkout to mount at /work. | ||
| * @param {string} options.head - Commit that checkout is at. | ||
| * @param {(args: string[]) => string} options.docker - Runs `docker` with the | ||
| * arguments and returns its stdout; throws on a non-zero exit. | ||
| * @returns {Map<string, string>} The CLI version that each platform printed. | ||
| */ | ||
| export function smokeTestImage({ image, platforms, checkout, head, docker }) { | ||
| const versions = new Map(); | ||
| for (const platform of platforms) { | ||
| const run = ["run", "--rm", "--platform", platform]; | ||
| const version = docker([...run, image, "--version"]).trim(); | ||
| if (!version) { | ||
| throw new Error(`${platform}: sentry --version printed nothing`); | ||
| } | ||
| // propose-version needs a token but makes no API call. | ||
| const proposed = docker([ | ||
| ...run, | ||
| "--env", | ||
| "SENTRY_AUTH_TOKEN=smoke-test", | ||
| "--volume", | ||
| `${checkout}:/work`, | ||
| image, | ||
| "release", | ||
| "propose-version", | ||
| "--json", | ||
| ]); | ||
| const mountedHead = JSON.parse(proposed).version; | ||
| if (mountedHead !== head) { | ||
| throw new Error( | ||
| `${platform}: propose-version in /work read ${mountedHead}, expected ${head}`, | ||
| ); | ||
| } | ||
| versions.set(platform, version); | ||
| } | ||
| return versions; | ||
| } | ||
|
|
||
| if ( | ||
| process.argv[1] && | ||
| import.meta.url === pathToFileURL(process.argv[1]).href | ||
| ) { | ||
| const [image, platforms] = process.argv.slice(2); | ||
| if (!image || !platforms) { | ||
| throw new Error( | ||
| "Usage: node scripts/cli-docker-smoke-test.mjs <image> <platform>[,<platform>...]", | ||
| ); | ||
| } | ||
| const versions = smokeTestImage({ | ||
| image, | ||
| platforms: platforms.split(","), | ||
| checkout: process.cwd(), | ||
| head: execFileSync("git", ["rev-parse", "HEAD"], { | ||
| encoding: "utf8", | ||
| }).trim(), | ||
| docker: (args) => | ||
| execFileSync("docker", args, { | ||
| encoding: "utf8", | ||
| stdio: ["ignore", "pipe", "inherit"], | ||
| }), | ||
| }); | ||
| for (const [platform, version] of versions) { | ||
| console.log(`${platform}: sentry ${version}; propose-version reads /work`); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
| import { smokeTestImage } from "./cli-docker-smoke-test.mjs"; | ||
|
|
||
| const IMAGE = "ghcr.io/getsentry/toolkit/sentry-cli:abc123"; | ||
| const HEAD = "abc123"; | ||
| const PLATFORMS = ["linux/amd64", "linux/arm64"]; | ||
|
|
||
| /** A fake `docker` that records its calls and answers like a working image. */ | ||
| function fakeDocker({ version = "4.0.0", mountedHead = HEAD } = {}) { | ||
| const calls = []; | ||
| const docker = (args) => { | ||
| calls.push(args); | ||
| return args.includes("--version") | ||
| ? `${version}\n` | ||
| : JSON.stringify({ version: mountedHead, source: "git" }); | ||
| }; | ||
| return { calls, docker }; | ||
| } | ||
|
|
||
| test("runs the CLI and reads the mounted checkout on every platform", () => { | ||
| const { calls, docker } = fakeDocker(); | ||
|
|
||
| const versions = smokeTestImage({ | ||
| image: IMAGE, | ||
| platforms: PLATFORMS, | ||
| checkout: "/repo", | ||
| head: HEAD, | ||
| docker, | ||
| }); | ||
|
|
||
| assert.deepEqual([...versions.keys()], PLATFORMS); | ||
| assert.deepEqual( | ||
| calls, | ||
| PLATFORMS.flatMap((platform) => [ | ||
| ["run", "--rm", "--platform", platform, IMAGE, "--version"], | ||
| [ | ||
| "run", | ||
| "--rm", | ||
| "--platform", | ||
| platform, | ||
| "--env", | ||
| "SENTRY_AUTH_TOKEN=smoke-test", | ||
| "--volume", | ||
| "/repo:/work", | ||
| IMAGE, | ||
| "release", | ||
| "propose-version", | ||
| "--json", | ||
| ], | ||
| ]), | ||
| ); | ||
| }); | ||
|
|
||
| test("fails when propose-version in /work reads another commit", () => { | ||
| const { docker } = fakeDocker({ mountedHead: "def456" }); | ||
|
|
||
| assert.throws( | ||
| () => | ||
| smokeTestImage({ | ||
| image: IMAGE, | ||
| platforms: PLATFORMS, | ||
| checkout: "/repo", | ||
| head: HEAD, | ||
| docker, | ||
| }), | ||
| /linux\/amd64: propose-version in \/work read def456, expected abc123/, | ||
| ); | ||
| }); | ||
|
|
||
| test("fails when the CLI prints no version", () => { | ||
| const { docker } = fakeDocker({ version: "" }); | ||
|
|
||
| assert.throws( | ||
| () => | ||
| smokeTestImage({ | ||
| image: IMAGE, | ||
| platforms: PLATFORMS, | ||
| checkout: "/repo", | ||
| head: HEAD, | ||
| docker, | ||
| }), | ||
| /linux\/amd64: sentry --version printed nothing/, | ||
| ); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.