https://garden.io logo
Uunable to resolve project outputs from Build acti...
# 🌱|help-and-getting-started
a
I am trying to display project outputs after running a Build actions. The reference in `project.garden.yaml `is
Copy code
outputs:
  - name: app_image
    value: "${actions.build.app.outputs.deploymentImageName}"
Running
garden get outputs
the Build actions are triggered but I receive the following error:
Copy code
...(removed for char limits)
ℹ build.app                 → Getting status for Build app (type container) at version v-e5b0c8e672...
ℹ build.app2                → Getting status for Build app2 (type container) at version v-b0365ed458...
ℹ build.app                 → Building app (type container) at version v-e5b0c8e672...
ℹ build.app2                → Building app2 (type container) at version v-b0365ed458...
ℹ build.app                 → Building app:v-ef287852fe...
ℹ build.app2                → Building app2:v-c41698070a...
✔ build.app2                → Done (took 1.1 sec)
✔ build.app                 → Done (took 1.2 sec)
project.garden.yaml:58
...
57  |   - name: app_image
58  |     value: "${actions.build.app.outputs.deploymentImageName}"
-----------------^
Could not find key actions. Available keys: local, command, datetime, project, git, secrets, variables, var, environment, providers, modules, runtime.

See .garden/error.log for detailed error message
My garden project api version is set to
apiVersion: garden.io/v2
and my garden version is
garden version: 0.14.7
. Why aren't actions outputs available? Very strange that
modules
is available since it is a not supported in
0.14
afaik. Anyway, any help would be appreciated! Thanks!
@microscopic-river-74022 - will try you - any ideas?
b
Hey @ancient-island-74119 ! Sorry for the late reply, we have quite a few people out and just catching up now. Would you mind showing me more of the config? At first glance it looks like you're using these in the project config (i.e. the YAML doc with
kind: Project
which doesn't work. You can only reference action outputs in other actons. Here's a quick example that I just tested and works as expected:
Copy code
yaml
# In project.garden.yml
apiVersion: garden.io/v2
kind: Project
name: outputs-test

environments:
  - name: local

---
# There's a Dockerfile in the same dir as the project.garden.yml file that the build uses
# The contents of the file are:
# FROM alpine:latest
# CMD ["echo", "Hello from my-build"]
kind: Build
type: container
name: my-build

---
kind: Run
type: exec
name: output-printer
spec:
  command: [echo, "Image name is: ${actions.build.my-build.outputs.deploymentImageName}"]
When I run
garden run output-printer
I get:
Image name is: my-build
As noted in the comment, you need a Dockerfile next to this config file if you want to give it a try. Mine was just:
Copy code
FROM alpine:latest
CMD ["echo", "Hello from my-build"]
Let me know if that helps
a
yes, I believe that is what I was doing which may be the issue. Thanks for the example and explanation. I'll see if this usage solves my problem. Basically I am trying to figure out a method to scan an image in CI before it is pushed. I don't think there is a way using garden publish to hook into it to do this, so was trying to maybe run
garden get outputs --env ci --output json
which would run a build - then taking those outputs be able to scan the image before pushing it. BUT maybe some combination of Run and Build (or other garden Action) would do it? idk If there are any examples of this sort of use case available that would be great - I didnt notice any in the /examples available in the public repo. Thanks again!
b
Aha I see. What tool are you using for scanning your images? We'd be happy to add an example for that. Either in our docs or /examples dir. Here's one simple example using Snyk, but of course depends your tooling:
Copy code
yaml
kind: Build
name: my-image
type: container
---
kind: Run
name: scan-image
type: exec
spec:
  command: [/bin/sh, "-c", "snyk container test ${actions.build.my-image.outputs.deploymentImageId}"]
Note that we're using the
deployImageId
output here which contains the full image path with the version tag.
If this is a common pattern for you, you might want to look into using ConfigTemplates which are basically re-usable templates with multiple configs. For example:
Copy code
yaml
kind: ConfigTemplate
name: build-and-scan

configs:
  - kind: Build
    type: container
    name: ${parent.name} # <--- Parent refers to the RenderTemplate.
    description: ${parent.name} build # <--- So this becomes "my-image-one build" or "my-image-two build" (as per the RenderTemplate actions below)

  - kind: Run
    type: exec
    name: scan-${parent.name}
    description: Scan the ${parent.name} container image
    dependencies:
      - build.${parent.name}
    spec:
      command: ["/bin/sh", "-c", "snyk container test ${actions.build[parent.name].outputs.deploymentImageId}"]

---
kind: RenderTemplate
template: build-and-scan
name: my-image-one
---
kind: RenderTemplate
template: build-and-scan
name: my-image-two
With this you can e.g. run
garden run scan-my-image-one
You can also add inputs to parametrise ConfigTemplates. Currently you do that with a JSON schema which is a bit cumbersome but with our next release you can do that inline in YAML. Here's the docs for how it's done currently: https://docs.garden.io/features/config-templates But I'd highly encourage you test it with the inline version which we're planning to release this week. Instead of adding a JSON schem you'd do something like this:
Copy code
yaml
kind: ConfigTemplate
name: build-image

inputs:
  os:
    type: string
  arch:
    type: string

configs:
  - kind: Build
    type: exec
    # Note: ${parent.name} resolves to the name of the RenderTemplate config below
    name: ${parent.name}-${inputs.os}-${inputs.arch}
    spec:
      command: ["./build.sh", "${inputs.os}", "${inputs.arch}"]

---

kind: RenderTemplate
name: build-image
template: build-image
matrix:
  os: ["linux", "macos"]
  arch: ["amd64", "arm64"]
a
Sorry I am late getting back to this... Yes, we do happen to use snyk so that example is very useful! Again thanks for all this info! I appreciate it! I hope to get back to this soon so i can take a detailed look at config templates etc - if I have any followup questions I will let you know.
Just wanted to follow up (kinda late) that this was very helpful in handling this @brief-restaurant-63679 thanks again for your help!
11 Views