Reputation: 5193
I have repository A that implements some CI/CD stuff to build an other repository. I can checkout the repository:
- name: Checkout Repo B
uses: actions/checkout@v3
with:
token: ${{ secrets.TOKEN }}
repository: org/repo-B
ref: main
path: repoB
And what I want, is to simply use this cloned repo instead of the actual one to build and push the docker image.
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build & Push API
uses: docker/build-push-action@v4
with:
push: true
context: "{{defaultContext}}:repoB"
file: apidockerfile
tags: ${{ env.ACR_URL }}/${{ env.API_IMAGE_NAME }}:${{ inputs.api }}
secrets: |
GIT_AUTH_TOKEN=${{ secrets.TOKEN }}
The problem is that buildx never finds the repoB, it always checkout the repoA event if the context is set.
Any idea please?
Upvotes: 0
Views: 504
Reputation: 517
The difference is that when you're using "{{defaultContext}}"
, this triggers the Git context
:
Git context
By default, this action uses the Git context, so you don't need to use the actions/checkout action to check out the repository as this will be done directly by BuildKit.
The git reference will be based on the event that triggered your workflow and will result in the following context:
https://github.com/<owner>/<repo>.git#<ref>.
[...]
Be careful because any file mutation in the steps that precede the build step will be ignored, including processing of the .dockerignore file since the context is based on the Git reference. However, you can use the Path context using the context input alongside the actions/checkout action to remove this restriction.
Default Git context can also be provided using the Handlebars template expression {{defaultContext}}. Here we can use it to provide a subdirectory to the default Git context:
[...]
which clones its own copy of your repository.
If you want to use the repository cloned in a previous step, use Path context
:
name: Build and push
uses: docker/build-push-action@v6
with:
context: ./mysubdir
push: true
tags: user/app:latest
So in your case:
context: ./repoB
Upvotes: 0