Skip to content
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

Action doesn't perform git checkout #528

Closed
BeyondEvil opened this issue Dec 24, 2021 · 5 comments · Fixed by #531
Closed

Action doesn't perform git checkout #528

BeyondEvil opened this issue Dec 24, 2021 · 5 comments · Fixed by #531

Comments

@BeyondEvil
Copy link
Contributor

Behaviour

Expected behaviour

According to README:

By default, this action uses the Git context so you don't need to use the actions/checkout action to checkout the repository because this will be done directly by buildkit.

Actual behaviour

Checkout doesn't happen.

Configuration

This

      - name: Build and push container
        uses: docker/build-push-action@v2
        with:
          context: ./app
          push: true
          tags: ${{ env.ECR_REGISTRY }}/proxyco/madmax-api:stable

fails with error:

/usr/local/bin/docker buildx build --tag ***.dkr.ecr.us-west-2.amazonaws.com/proxyco/madmax-api:stable --iidfile /tmp/docker-build-push-s6cfCu/iidfile --metadata-file /tmp/docker-build-push-s6cfCu/metadata-file --push ./app
error: unable to prepare context: path "./app" not found
Error: buildx failed with: error: unable to prepare context: path "./app" not found

I have to explicitly do a checkout first, for the build to be successful.

      - uses: actions/checkout@v2

      - name: Build and push container
        uses: docker/build-push-action@v2
        with:
          context: ./app
          push: true
          tags: ${{ env.ECR_REGISTRY }}/proxyco/madmax-api:stable

It's a private repo.

This is run on a self-hosted runner using ubuntu-latest.

What am I doing wrong?

@actualben
Copy link

actualben commented Dec 27, 2021

You're specifying a path context string (./app) which overrides the described automagic.

It looks like you want to specify a subdir on your build. You can still have most of the automagic by specifying the context as a full git repo URL in the way described by the docker build docs' description of Git Repo URLs. You'd use one with a trailing :app. Something like:

context: https://github.com/proxyco/madmax-api.git#${{ env.GITHUB_REF }}:app

To make it a bit more reusable you can do something like:

jobs:
  buildo:
    runs-on: ubuntu-latest
    env:
      CONTEXT_SUBDIR: app
    steps:
      - name: Login to ECR
        uses: docker/login-action@v1
        with:
          # your ecr details here
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      - name: Build and push container
        uses: docker/build-push-action@v2
        with:
          context: "${{ github.server_url }}/${{ github.repository }}.git#${{ github.ref }}:${{ env.CONTEXT_SUBDIR }}"
          push: true
          tags: ${{ env.ECR_REGISTRY }}/proxyco/madmax-api:stable

@actualben
Copy link

There is a related feature request in: #460

@BeyondEvil
Copy link
Contributor Author

Thanks for the response @actualben !

Also, thanks for the suggested workaround, although not pretty, haha. :)

I might take a stab at that feature request, if you'll allow me?

BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Dec 28, 2021
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528
BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Dec 28, 2021
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528

Signed-off-by: Jim Brännlund <jimbrannlund@fastmail.com>
@BeyondEvil
Copy link
Contributor Author

There is a related feature request in: #460

I went ahead and added a PR. Hope you approve! 😊

@BeyondEvil BeyondEvil reopened this Dec 28, 2021
BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Dec 28, 2021
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528

Signed-off-by: Jim Brännlund <jimbrannlund@fastmail.com>
@actualben
Copy link

👍 I was working on a PR myself but you were much quicker! I've submitted mine as a friendly alternative.

BeyondEvil added a commit to BeyondEvil/build-push-action that referenced this issue Jan 6, 2022
Since v0.9.0 of BuildKit (BuildX v0.7.0) you can provide a subdirectory
to the default Git context.

Closes docker#460
Closes docker#528

Signed-off-by: Jim Brännlund <jimbrannlund@fastmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants