-
Notifications
You must be signed in to change notification settings - Fork 31
ci: publish switchyard-server container from main #131
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ benchmark/datasets | |
| benchmark/tb_runs | ||
| dist | ||
| site | ||
| target | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||
| name: Publish switchyard-server container | ||||||||||
|
|
||||||||||
| on: | ||||||||||
| push: | ||||||||||
| branches: [main] | ||||||||||
| schedule: | ||||||||||
| - cron: "17 * * * *" | ||||||||||
|
|
||||||||||
| permissions: | ||||||||||
| contents: read | ||||||||||
| packages: write | ||||||||||
|
|
||||||||||
| concurrency: | ||||||||||
| group: ${{ github.workflow }}-${{ github.event_name }} | ||||||||||
| cancel-in-progress: ${{ github.event_name == 'push' }} | ||||||||||
|
|
||||||||||
| env: | ||||||||||
| PACKAGE_NAME: switchyard-server | ||||||||||
|
|
||||||||||
| jobs: | ||||||||||
| publish: | ||||||||||
| name: Publish container | ||||||||||
| if: github.event_name == 'push' | ||||||||||
| runs-on: ubuntu-latest | ||||||||||
| steps: | ||||||||||
| - uses: actions/checkout@v4 | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Do not retain the registry-capable token in Git config.
Proposed fix- - uses: actions/checkout@v4
+ - uses: actions/checkout@v4
+ with:
+ persist-credentials: false📝 Committable suggestion
Suggested change
🧰 Tools🪛 zizmor (1.26.1)[warning] 26-26: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) 🤖 Prompt for AI AgentsSource: Linters/SAST tools 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Show the workflow with line numbers, focusing on the cited region.
sed -n '1,140p' .github/workflows/server-container.yml | cat -n
# Also list all `uses:` references in the file for a quick inventory.
grep -nE '^\s*-\s*uses:|^\s*uses:' .github/workflows/server-container.yml || trueRepository: NVIDIA-NeMo/Switchyard Length of output: 3903 🏁 Script executed: #!/bin/bash
set -euo pipefail
nl -ba .github/workflows/server-container.yml | sed -n '1,140p' | grep -nE 'uses:|name:|on:|jobs:|runs-on:'Repository: NVIDIA-NeMo/Switchyard Length of output: 196 Pin these GitHub Actions to commit SHAs. 🧰 Tools🪛 zizmor (1.26.1)[warning] 26-26: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) 🤖 Prompt for AI Agents |
||||||||||
| - name: Set image coordinates | ||||||||||
| id: image | ||||||||||
| shell: bash | ||||||||||
| run: | | ||||||||||
| echo "name=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${PACKAGE_NAME}" >> "$GITHUB_OUTPUT" | ||||||||||
| echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" | ||||||||||
| - uses: docker/setup-buildx-action@v3 | ||||||||||
| - uses: docker/login-action@v3 | ||||||||||
| with: | ||||||||||
| registry: ghcr.io | ||||||||||
| username: ${{ github.actor }} | ||||||||||
| password: ${{ secrets.GITHUB_TOKEN }} | ||||||||||
| - name: Publish commit image | ||||||||||
| uses: docker/build-push-action@v6 | ||||||||||
| with: | ||||||||||
| context: . | ||||||||||
| file: crates/switchyard-server/Dockerfile | ||||||||||
| push: true | ||||||||||
| tags: ${{ steps.image.outputs.name }}:${{ steps.image.outputs.short_sha }} | ||||||||||
| build-args: | | ||||||||||
| IMAGE_VERSION=${{ steps.image.outputs.short_sha }} | ||||||||||
| VCS_REF=${{ github.sha }} | ||||||||||
| cache-from: type=gha,scope=switchyard-server | ||||||||||
| cache-to: type=gha,mode=max,scope=switchyard-server | ||||||||||
| - name: Publish main image | ||||||||||
| uses: docker/build-push-action@v6 | ||||||||||
| with: | ||||||||||
| context: . | ||||||||||
| file: crates/switchyard-server/Dockerfile | ||||||||||
| push: true | ||||||||||
| tags: ${{ steps.image.outputs.name }}:main | ||||||||||
| build-args: | | ||||||||||
| IMAGE_VERSION=main | ||||||||||
| VCS_REF=${{ github.sha }} | ||||||||||
| cache-from: type=gha,scope=switchyard-server | ||||||||||
|
|
||||||||||
| cleanup: | ||||||||||
| name: Delete expired commit images | ||||||||||
| if: github.event_name == 'schedule' | ||||||||||
| runs-on: ubuntu-latest | ||||||||||
| env: | ||||||||||
| GH_TOKEN: ${{ github.token }} | ||||||||||
| steps: | ||||||||||
| - name: Delete commit images older than 23 hours | ||||||||||
| shell: bash | ||||||||||
| run: | | ||||||||||
| set -euo pipefail | ||||||||||
| package_path="/orgs/${GITHUB_REPOSITORY_OWNER}/packages/container/${PACKAGE_NAME}/versions" | ||||||||||
| versions_file="${RUNNER_TEMP}/switchyard-server-versions.tsv" | ||||||||||
| cutoff="$(date -u -d '23 hours ago' +%s)" | ||||||||||
|
|
||||||||||
| gh api --paginate "${package_path}?per_page=100" \ | ||||||||||
| --jq '.[] | [.id, .created_at, (.metadata.container.tags | join(","))] | @tsv' \ | ||||||||||
| > "${versions_file}" | ||||||||||
|
|
||||||||||
| while IFS=$'\t' read -r version_id created_at tags; do | ||||||||||
| if [[ "${tags}" =~ ^[0-9a-f]{7}$ ]] \ | ||||||||||
| && (( $(date -u -d "${created_at}" +%s) < cutoff )); then | ||||||||||
| echo "Deleting expired container tag ${tags}" | ||||||||||
| gh api --method DELETE "${package_path}/${version_id}" | ||||||||||
| fi | ||||||||||
| done < "${versions_file}" | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| ARG RUST_VERSION=1.96.1 | ||
| FROM rust:${RUST_VERSION}-bookworm AS builder | ||
|
|
||
| WORKDIR /src | ||
| COPY Cargo.toml Cargo.lock rust-toolchain.toml ./ | ||
| COPY crates ./crates | ||
| RUN cargo build --locked --release -p switchyard-server | ||
|
|
||
| FROM debian:bookworm-slim | ||
|
|
||
| RUN apt-get update \ | ||
| && apt-get install --yes --no-install-recommends ca-certificates \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY --from=builder /src/target/release/switchyard-server /usr/local/bin/switchyard-server | ||
|
|
||
| ARG IMAGE_VERSION=local | ||
| ARG VCS_REF=unknown | ||
| LABEL org.opencontainers.image.source="https://github.com/NVIDIA-NeMo/Switchyard" \ | ||
| org.opencontainers.image.description="Switchyard's libsy-based HTTP server" \ | ||
| org.opencontainers.image.licenses="Apache-2.0" \ | ||
| org.opencontainers.image.version="${IMAGE_VERSION}" \ | ||
| org.opencontainers.image.revision="${VCS_REF}" | ||
|
|
||
| USER 65532:65532 | ||
| EXPOSE 4000 | ||
| ENTRYPOINT ["/usr/local/bin/switchyard-server"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Scope package-write permission to the individual jobs.
A workflow-level
packages: writetoken is unnecessarily available to every current and future job. Remove the global permission block; grantcontents: readandpackages: writetopublish, and onlypackages: writetocleanup.Proposed permission scoping
🧰 Tools
🪛 zizmor (1.26.1)
[error] 11-11: overly broad permissions (excessive-permissions): packages: write is overly broad at the workflow level
(excessive-permissions)
🤖 Prompt for AI Agents
Source: Linters/SAST tools