GoogleContainerTools / skaffold

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

Where should I set the skaffold.env to load my parameter to the skaffold.yaml? #9567

Open IcewaveLJW opened 1 week ago

IcewaveLJW commented 1 week ago

Expected behavior

skaffold.yaml can read the env variable WORKSPACE and worked as expexted.

Actual behavior

Error:parsing skaffold config: error parsing skaffold configuration file: parsing api version: yaml: line 13: did not find expected key

Information

I built like this

-ope/skaffold
  |_myservice
      |_skaffold.yaml
      |_skaffold.env
# Deprecated
apiVersion: skaffold/v2beta26
kind: Config
metadata:
  name: myservice
build:
  tagPolicy:
    gitCommit: {}
  local:
    push: true
    useDockerCLI: true
  artifacts:
    - image: dataservice
      context: '{{.WORKSPACE}}'/dist/
      docker:
        dockerfile: ../ope/docker/myservice/Dockerfile
deploy: ......

I saw the page here, https://skaffold.dev/docs/environment/env-file/, but seems it didn't work.

idsulik commented 1 week ago

Try this one: context: "${WORKSPACE}/dist/"

IcewaveLJW commented 1 week ago

"${WORKSPACE}/dist/"

Thank you for quick replying, but no luck it still error like [2024-11-14T07:24:43.432Z] image "myservice" context "/${WORKSPACE}/dist/" does not exist

idsulik commented 1 week ago

@IcewaveLJW it's a different error, have you passed the WORKSPACE environment? looks like you haven't

IcewaveLJW commented 1 week ago

@IcewaveLJW it's a different error, have you passed the WORKSPACE environment? looks like you haven't

@idsulik I saw this on the page Skaffold will automatically load these variables into the environment before running any commands. Actually it's blur for me to pass a parameter in skaffold.yaml, here is my jenkins gvy which execute skaffold command,

 mkdir dist || true
 skaffold config set --global collect-metrics false
 skaffold build --profile=jenkins --default-repo=${REPO} --file-output=${env.SKAFFOLD_BUILD_ARTIFACTS} ${SH_SKAFFOLD_DRY_RUN} ${SKAFFOLD_OPTIONS}
 skaffold deploy --profile=${params.ENV} --build-artifacts=${env.SKAFFOLD_BUILD_ARTIFACTS} ${SKAFFOLD_OPTIONS}

, shall I do something here?

idsulik commented 1 week ago

put this before the skaffold command: echo "${WORKSPACE}/dist/" && ls "${WORKSPACE}/dist/"

IcewaveLJW commented 1 week ago

Hi @idsulik I add these two new command export WORKSPACE=${env.WORKSPACE} echo "${WORKSPACE}/dist/" && ls "${WORKSPACE}/dist/" beforeskaffold config set, it can show in the log but it still look like this in deployment process.


[2024-11-14T07:54:50.249Z] + export WORKSPACE=/var/lib/jenkins/workspace/mono_Skaffold
[2024-11-14T07:54:50.249Z] + echo /var/lib/jenkins/workspace/mono_Skaffold/dist/
[2024-11-14T07:54:50.249Z] /var/lib/jenkins/workspace/mono_Skaffold/dist/
[2024-11-14T07:54:50.249Z] + ls /var/lib/jenkins/workspace/mono_Skaffold/dist/
[2024-11-14T07:54:50.249Z] + skaffold config set --global collect-metrics false
[2024-11-14T07:54:50.249Z] set global value collect-metrics to false
[2024-11-14T07:54:50.249Z] + skaffold build --profile=jenkins --default-repo=xxx --file-output=skaffold-build.json --filename=xxx --namespace=xxx
[2024-11-14T07:54:50.504Z] image "myservice" context "/${WORKSPACE}/dist/" does not exist```
idsulik commented 1 week ago

It seems to me that the context field doesn't support env templating https://skaffold.dev/docs/environment/templating/#list-of-fields-that-support-templating

IcewaveLJW commented 1 week ago

It seems to me that the context field doesn't support env templating https://skaffold.dev/docs/environment/templating/#list-of-fields-that-support-templating

Thank you for checking, I mean does there some way can help me to deal with that? Why we need to use env variable here is that we may have lots of task running in the same time which be assigned different WORKSPACE so we have to transport it into yaml and make as absolute path.