light-codegen icon indicating copy to clipboard operation
light-codegen copied to clipboard

In build.sh derive the organization name, image name, and version from the pom.xml

Open 243826 opened this issue 6 years ago • 9 comments

All the information is needed is readily available in the pom file. By using these values, we can avoid the configuration when not needed. But users invoking build.sh can still override that from command line.

243826 avatar Mar 08 '19 00:03 243826

@243826 I assume you mean the generated build.sh which is the script to build and publish Docker images. How to get the info from the pom.xml? By parsing the pom.xml in the shell script? Thanks.

stevehu avatar Mar 08 '19 00:03 stevehu

@stevehu This is what I think:

dockerize --publish --org org_name --name image_name --version version
--file docker_file

And invoke this command from within pom in response to deploy phase and docker profile.

dockerize is the new name for build.sh and of course can also be executed manually from outside of maven.

So no parsing of pom.xml involved. If you think this adds value, I should be able to code it up.

243826 avatar Mar 08 '19 06:03 243826

Yes. That should work great. I also looked at https://fabric8.io/guide/mavenDockerPush.html before but didn't find any time to get it implemented in the pom.xml file. There is another maven plugin designed for the same purpose.

stevehu avatar Mar 08 '19 13:03 stevehu

I'm using jib for this purpose for all my internal services and examples.. would recommend it

DSchrupert avatar Mar 08 '19 14:03 DSchrupert

jib looks good and we really need a tool that can support both Maven and Gradle. I am thinking to update the light-codegen to let users select Maven or Gradle(with Kotlin DSL) for their build. @NicholasAzar, Do you have any example to share?

stevehu avatar Mar 08 '19 14:03 stevehu

Yeah I've been using something similar to this:

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>1.0.1</version>
    <configuration>
        <from>
            <image>openjdk:8-jre-alpine</image>
        </from>
        <to>
            <image>registry.hub.docker.com/org/image</image>
            <credHelper>osxkeychain</credHelper>
            <tags>
                <tag>${project.version}</tag>
                <tag>latest</tag>
            </tags>
        </to>
        <container>
            <jvmFlags>
                <jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag>
                <jvmFlag>-XX:+UseCGroupMemoryLimitForHeap</jvmFlag>
                <jvmFlag>-XX:MaxRAMFraction=1</jvmFlag>
                <jvmFlag>-Dlight-4j-config-dir=/config</jvmFlag>
                <jvmFlag>-Dlogback.configurationFile=/config/logback.xml</jvmFlag>
            </jvmFlags>
        </container>
    </configuration>
</plugin>

Then there's no need to have a docker file or to even have docker installed..

DSchrupert avatar Mar 08 '19 17:03 DSchrupert

I wrote the other script yesterday. But if this is good, we should go this route and I feel that this is better especially since you do not need docker installed and I wanted an easy flag to trigger building the docker container.

243826 avatar Mar 08 '19 20:03 243826

I reviewed it and seems to work very well. @NicholasAzar do you want to create a PR or do you want me to create one?

243826 avatar Mar 08 '19 21:03 243826

@243826 yeah please feel free to work on this! There's a few items that might need to be thought through, like the default credHelper, image location, and how this would look in your pom.xml (in my case I have 2 copies of that plugin in different 2 profiles with different "to" image repositories so I can decide where I'm pushing the image). Just food for thought 😊

DSchrupert avatar Mar 08 '19 23:03 DSchrupert