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

0.13: [Bug]: When using templates, file added by copyFrom are excluded from the build context #5201

Closed
10ko opened this issue Oct 6, 2023 · 2 comments · Fixed by #5230
Closed

Comments

@10ko
Copy link
Member

10ko commented Oct 6, 2023

Garden Bonsai (0.13) Bug

Current Behavior

A user is trying to create a template + an exec action to dynamically use a dev Dockerfile (see below).

kind: Build
name: docker-dev
type: exec
include:
  - ./Dockerfile.dev
---

kind: ConfigTemplate
name: node-build

configs:
  - kind: Build
    type: container
    name: ${parent.name}-dev
    description: Development build of the ${parent.name}
    exclude: ['node_modules']
    dependencies:
      - build.docker-dev
    copyFrom:
      - build: docker-dev
        sourcePath: ./Dockerfile.dev
        targetPath: ./Dockerfile.dev
    spec:
      dockerfile: ./Dockerfile.dev

When trying to build the following templated build action:

kind: RenderTemplate

name: node-app-2

template: node-build

Garden will throw the following error:

...

✖ build.node-app-1-dev → Build failed (took 0.7 sec)
✖ build.node-app-1-dev → Failed processing Build type=container name=node-app-1-dev (took 0.73 sec). This is what happened:

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Dockerfile not found at ./Dockerfile.dev for build node-app-1-dev.
Please make sure the file exists, and is not excluded by include/exclude fields or .gardenignore files.
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 build action(s) failed!
...

NOTE: the Dockerfile.dev file is correctly found in the .garden/build directory for the action.

Expected behavior

Garden should take into consideration all the files in the action folder in the build context and successfully build the container using the Dockerfile.dev file.

Reproducible example

Please find the full repo below:

repro.zip

Workaround

There is no workaround at the moment. Additionally, the flow the user is trying to implement is a workaround in itself, to overcome the removal of the old generateFiles property of Modules (0.12).

Suggested solution(s)

Additional context

Your environment

  • OS:
  • How I'm running Kubernetes:

garden version: edge

@pabbott-starbucks
Copy link

To clarify, copyFrom does work for .txt files, but the Dockerfile does not work with a local-kubernetes provider. I suspect that the dockerfile is expected to be present before the copyFrom takes place. fun fact: If you switch to remote kubernetse and kaniko to build, everything works fine as the timing of a container build in that situation is different.

stefreak added a commit that referenced this issue Oct 11, 2023
In the container and jib-container build actions, we checked for the
existance of files checked in to version control for certain checks.

Garden allows for files to be injected into the build action dynamically
at run time, e.g. by using `copyFrom` and `generateFiles`.

We want to check for actual presence of files in the action's build
directory instead of checking for the files that are included from
version control.

Fixes #5201
stefreak added a commit that referenced this issue Oct 11, 2023
In the container and jib-container build actions, we checked for the
existance of files checked in to version control for certain checks.

Garden allows for files to be injected into the build action dynamically
at run time, e.g. by using `copyFrom` and `generateFiles`.

We want to check for actual presence of files in the action's build
directory instead of checking for the files that are included from
version control.

Fixes #5201
@stefreak
Copy link
Member

stefreak commented Oct 11, 2023

I was able to reproduce this issue with the following garden.yml configuration:

kind: Build
type: exec
name: generate-dockerfile
spec:
  command: [sh, -c, "echo FROM scratch > Dockerfile.dev"]
---

kind: Build
type: container
name: test
description: test
dependencies:
  - build.generate-dockerfile
copyFrom:
  - build: generate-dockerfile
    sourcePath: ./Dockerfile.dev
    targetPath: ./Dockerfile.dev
spec:
  dockerfile: ./Dockerfile.dev

Unfortunately, for kind=Module type=container this cannot be fixed because the image parameter is overloaded and we need to know pretty early wether the Dockerfile exists or not; However for kind=Build type=container (the new build actions) we managed to come up with a fix at #5230

github-merge-queue bot pushed a commit that referenced this issue Oct 11, 2023
In the container and jib-container build actions, we checked for the
existance of files checked in to version control for certain checks.

Garden allows for files to be injected into the build action dynamically
at run time, e.g. by using `copyFrom` and `generateFiles`.

We want to check for actual presence of files in the action's build
directory instead of checking for the files that are included from
version control.

Fixes #5201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants