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

Skaffold deploy does not replace images (even if default-repo and tag-policy are defined) #2481

Closed
strikeout opened this issue Jul 16, 2019 · 5 comments
Labels
area/tag priority/awaiting-more-evidence Lowest Priority. May be useful, but there is not yet enough supporting evidence.

Comments

@strikeout
Copy link

strikeout commented Jul 16, 2019

Expected behavior

skaffold deploy should take the artifacts from skaffold.yaml and replace the image names (in a kustomize deployment) accordingly when a tag-policy and a default-repo are defined.

Example:

artifacts.image: fake/node-react
--default-repo: docker.mycorp.com
build.tagPolicy.envTemplate: "{{.IMAGE_NAME}}:dev"
should result in: docker.mycorp.com/fake_node-react:dev

Actual behavior

skaffold deploy outputs the original, unmodified image-tags, eg.

results in: fake/node-react

Information

  • Skaffold version: v0.33
  • Operating system: macOs / linux
  • Contents of skaffold.yaml:
build:
    - image: fake/node-react
      context: app/node-react
...
profiles:
  - name: ci-dev-deploy     
    activation:         
      - env: ENV=dev
    build:
      tagPolicy:
        envTemplate:
          template: "{{.IMAGE_NAME}}:dev"
@dgageot dgageot added area/tag kind/bug Something isn't working labels Jul 16, 2019
@dgageot
Copy link
Contributor

dgageot commented Jul 16, 2019

@strikeout Is the problem still there if you inline the profile?

@dgageot
Copy link
Contributor

dgageot commented Jul 16, 2019

Oh, you are using skaffold deploy. Maybe you should try skaffold run.

  • skaffold run will build artifacts, tag them, replace the tags in the yaml manifests and deploy the app
  • skaffold deploy will use the tags you provide with --images=. It assumes images are already built

@tejal29 tejal29 added priority/awaiting-more-evidence Lowest Priority. May be useful, but there is not yet enough supporting evidence. and removed kind/bug Something isn't working labels Jul 16, 2019
@tejal29
Copy link
Contributor

tejal29 commented Jul 16, 2019

@strikeout @dgageot is right. skaffold run will build and replace the image with the newly built image.
Closing this for now.
Please re-open if you see this issue again.

Thanks
Tejal

@tejal29 tejal29 closed this as completed Jul 16, 2019
@strikeout
Copy link
Author

Thanks for your input, but I can not use the run stage: the images in my pipeline get build and pushed via an external worker container (gitlab-runner) plus some additional tests in between. I need skaffold just for the local dev and deployment part in unison with kustomize.

To quote the homepage, this should be possible:

What’s more, the pluggable architecture is central to Skaffold’s design, allowing you to use the tool you prefer in each stage.

I have tested the --images flag as well, together with a --default-repo arg it does not replace the image

# k8s-deployment.yml
image: my_image


# skaffold.yaml
artifacts:
 - image: my_image
   context: app/some-context

# cli command which does NOT replace my_image with proper repo-path
skaffold  --default-repo docker.somecorp.com  deploy --images  docker.somecorp.com/project/my_image:sometag 

result-k8s-deployment.yml
image: my_image :(

Would you be so kind as to provide a working example for the --images flag?

Also, I would expect skaffold to work in the way I mentioned in my report, as the runner has all the necessary infos to create and replace image with the proper path: the default-repo, an image-name from skaffold.yml and a tag-policy?

@tejal29
Copy link
Contributor

tejal29 commented Jul 17, 2019

You are missing the project id in the default-repo parameter.
Can you try

skaffold deploy --default-repo docker.somecorp.com/project --images docker.somecorp.com/project/my_image:tag  -v debug

The result-k8s-deployment.yaml shd be

result-k8s-deployment.yml
image: docker.somecorp.com/project/my_image:tag:sometag

Skaffold also provides build and deploy ad CI/CD build blocks. you could also use skaffold build if possible in your build phase.
You can try this in the example dirs:

$ cd examples/getting-started
$ skaffold build  --default-repo gcr.io/tejal-test --quiet > build.out
$ cat build.out &&  echo "\n"
{"builds":[{"imageName":"gcr.io/tejal-test/gcr.io/k8s-skaffold/skaffold-example","tag":"gcr.io/tejal-test/gcr.io/k8s-skaffold/skaffold-example:v0.33.0-116-gb847545d-dirty@sha256:c359d62ff3332fdfe29e2c8196cadaedbe1f21a29bc161563a9e46fabac728c2"}]}\n

$ skaffold deploy --default-repo gcr.io/tejal-test --build-artifacts  build.out -v debug
INFO[0000] Skaffold &{Version:v0.33.0-116-gb847545d ConfigVersion:skaffold/v1beta13 GitVersion: GitCommit:b847545d3ce283914cdc11b10edee4cf90abcd30 GitTreeState:clean BuildDate:2019-07-1
....
Starting deploy...
DEBU[0000] Running command: [kubectl version --client -ojson] 
...
kubectl client version: 1.11+
kubectl version 1.12.0 or greater is recommended for use with Skaffold
DEBU[0000] Running command: [kubectl --context gke_tejal-test_us-central1-a_dump create --dry-run -oyaml -f /usr/local/google/home/tejaldesai/go/src/github.com/GoogleContainerTools/skaffold/integration/examples/getting-started/k8s-pod.yaml] 
DEBU[0000] Command output: [apiVersion: v1
kind: Pod
metadata:
  name: getting-started
  namespace: default
spec:
  containers:
  - image: gcr.io/k8s-skaffold/skaffold-example
    name: getting-started
] 
DEBU[0000] manifests apiVersion: v1
kind: Pod
metadata:
  name: getting-started
  namespace: default
spec:
  containers:
  - image: gcr.io/k8s-skaffold/skaffold-example
    name: getting-started 
DEBU[0000] manifests with tagged images apiVersion: v1
kind: Pod
metadata:
  name: getting-started
  namespace: default
spec:
  containers:
  - image: gcr.io/tejal-test/gcr.io/k8s-skaffold/skaffold-example:v0.33.0-116-gb847545d-dirty@sha256:c359d62ff3332fdfe29e2c8196cadaedbe1f21a29bc161563a9e46fabac728c2
    name: getting-started 
DEBU[0000] manifests with labels apiVersion: v1
kind: Pod
metadata:
  labels:
    app.kubernetes.io/managed-by: skaffold-v0.33.0-116-gb847545d
    skaffold.dev/builder: local
    skaffold.dev/cleanup: "true"
    skaffold.dev/deployer: kubectl
    skaffold.dev/docker-api-version: "1.39"
    skaffold.dev/tag-policy: git-commit
    skaffold.dev/tail: "true"
  name: getting-started
  namespace: default
spec:
  containers:
  - image: gcr.io/tejal-test/gcr.io/k8s-skaffold/skaffold-example:v0.33.0-116-gb847545d-dirty@sha256:c359d62ff3332fdfe29e2c8196cadaedbe1f21a29bc161563a9e46fabac728c2
    name: getting-started 
DEBU[0000] 1 manifests to deploy. 1 are updated or new  
DEBU[0000] Running command: [kubectl --context gke_tejal-test_us-central1-a_dump apply -f - --force] 
pod/getting-started configured
Deploy complete in 922.476644ms
Waiting for deployments to stabilize
$

If you the result pod spec has the right default repo substituted.

$ kubectl get pod/getting-started -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    ....
  name: getting-started
  namespace: default
  resourceVersion: "29575267"
  selfLink: /api/v1/namespaces/default/pods/getting-started
  uid: 4adbfb28-a858-11e9-a145-42010a80006b
spec:
  containers:
  - image: gcr.io/tejal-test/gcr.io/k8s-skaffold/skaffold-example:v0.33.0-116-gb847545d-dirty@sha256:c359d62ff3332fdfe29e2c8196cadaedbe1f21a29bc161563a9e46fabac728c2
    imagePullPolicy: IfNotPresent
    name: getting-started
    resources:
      requests:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tag priority/awaiting-more-evidence Lowest Priority. May be useful, but there is not yet enough supporting evidence.
Projects
None yet
Development

No branches or pull requests

3 participants