https://garden.io logo
#💻|dev
Title
# 💻|dev
b

big-spring-14945

05/31/2023, 4:33 PM
What is the Action-way to copy files from a dependency? Dependencies in action seems to be an array now, and there is no way to copy files anymore from other build actions?
Ah, there is
copyFrom
but it only exists in build actions. What if I need to
copyFrom
a build action into a deploy action? Isn't that a valid use case too?
My use case: I want to deploy a Kubernetes manifest from a remote git repository:
Copy code
kind: Deploy
type: kubernetes
name: test
source:
  repository:
    url: https://github.com/prometheus-operator/kube-prometheus.git#0198f98f682f1d7e40b1dd5615437a916107f1aa
spec:
  files:
    - manifests/grafana-dashboardDefinitions.yaml
Because I need to add a special annotation too, I want to run a kustomization on top of this. But when specifying
Copy code
spec:
  kustomize:
    path: .
it does not find the
kustomize.yaml
, because it is not part of the "action context" (What do you call this in a deploy action?) I thought maybe I could do
Copy code
kind: Build
type: exec
name: prometheus-operator-dashboards
source:
  repository:
    url: https://github.com/prometheus-operator/kube-prometheus.git#0198f98f682f1d7e40b1dd5615437a916107f1aa
path: manifests
And then I have a deploy like this:
Copy code
kind: Deploy
type: kubernetes
name: test
copyFrom:
  - build: prometheus-operator-dashboards
    sourcePath: grafana-dashboardDefinitions.yaml
spec:
  kustomization:
    path: .
  files:
    - grafana-dashboardDefinitions.yaml
a

alert-helicopter-61082

05/31/2023, 6:38 PM
You can also set
build
on Deploy actions, and then you shouldn't need the
copyFrom
. The Deploy's source path then becomes the build path of the Build action you reference.
b

big-spring-14945

06/01/2023, 9:09 AM
Ah ok! I'll try that
@alert-helicopter-61082 this also doesn't work for me... it seems somehow that the build has no effect, or the copyFrom doesn't work, but I'm not sure why repro:
Copy code
`
kind: Project
apiVersion: garden.io/v1
name: repro
environments:
 - name: default
providers:
 - name: local-kubernetes
---
# Get prometheus-operator Grafana default dashboards
kind: Build
type: exec
name: github-kube-prometheus
source:
  repository:
    url: https://github.com/prometheus-operator/kube-prometheus.git#3fff8b56097778f1491edba968aee3cfbd5652ef
---
# Combine the dashboards we need with the kustomization we need
kind: Build
type: exec
name: grafana-default-dashboards-with-kustomization
dependencies:
 - build.github-kube-prometheus
copyFrom:
  - build: github-kube-prometheus
    sourcePath: manifests/grafana-dashboardDefinitions.yaml
    targetPath: grafana-prometheus-default.yaml
include:
 - kustomize-add-label/**/*
 - grafana-prometheus-default.yaml
---
# Deploy the default dashboards after applying the kustomization
kind: Deploy
type: kubernetes
name: grafana-default-dashboards
description: Additional grafana dashboards
dependencies:
 - build.grafana-default-dashboards-with-kustomization
build: grafana-default-dashboards-with-kustomization
spec:
  namespace: monitoring
  kustomize:
    path: ./kustomize-add-label/
  files:
    - grafana-prometheus-default.yaml
error:
Copy code
✖ deploy.grafana-default-dashboards → Failed resolving status for Deploy type=kubernetes name=grafana-default-dashboards (took 0.04 sec). Here is the output:

ENOENT: no such file or directory, open '/Users/steffen/repro2/grafana-prometheus-default.yaml'
This issue is the culprit here: https://github.com/garden-io/garden/issues/4506
a

alert-helicopter-61082

06/01/2023, 11:09 AM
Ok, thanks for writing it up. Please let me know whether you need me to dig into this, or if anyone else can take it on.
I believe the issue is most likely that we're getting the Deploy source directory (and likely the same with Run and Test in many cases) with
action.basePath()
instead of
action.getBuildPath()
(see https://github.com/garden-io/garden/blob/5b59b9ffc39b4f99d387faa5905c3578c68809d5/core/src/actions/base.ts#L662). Which is to say, this is in some sense accounted for in the framework but incorrectly handled in various plugin handlers. However, that's such an easy mistake to make and to keep making it, so instead of fixing it from that point of view I'd suggest making it a bit more obvious which
action.<something>Path()
is the right one for each context. I think "basePath" should likely only be an private method on actions, because its semantics aren't obvious.
I suspect I'm talking myself into taking this on...
I decided not to fold in broader changes around action path stuff, just fixed the particular thing with kubernetes Deploys.
cc @big-spring-14945
b

big-spring-14945

06/06/2023, 11:55 AM
That's super cool @alert-helicopter-61082 –thank you for your work on this. Sorry that I did not have so much time to look more closely into it and make sure that it works with AEC pause. I might be able to do that this week or in the worst case next week.
9 Views