GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
15k stars 1.62k forks source link

Path conflict in local config dependency #8231

Open IcewaveLJW opened 1 year ago

IcewaveLJW commented 1 year ago

Expected behavior

I have 4 micro-services and set 4 skaffold.yaml(A,B,C,D) for each of them, and I want to create an integrate for all of them so I create a. new skaffold.yaml(E) to handle this. I expect I can test this 4(A,B,C,D) individually and integrately(E). In the E/skaffold.yaml I need to use local config dependency. and In the (A,B,C,D) build part, I need to set build.artifact.context.

Actual behavior

Currently, A,B,C,D worked well, but when I want to run the E (which calls A,B,C,B by local config dependency) Due to

Note: In imported configurations, files are resolved relative to the location of imported Skaffold configuration file.

the path was changed and it will bring error because of it wrong path of build.artifact.context. like ' image "A" context "root/ope/skaffold/A/dist" does not exist ' Structure as follow.

___ope__skaffold__A
   |            |__B
   |            |__C
   |            |__D
   |            |__E
   |_dist
   |_docker

Information

E/skaffold.yaml

apiVersion: skaffold/v2beta26
kind: Config
requires:
  - path: ../A/skaffold.yaml
    configs: ["A"]
  - path: ../B/skaffold.yaml
    configs: ["B"]

A/skaffold.yaml

apiVersion: skaffold/v2beta26
kind: Config
metadata:
  name: A
build:
  tagPolicy:
    gitCommit: {}
  local:
    push: true
    useDockerCLI: true
  artifacts:
    - image: A
      context: dist/
      docker:
        dockerfile: ../ope/docker/A/Dockerfile
deploy:
~~~
profiles:
~~~

Conflict

Are there some ways I can override in E to reset the path ? I think I can just set the context by using absolute path but I can't do that because it will change by our different servers.

gsquared94 commented 1 year ago

the path was changed and it will bring error because of it wrong path of build.artifact.context. like ' image "A" context "root/ope/skaffold/A/dist" does not exist '

Can you specify which properties are being set differently here, and from which directory you're running Skaffold when invoking A/skaffold.yaml directly, and E/skaffold.yaml ?

IcewaveLJW commented 1 year ago

Sorry for such late reply because of my vacation. Currently we review this issue and find some different expectation about solution. The key points is In imported configurations, files are resolved relative to the location of imported Skaffold configuration file. and we use relative path to define our build.artifact.context.

So problem is we have a jenkins pipeline(goovy file) to control this. Here is a command in goovy file

  1. If we set A as target. sh """ skaffold build --profile=jenkins --default-repo=xxx --file-output=xxx.json --filename=ope/skaffold/A/skaffold.yaml --namespace=xxx""" And it worked.

  2. if we set E as target(which use a integrate skaffold.yaml include A). sh """ skaffold build --profile=jenkins --default-repo=xxx --file-output=xxx.json --filename=ope/skaffold/E/skaffold.yaml --namespace=xxx""" And it will return a error like image "A" context "${WORKSPACE}/ope/skaffold/A/dist/" does not exist What we want context is "${WORKSPACE}/dist/"

Problem is like above. So we consider a new fix way is to use environment variables in jenkins and hardcode as absolute path . In the jenkins(goovy files),we can use ${env,WORKSPACE} to check current workspace. As a part of path, we want to sent it into skaffold.yaml so that we can re-code skaffold.yaml

kind: Config
metadata:
  name: A
build:
  tagPolicy:
    gitCommit: {}
  local:
    push: true
    useDockerCLI: true
  artifacts:
    - image: A
      context: ${env,WORKSPACE}/dist/
      docker:
        dockerfile: ../ope/docker/A/Dockerfile
deploy:
~~~
profiles:
~~~

But current we can't find a way to read environment variables from jenkins? context: ${env,WORKSPACE}/dist/ this is not work. What we can sure is in jenkins pipeline goovy file sh "ws: ${env.WORKSPACE}" is working. How to sent or pass this value into "ope/skaffold/A/skaffold.yaml" is the most efficient way for solving issues.

IcewaveLJW commented 1 year ago

the path was changed and it will bring error because of it wrong path of build.artifact.context. like ' image "A" context "root/ope/skaffold/A/dist" does not exist '

Can you specify which properties are being set differently here, and from which directory you're running Skaffold when invoking A/skaffold.yaml directly, and E/skaffold.yaml ?

Addtion: I found the feature I want but seems it not be improved well XD https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues/378 Also some other ticket https://github.com/GoogleContainerTools/skaffold/pull/295 But still I didn't find exact way or doc for how to use skaffold.yaml. especially how to pass the values from platform(like Jenkins pipeline groovy) through the command or some other way.

IcewaveLJW commented 10 months ago

Does this any update on this issues XD