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

fix: make IMAGE_TAG available in buildArgs when used in docker FROM #9450

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

abe-winter
Copy link

@abe-winter abe-winter commented Jun 19, 2024

Related:

Description
Apologies if I am simply misunderstanding something and this can be fixed w/out a code change. I am certainly not fully wrapping my head around this codebase.

This PR adds the ability to use IMAGE_TAG (IMAGE_REPO etc) in the docker buildArgs section, specifically when the build arg is then consumed in the Dockerfile FROM. On current stable and main, this case fails in the depList / SingleArtifactDependencies phase, with logs like:

Checking cache...

  • base: Found Remotely
  • child: Error checking cache.

getting hash for artifact "child": getting dependencies for "child": parsing ONBUILD instructions: retrieving image "gcr.io/headsdown/base:": parsing reference "gcr.io/headsdown/base:": could not parse reference: gcr.io/headsdown/base:

Note that when used with dependencies (as below), this seems to only work reliably if I run skaffold build && skaffold run. skaffold run by itself will sometimes fail with 'image not found remotely'.

Repro

Stripped-down skaffold.yaml:

build:
  local:
    useBuildkit: true
  artifacts:
    - image: base
      docker:
        dockerfile: Dockerfile
    - image: child
      requires:
      - image: base
      docker:
        dockerfile: child/Dockerfile
        buildArgs:
          IMAGE_TAG: '{{.IMAGE_TAG}}'

Top of child/Dockerfile:

# syntax=docker/dockerfile:1
ARG IMAGE_TAG
FROM gcr.io/PROJECTNAME/base:$IMAGE_TAG

tldr the second artifact depends on the first and then uses it as a base image

User facing changes
I think the docs already imply this is possible

Follow-up Work
No idea if I'm conforming to house style -- if accepted, guessing someone on the team will need to clean up or at least assign me cleanup. I would normally have submitted a bug rather than a PR for something like this, but I didn't understand why my template param was missing until I'd already solved the problem.

If this is something useful, happy to add tests etc.

Copy link

google-cla bot commented Jun 19, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@abe-winter abe-winter changed the title make IMAGE_TAG available in buildArgs when used in docker FROM fix: make IMAGE_TAG available in buildArgs when used in docker FROM Jun 19, 2024
@abe-winter abe-winter marked this pull request as draft September 6, 2024 17:50
@abe-winter abe-winter marked this pull request as ready for review September 6, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant