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'