dekorateio / dekorate

Tools for generating Kubernetes related manifests.
Apache License 2.0
477 stars 103 forks source link

image name, registry - customization needed #581

Open aishvaryaps opened 4 years ago

aishvaryaps commented 4 years ago

Hello, As per Doc Everything can be customized via annotation parameters and system properties Can i change Docker Registry name and image name When i run- mvn clean install -Ddekorate.build=true

My mvn build is success

Issue: Successfully built a53977439a6d Successfully tagged root/spring-boot-on-kubernetes-example:0.12-SNAPSHOT [INFO] Performing docker push. The push refers to repository [docker.io/root/spring-boot-on-kubernetes-example] c6efcdbd0555: Preparing 37c87d474eaa: Preparing 138726990cf7: Preparing 5b40c5fb5220: Preparing 717b092b8c86: Preparing denied: requested access to the resource is denied [INFO] Scaling deployment: anno-app-aishu to: 1.

i am unable to change root/spring-boot-on-kubernetes-example:0.12-SNAPSHOT i want to replace that with my docker hub user

By default following gets created for command- docker images root/spring-boot-on-kubernetes-example_0.12-SNAPSHOT____4cd5b401acc0__About a minute ago_141MB

it picks up the machine user I want to change root user to my registry and custom image name and tag I am referring Spring boot App for Kubernetes

iocanel commented 4 years ago

This is a dublicate of #409 which has been already fixed.

Please check: https://github.com/dekorateio/dekorate/blob/master/tests/issue-409-image-customization which is the integration tests that demonstrates how to fully customize the image.

If this isn't obvious in the doucmentation, it needs to change ASAP. So, I am keeping this open until documentation is update. Please, let me know how the suggested approach in the example works for you.

EDIT:

aishvaryaps commented 4 years ago

Hello Dekorate Team,

Thanks for responding.

### ISSUE:

  1. Name of the image and version is not customized eg: image: docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT
  2. Deployment is in CrashLoopBackOff eg : k8-demo-aishwarya-fdd8d58c6-lvxp9 0/1 CrashLoopBackOff

I have added in application.properties dekorate.docker.name: docker-demo dekorate.docker.group: docker-group dekorate.docker.version: v1

I want to build, push deploy on K8, hence my command to run the app is : mvn clean install -Duser.name=aishvaryaps -Ddekorate.build=true -Ddekorate.push=true -Ddekorate.deploy=true

[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------

Also, Docker image is built and pushed successfully in my docker hub user

Yaml file created in target/classes/META-INF/dekorate/kubernetes.yml


apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/name: k8-demo-aishwarya app.kubernetes.io/version: version1 name: k8-demo-aishwarya spec: ports:

Name of the image and version is not customized Why is the Deployment is in CrashLoopBackOff when the yaml file is created by dekorate ( i have tested that Docker image pushed runs correctly, no issue with image )

Kindly guide me Thank you

iocanel commented 4 years ago

Not sure what exactly is going on, we have a test testing exactly this case. Would it be possible to provide a reproducer?

aishvaryaps commented 4 years ago

Hello, Deployment in CrashLoopBackOff is resolved.. there was an issue with my container

Still facing same issue for name of the image and version is not customized Example of image: docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT I am able to customize docker registry, docker username. unable to customize image:version (spring-boot-on-kubernetes-example:0.12-SNAPSHOT)

Is it not able to read from application.properties, can we customize image name and versions from params Example: can we add in mvn command as a param to customize image name mvn clean install -Duser.name=aishvaryaps -Ddekorate.build=true -Ddekorate.push=true -Ddekorate.deploy=true

Any information required from my end , let me know Thank you

iocanel commented 4 years ago

Looking closer at this issue:

The configuration below seems wrong, as it seems to be a mix of styles (properties and yaml).

dekorate.docker.name: docker-demo
dekorate.docker.group: docker-group
dekorate.docker.version: v1

If you use application.properties it should be:

dekorate.docker.name: docker-demo
dekorate.docker.group: docker-group
dekorate.docker.version: v1

Or if you go with yaml it should be:

dekorate:
  docker:
    name: docker-demo
    group: docker-group
    version: v1
sasiperi commented 1 year ago

After looking at the source code I realized the prop name used is not "gorup" for kubes but is "partOf", for it to work. So what worked for me is the following property, to override "group" of the image for Kubernetes annotations

The name that worked in app.props (so the root/image-name or on mac the "userid/image-name) is dekorate.kubernetes.part-of= @project.groupId@. (if we want it to be, same as maven project props for example) Or something like

   dekorate:
     kubernetes:
       part-of: ^project.groupId^

ApplicationConfig does not even have any prop named "group" and ImageConfig does the below, for the group part of it. dekorate.docker.image: did not work either, "partOf" is the only thing working to override default group name of the image.

.withGroup(applicationConfiguration.getPartOf())

sasiperi commented 1 year ago

The code has .withGroup(applicationConfiguration.getPartOf()) --> group name. Then this.group = Strings.isNotNullOrEmpty(group) ? group : System.getProperty("user.name");

So instead of defaulting it to "user.name", I feel it would be more appropriate to default it to "group-id" from the "BuildInfo". (that's maven/gradle project.groupId).

https://github.com/dekorateio/dekorate/blob/main/core/src/main/java/io/dekorate/project/BuildInfo.java