From ebe47f0be45d23e5bc0f468aa03c65c7d9fdba11 Mon Sep 17 00:00:00 2001 From: Francis Secada Date: Sun, 15 Nov 2026 22:50:47 -0500 Subject: [PATCH] ci: read private shared-packages with a GitHub App token The image build resolves a git dependency on the private fsecada01/shared-packages repo. Mint a short-lived, read-only GitHub App installation token in the workflow (create-github-app-token v2.2.2, pinned to a commit SHA) and pass it to the build as a BuildKit secret. The Dockerfile mounts it for the python_build.sh RUN step only and points git at it with GIT_CONFIG_* variables, so it never lands in an ARG, ENV or image layer. The secret is optional, so builds without it still work. Also install git in the final stage and stop persisting checkout credentials. Fork PRs get no secrets, so the image build is only expected to run for same-repo branches. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017F3tydTA6i18mpWhvLQv9d --- .github/workflows/docker-image.yml | 19 +++++++++++++++++++ Dockerfile | 10 ++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 39b5567..87c2d0d 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -29,6 +29,23 @@ jobs: run: echo "sanitized_branch=$(echo '${{ steps.extract_branch.outputs.branch }}' | sed 's/\//-/g')" >> $GITHUB_OUTPUT id: sanitize_branch - uses: actions/checkout@v4 + with: + persist-credentials: false + # The image build fetches the PRIVATE fsecada01/shared-packages repo + # (git dependency), so it needs a short-lived GitHub App installation + # token with read-only contents access to that one repository. + # This repo is public: pull requests from forks do not receive + # secrets, so this step fails for them. The image build is only + # expected to run for same-repo branches. + - name: Create GitHub App token for shared-packages + id: app-token + uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2.2.2 + with: + app-id: ${{ secrets.SHARED_PACKAGES_APP_ID }} + private-key: ${{ secrets.SHARED_PACKAGES_APP_PRIVATE_KEY }} + owner: fsecada01 + repositories: shared-packages + permission-contents: read - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Set up Python ${{ matrix.python-version }} @@ -44,3 +61,5 @@ jobs: s3docker.francissecada.com/pygentic_ai:${{ steps.sanitize_branch.outputs.sanitized_branch }}.${{ steps.date.outputs.date }} s3docker.francissecada.com/pygentic_ai:${{ steps.sanitize_branch.outputs.sanitized_branch }}-latest pull: true + secrets: | + gh_token=${{ steps.app-token.outputs.token }} diff --git a/Dockerfile b/Dockerfile index bd0a4ab..ae11517 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ WORKDIR ${WORKDIR} FROM s3docker.francissecada.com/fjs_ubuntu:latest RUN apt-get update && \ - apt-get install -y curl + apt-get install -y curl git ENV WORKDIR="/opt/pygentic_ai" COPY --from=intermediate ${WORKDIR} ${WORKDIR} WORKDIR ${WORKDIR} @@ -27,5 +27,11 @@ RUN mkdir -p /tmp/log/celery && \ chown celery:celery celerybeat-schedule RUN find . -name "*.sh" -exec chmod +x {} \; RUN echo $WORKDIR -RUN /bin/bash -c 'source $WORKDIR/docker/pygentic_ai/python_build.sh' +# python_build.sh resolves a private git dependency (fsecada01/shared-packages). +# The GitHub App token comes in as a BuildKit secret mounted only for this +# RUN step: it must never go in ARG/ENV, which would persist in image layers +# and history. git reads the exported GIT_CONFIG_* variables for this one RUN +# only; they are inherited by the child bash. The secret is optional so +# builds without it (e.g. local builds) still work for public dependencies. +RUN --mount=type=secret,id=gh_token,required=false if [ -s /run/secrets/gh_token ]; then export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="url.https://x-access-token:$(cat /run/secrets/gh_token)@github.com/fsecada01/shared-packages.insteadOf" GIT_CONFIG_VALUE_0="https://github.com/fsecada01/shared-packages"; fi && /bin/bash -c 'source $WORKDIR/docker/pygentic_ai/python_build.sh' CMD /bin/bash -c 'source $WORKDIR/docker/pygentic_ai/python_start.sh'