konveyor / move2kube

Move2Kube is a command-line tool for automating creation of Infrastructure as code (IaC) artifacts. It has inbuilt support for creating IaC artifacts for replatforming to Kubernetes/Openshift.
https://move2kube.konveyor.io/
Apache License 2.0
383 stars 118 forks source link

Dockerfile Missing Version in Name When Copying jar File #857

Closed jacobmammoliti closed 2 years ago

jacobmammoliti commented 2 years ago

Describe the bug Trying to migrate a CloudFoundry application to Kubernetes with the Gradle and Cloud Foundry transformer. The Dockerfile that gets generated does not reference the jar file built by Gradle properly. It is missing the version. In my specific example, the Dockerfile tries a COPY with COPY --from=spring-music-buildstage /app/build/libs/spring-music.jar . when Gradle actually builds /app/build/libs/spring-music-1.0.jar as it references the version from gradle.properties.

To Reproduce Steps to reproduce the behavior:

  1. Git clone spring-music git clone https://github.com/cloudfoundry-samples/spring-music
  2. Plan a Migration move2kube plan -s spring-music
  3. Transform move2kube transform

Expected behavior The Dockerfile to reference the correct jar file name. It is leaving out the version of the jar file being built.

Desktop (please complete the following information):

Additional context Here is the full Dockerfile (minus the comments):

FROM registry.access.redhat.com/ubi8/ubi:latest AS spring-music-buildstage
RUN yum install -y java-17-openjdk-devel

WORKDIR /app

# copy everything, including child modules to do a build using the parent build.gradle
COPY . .
COPY gradlew .
COPY gradle gradle

RUN ./gradlew clean assemble

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
ENV PORT 8080
RUN microdnf update && microdnf install --nodocs java-17-openjdk-devel && microdnf clean all
COPY --from=spring-music-buildstage /app/build/libs/spring-music.jar .
EXPOSE 8080
CMD ["java", "-jar", "spring-music.jar"]
ashokponkumar commented 2 years ago

Thanks @jacobmammoliti for the issue.

@HarikrishnanBalagopal can you please take a look at this issue. We are most probably not using the gradle.properties file yet. We might need to add it.

HarikrishnanBalagopal commented 2 years ago

@jacobmammoliti Yeah we were not looking at gradle.properties for the version. Have made a PR to fix that. Let us know if we should be looking for more things inside the gradle.properties file.

The new Dockerfiles we generate have the version in the JAR filename.

$ cat Dockerfile.buildstage 
#   Copyright IBM Corporation 2021
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

FROM registry.access.redhat.com/ubi8/ubi:latest AS spring-music-buildstage
RUN yum install -y java-1.8.0-openjdk-devel

WORKDIR /app

# copy everything, including child modules to do a build using the parent build.gradle
COPY . .
COPY gradlew .
COPY gradle gradle

RUN ./gradlew clean assemble
ibm-macbook-pro:source user$ cat Dockerfile
#   Copyright IBM Corporation 2021
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
ENV PORT 8080
RUN microdnf update && microdnf install --nodocs java-1.8.0-openjdk-devel && microdnf clean all
COPY --from=spring-music-buildstage /app/build/libs/spring-music-1.0.jar .
EXPOSE 8080
CMD ["java", "-jar", "spring-music-1.0.jar"]

and tested building and running those Dockerfiles:

$ ./builddockerimages.sh 
building image spring-music-buildstage
[+] Building 3.5s (12/12) FINISHED                                                                                                                                                                                                                            
 => [internal] load build definition from Dockerfile.buildstage                                                                                                                                                                                          0.0s
 => => transferring dockerfile: 950B                                                                                                                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                                                                                          0.0s
 => [internal] load metadata for registry.access.redhat.com/ubi8/ubi:latest                                                                                                                                                                              3.4s
 => [internal] load build context                                                                                                                                                                                                                        0.0s
 => => transferring context: 1.23MB                                                                                                                                                                                                                      0.0s
 => [1/7] FROM registry.access.redhat.com/ubi8/ubi:latest@sha256:8b002ccba444981ba32cab7d9454414da920218bd13f5b3f276978d577cd966f                                                                                                                        0.0s
 => CACHED [2/7] RUN yum install -y java-1.8.0-openjdk-devel                                                                                                                                                                                             0.0s
 => CACHED [3/7] WORKDIR /app                                                                                                                                                                                                                            0.0s
 => CACHED [4/7] COPY . .                                                                                                                                                                                                                                0.0s
 => CACHED [5/7] COPY gradlew .                                                                                                                                                                                                                          0.0s
 => CACHED [6/7] COPY gradle gradle                                                                                                                                                                                                                      0.0s
 => CACHED [7/7] RUN ./gradlew clean assemble                                                                                                                                                                                                            0.0s
 => exporting to image                                                                                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                                                                                  0.0s
 => => writing image sha256:90c25056ba1f53f6dc57fcafe6e0ca31dcfede547c3cdd0a65d546b8d97d22c1                                                                                                                                                             0.0s
 => => naming to docker.io/library/spring-music-buildstage                                                                                                                                                                                               0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
/Users/user/temp/tbug-m2k-857/t8/myproject
building image spring-music
[+] Building 1.6s (8/8) FINISHED                                                                                                                                                                                                                              
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                     0.0s
 => => transferring dockerfile: 943B                                                                                                                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                                                                                          0.0s
 => [internal] load metadata for registry.access.redhat.com/ubi8/ubi-minimal:latest                                                                                                                                                                      1.5s
 => FROM docker.io/library/spring-music-buildstage:latest                                                                                                                                                                                                0.0s
 => [stage-0 1/3] FROM registry.access.redhat.com/ubi8/ubi-minimal:latest@sha256:9a9149dbba8dc5a961dfec460018c245b49da0f52e9934e1a70dd4d42f9fc5b7                                                                                                        0.0s
 => CACHED [stage-0 2/3] RUN microdnf update && microdnf install --nodocs java-1.8.0-openjdk-devel && microdnf clean all                                                                                                                                 0.0s
 => CACHED [stage-0 3/3] COPY --from=spring-music-buildstage /app/build/libs/spring-music-1.0.jar .                                                                                                                                                      0.0s
 => exporting to image                                                                                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                                                                                  0.0s
 => => writing image sha256:b3e92093784187b3e4f8e56b771aa8868d239fd49e1cb7e6d1c5bc1be3a45689                                                                                                                                                             0.0s
 => => naming to docker.io/library/spring-music                                                                                                                                                                                                          0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
/Users/user/temp/tbug-m2k-857/t8/myproject
done
$ docker run --rm -it -p 8080:8080 spring-music

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.7)

2022-09-05 15:15:07.153  INFO 1 --- [           main] .m.c.SpringApplicationContextInitializer : Found services 
2022-09-05 15:15:07.159  INFO 1 --- [           main] o.c.samples.music.Application            : Starting Application using Java 1.8.0_342 on f851ffb2ff1f with PID 1 (/spring-music-1.0.jar started by root in /)
2022-09-05 15:15:07.160  INFO 1 --- [           main] o.c.samples.music.Application            : No active profile set, falling back to 1 default profile: "default"
2022-09-05 15:15:08.091  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2022-09-05 15:15:08.093  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-09-05 15:15:08.299  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 196 ms. Found 1 JPA repository interfaces.
2022-09-05 15:15:08.917  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-09-05 15:15:08.932  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-09-05 15:15:08.932  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.62]
2022-09-05 15:15:09.015  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-09-05 15:15:09.015  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1806 ms
2022-09-05 15:15:09.269  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-09-05 15:15:09.458  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-09-05 15:15:09.510  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-09-05 15:15:09.572  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.8.Final
2022-09-05 15:15:09.770  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-09-05 15:15:09.924  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-09-05 15:15:10.623  INFO 1 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-09-05 15:15:10.632  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-09-05 15:15:10.893  WARN 1 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-09-05 15:15:11.060  INFO 1 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2022-09-05 15:15:11.300  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 13 endpoint(s) beneath base path '/actuator'
2022-09-05 15:15:11.344  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-09-05 15:15:11.358  INFO 1 --- [           main] o.c.samples.music.Application            : Started Application in 4.637 seconds (JVM running for 5.242)
2022-09-05 15:15:16.919  INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-09-05 15:15:16.919  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-09-05 15:15:16.922  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms
HarikrishnanBalagopal commented 2 years ago
image

And the website comes up now.