eclipse-jkube / jkube

Build and Deploy java applications on Kubernetes
https://www.eclipse.dev/jkube/
Eclipse Public License 2.0
775 stars 521 forks source link

k8s:build issue COPY failed: stat #149

Closed zebu closed 4 years ago

zebu commented 4 years ago

I'm seeing an issue building docker images with 1.0.0-alpha-1. The pom + Dockerfile has no issues with fabric8 4.4.1.

[INFO] k8s: ---> d99a48de8998 [INFO] k8s: Step 9/10 : COPY target/my-service.jar my-service.jar [INFO] k8s: [ERROR] k8s: Failed to execute the build [Error while trying to build the image] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.812 s [INFO] Finished at: 2020-04-13T15:23:49-04:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.0.0-alpha-1:build (default-cli) on project my-service: Failed to execute the build: Error while trying to build the image: Unable to build image [myrepo.com:5100/com.xxx.xxxxx.xx/my-service:1.0] : "COPY failed: stat /var/lib/docker/tmp/docker-builder481246942/target/my-service.jar: no such file or directory" -> [Help 1]

Has anyone run across this?

rohanKanojia commented 4 years ago

@zebu : ah, Could you please share a sample pom so that we can try to reproduce?

zebu commented 4 years ago
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.companyname.ol</groupId>
    <artifactId>my-service</artifactId>
    <version>1.0</version>

    <name>my-service</name>
    <description>MyService</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR3</spring-cloud.version>

        <junit-jupiter.version>5.6.0</junit-jupiter.version>
        <mockito.version>2.24.0</mockito.version>
        <cim-clientinterface.version>1.2.0</cim-clientinterface.version>

        <kubernetes-maven-plugin.version>1.0.0-alpha-1</kubernetes-maven-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>2.1.1</version>
        </dependency>

        <!-- junit -->
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mockito</groupId>
                    <artifactId>mockito-junit-jupiter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-test-support</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- For cucumber -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>${project.artifactId}</finalName>

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>

                <!-- todo: use a buildpacks/layered jar in spring-boot 2.3 -->
                <!-- https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1 -->
            </plugin>
            <plugin>                
                <groupId>org.eclipse.jkube</groupId>
                <artifactId>kubernetes-maven-plugin</artifactId>
                <version>${kubernetes-maven-plugin.version}</version>

                <configuration>
                    <mode>kubernetes</mode>
                    <namespace>com-companyname-dev</namespace>
                    <verbose>true</verbose>

                    <access>
                        <masterUrl>https://ratlbls01-api.companyname.com</masterUrl>
                    </access>

                    <generator>
                        <config>
                            <spring-boot>
                                <color>always</color>
                            </spring-boot>
                        </config>
                    </generator>

                    <enricher>
                        <config>
                            <jkube-controller>
                                <!-- why is this not overriding the name in fragment? -->
                                <name>myservice-1-0-dev</name>
                                <pullPolicy>Always</pullPolicy>
                            </jkube-controller>

                            <jkube-service>
                                <type>NodePort</type>
                            </jkube-service>
                        </config>
                    </enricher>

                    <images>
                        <image>
                            <alias>${project.artifactId}</alias>
                            <name>dockercentral.companyname.com:5100/${project.groupId}/%a:%l</name>
                            <build>
                                <dockerFile>${project.basedir}/Dockerfile</dockerFile>
                            </build>
                        </image>
                    </images>

                </configuration>

            </plugin>
        </plugins>
    </build>

</project>
rohanKanojia commented 4 years ago

@zebu: strange, I copy-pasted your pom with some modifications in one of my samples but was unable to reproduce this. I'm not sure what's wrong in my reproduced but it was able to build image fine.

https://github.com/r0haaaan/jkube-dockerfile-sample

~/work/repos/jkube-dockerfile-sample : $ mvn k8s:build
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< com.companyname.ol:my-service >--------------------
[INFO] Building my-service 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.0.0-alpha-1:build (default-cli) @ my-service ---
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[WARNING] k8s: Cannot access cluster for detecting mode: Unknown host ratlbls01-api.companyname.com: Name or service not known
[INFO] k8s: Generators:
[INFO] k8s:  - quarkus
[INFO] k8s:  - spring-boot
[INFO] k8s:  - wildfly-swarm
[INFO] k8s:  - thorntail-v2
[INFO] k8s:  - openliberty
[INFO] k8s:  - karaf
[INFO] k8s:  - vertx
[INFO] k8s:  - java-exec
[INFO] k8s:  - webapp
[WARNING] k8s: Cannot access cluster for detecting mode: Unknown host ratlbls01-api.companyname.com
[INFO] k8s: [docker.io/com.companyname.ol/my-service:1.0] "my-service": Created docker-build.tar in 305 milliseconds
[INFO] k8s: Step 1/1 : FROM openjdk:latest
[INFO] k8s: 
[INFO] k8s: ---> 6adc576f6a58
[INFO] k8s: Successfully built 6adc576f6a58
[INFO] k8s: Successfully tagged com.companyname.ol/my-service:1.0
[INFO] k8s: [docker.io/com.companyname.ol/my-service:1.0] "my-service": Built image sha256:6adc5
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.344 s
[INFO] Finished at: 2020-04-16T17:40:20+05:30
[INFO] ------------------------------------------------------------------------

Could you please share a full project(maybe contents of your Dockerfile) or see what's wrong in my reproducer?

zebu commented 4 years ago

I'll build a demo project that demonstrates the issue. Give me a few days

zebu commented 4 years ago

I've written an example project that demonstrates a similar issue but not the exact. https://github.com/zebu/jkube-demo.git

The original issue was stat complaining about a file that did not exist. This issue I'm seeing now is the copy not finding files.

working example mvn -f pom_fabric8.xml clean package fabric8:build

[INFO] --- fabric8-maven-plugin:4.4.1:build (default-cli) @ jkube-demo ---
[INFO] F8: Running in Kubernetes mode
[INFO] F8: Building Container image with Docker in Kubernetes mode
[WARNING] F8: Cannot access cluster for detecting mode: Unknown host zlp30797.vci.att.com: nodename nor servname provided, or not known
[INFO] F8: Generators:
[INFO] F8:  - quarkus
[INFO] F8:  - spring-boot
[INFO] F8:  - wildfly-swarm
[INFO] F8:  - thorntail-v2
[INFO] F8:  - openliberty
[INFO] F8:  - karaf
[INFO] F8:  - vertx
[INFO] F8:  - java-exec
[INFO] F8:  - webapp
[WARNING] F8: Cannot access cluster for detecting mode: Unknown host zlp30797.vci.att.com
[INFO] Building tar: /Users/bconner/git/jkube-demo/target/docker/jkube-demo/1.0.0/tmp/docker-build.tar
[INFO] F8: [jkube-demo:1.0.0]: Created docker-build.tar in 121 milliseconds
[INFO] F8: Step 1/3 : FROM openjdk:15-slim-buster
[INFO] F8: 
[INFO] F8: ---> 3311374531ea
[INFO] F8: Step 2/3 : COPY target/*.jar application.jar
[INFO] F8: 
[INFO] F8: ---> 1367719120ee
[INFO] F8: Step 3/3 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=st9","-jar","/application.jar"]
[INFO] F8: 
[INFO] F8: ---> Running in d19ab1045670
[INFO] F8: Removing intermediate container d19ab1045670
[INFO] F8: ---> 42a3138ed628
[INFO] F8: Successfully built 42a3138ed628
[INFO] F8: Successfully tagged jkube-demo:1.0.0
[INFO] F8: [jkube-demo:1.0.0]: Built image sha256:42a31
[INFO] F8: [jkube-demo:1.0.0]: Removed old image sha256:f9b76
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.448 s
[INFO] Finished at: 2020-04-25T13:35:51-04:00
[INFO] ------------------------------------------------------------------------

non-working example mvn -f pom.xml clean package k8s:build

[INFO] --- kubernetes-maven-plugin:1.0.0-alpha-2:build (default-cli) @ jkube-demo ---
[WARNING] k8s: Cannot access cluster for detecting mode: Unknown host zlp30797.vci.att.com: nodename nor servname provided, or not known
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[INFO] k8s: Generators:
[INFO] k8s:  - quarkus
[INFO] k8s:  - spring-boot
[INFO] k8s:  - wildfly-swarm
[INFO] k8s:  - thorntail-v2
[INFO] k8s:  - openliberty
[INFO] k8s:  - karaf
[INFO] k8s:  - vertx
[INFO] k8s:  - java-exec
[INFO] k8s:  - webapp
[INFO] k8s: [jkube-demo:1.0.0]: Created docker-build.tar in 60 milliseconds
[INFO] k8s: Step 1/3 : FROM openjdk:15-slim-buster
[INFO] k8s: 
[INFO] k8s: ---> 3311374531ea
[INFO] k8s: Step 2/3 : COPY target/*.jar application.jar
[INFO] k8s: 
[ERROR] k8s: Failed to execute the build [Error while trying to build the image]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.379 s
[INFO] Finished at: 2020-04-25T13:38:16-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.0.0-alpha-2:build (default-cli) on project jkube-demo: Failed to execute the build: Error while trying to build the image: Unable to build image [jkube-demo:1.0.0] : "COPY failed: no source files were specified" -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Based on your previous comment maybe this is an environmental issue but these poms are nearly identical.

manusa commented 4 years ago

Hi @zebu,

On Friday we published a quickstart showcasing how to use external Dockerfile for your build.

As of now, one of the required configurations, besides <dockerFile>, is contextDir.

Please, check if updating your affected pom.xml accordingly works.

https://github.com/eclipse/jkube/blob/358da963dcc3f16613833be48946b40b316ebf4c/quickstarts/maven/docker-file-provided/pom.xml#L62-L68

manusa commented 4 years ago

Anyway, we'll do a thorougher check of the current behavior, as it is redundant to specify both properties as they can be inferred from some defaults:

manusa commented 4 years ago

Relates to: https://github.com/fabric8io/fabric8-maven-plugin/issues/1097

manusa commented 4 years ago

HI @zebu,

I'm checking your demo project now with latest release 1.0.0-alpha-3.

Following what's stated in the documentation, your source directory should be changed to /maven unless specified otherwise.

The files of the assembly are stored in a build context relative directory maven/ but can be changed by changing the assembly name with the option in the assembly configuration.

So in order to make your project work you have 2 options:

A. Modify your Dockerfile and change directory from where COPY picks up the files to /maven and leave your pom.xml as it is:

FROM openjdk:15-slim-buster

COPY maven/*.jar application.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=st9","-jar","/application.jar"]

B. Modify your pom.xml and provide an <assembly> description and leave your Dockerfile as it is:

<images>
    <image>
        <name>%a:%l</name>
        <build>
            <dockerFile>${project.basedir}/Dockerfile</dockerFile>
            <assembly>
                <name>target</name>
                <dockerFileDir>${project.basedir}</dockerFileDir>
            </assembly>
        </build>
    </image>
</images>

I'm not sure why fabric8_pom.xml works.

Option A:

$ mvn k8s:build
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example.demo:jkube-demo >---------------------
[INFO] Building jkube-demo 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.0.0-alpha-3:build (default-cli) @ jkube-demo ---
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[INFO] k8s: Generators:
[INFO] k8s:  - quarkus
[INFO] k8s:  - spring-boot
[INFO] k8s:  - wildfly-swarm
[INFO] k8s:  - thorntail-v2
[INFO] k8s:  - openliberty
[INFO] k8s:  - karaf
[INFO] k8s:  - vertx
[INFO] k8s:  - java-exec
[INFO] k8s:  - webapp
[INFO] k8s: [jkube-demo:1.0.0]: Created docker-build.tar in 109 milliseconds
[INFO] k8s: Step 1/3 : FROM openjdk:15-slim-buster
[INFO] k8s: 
[INFO] k8s: ---> 5d5189be8bcd
[INFO] k8s: Step 2/3 : COPY maven/*.jar application.jar
[INFO] k8s: 
[INFO] k8s: ---> Using cache
[INFO] k8s: ---> 2951efc0aacd
[INFO] k8s: Step 3/3 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=st9","-jar","/application.jar"]
[INFO] k8s: 
[INFO] k8s: ---> Using cache
[INFO] k8s: ---> a28066a17562
[INFO] k8s: Successfully built a28066a17562
[INFO] k8s: Successfully tagged jkube-demo:1.0.0
[INFO] k8s: [jkube-demo:1.0.0]: Built image sha256:a2806
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.692 s
[INFO] Finished at: 2020-05-07T07:46:26+02:00
[INFO] ------------------------------------------------------------------------

Option B:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example.demo:jkube-demo >---------------------
[INFO] Building jkube-demo 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.0.0-alpha-3:build (default-cli) @ jkube-demo ---
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[INFO] k8s: Generators:
[INFO] k8s:  - quarkus
[INFO] k8s:  - spring-boot
[INFO] k8s:  - wildfly-swarm
[INFO] k8s:  - thorntail-v2
[INFO] k8s:  - openliberty
[INFO] k8s:  - karaf
[INFO] k8s:  - vertx
[INFO] k8s:  - java-exec
[INFO] k8s:  - webapp
[INFO] k8s: [jkube-demo:1.0.0]: Created docker-build.tar in 131 milliseconds
[INFO] k8s: Step 1/3 : FROM busybox
[INFO] k8s: 
[INFO] k8s: ---> be5888e67be6
[INFO] k8s: Step 2/3 : COPY target /maven/
[INFO] k8s: 
[INFO] k8s: ---> c7ad3f2358ea
[INFO] k8s: Step 3/3 : VOLUME ["/maven"]
[INFO] k8s: 
[INFO] k8s: ---> Running in 154fe42d88c6
[INFO] k8s: Removing intermediate container 154fe42d88c6
[INFO] k8s: ---> 55955848c4da
[INFO] k8s: Successfully built 55955848c4da
[INFO] k8s: Successfully tagged jkube-demo:1.0.0
[INFO] k8s: [jkube-demo:1.0.0]: Built image sha256:55955
[INFO] k8s: [jkube-demo:1.0.0]: Removed old image sha256:a2806
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.122 s
[INFO] Finished at: 2020-05-07T07:49:13+02:00
[INFO] ------------------------------------------------------------------------
zebu commented 4 years ago

thanks, this resolved the issue

yaakov-berkovitch commented 3 years ago

Im using the plugin version 1.1.0 and failed on the same. Also for me fabrik8 plugin works fine. If I add the assembly, i get the error:

[WARNING] k8s: Dockerfile /shared-folders/dev/ms-configuration/ms-configuration/src/main/docker/Dockerfile does not contain an ADD or COPY directive to include assembly created at target. Ignoring assembly.

Also, in this version dockerFileDir tag is not valid.

My Dockerfile looks like:

FROM asms/base-openjdk-openj9-11:latest
ARG JAR_FILE

# Copy the micro-service jar into the image
COPY --chown=afa /maven/${JAR_FILE} /jdk-minimal/application
# Explode the jar
RUN mkdir -p /jdk-minimal/application/exploded && cd /jdk-minimal/application/exploded \
    && jar xvf /jdk-minimal/application/*.jar \
    && cp -r /jdk-minimal/application/exploded/BOOT-INF/lib /jdk-minimal/application/ \
    && cp -r /jdk-minimal/application/exploded/META-INF /jdk-minimal/application/ \
    && cp -r /jdk-minimal/application/exploded/BOOT-INF/classes /jdk-minimal/application/ \
    && rm -rf /jdk-minimal/application/*jar /jdk-minimal/application/exploded

Any idea ?

rohanKanojia commented 3 years ago

@yaakov-berkovitch : Hi, Do you have a quick reproducer project which we can try out? I would like to see your assembly configuration XML.

yaakov-berkovitch commented 3 years ago

Thanks @rohanKanojia .

Attached an hello-world project that reproduces the issue. hello-world.zip

Following the output i got:

[root@k8s-node-1 hello-world]# mvn k8s:build
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-shade-plugin/3.2.4/maven-shade-plugin-3.2.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-shade-plugin/3.2.4/maven-shade-plugin-3.2.4.pom (11 KB at 8.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-shade-plugin/3.2.4/maven-shade-plugin-3.2.4.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-shade-plugin/3.2.4/maven-shade-plugin-3.2.4.jar (132 KB at 358.6 KB/sec)
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hello-world 0.1.0
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/joda-time/joda-time/2.9.2/joda-time-2.9.2.pom
Downloaded: https://repo.maven.apache.org/maven2/joda-time/joda-time/2.9.2/joda-time-2.9.2.pom (30 KB at 87.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/joda-time/joda-time/2.9.2/joda-time-2.9.2.jar
Downloaded: https://repo.maven.apache.org/maven2/joda-time/joda-time/2.9.2/joda-time-2.9.2.jar (611 KB at 917.3 KB/sec)
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.1.0:build (default-cli) @ hello-world ---
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[INFO] k8s: Generators:
[INFO] k8s:  - quarkus
[INFO] k8s:  - spring-boot
[INFO] k8s:  - wildfly-swarm
[INFO] k8s:  - thorntail-v2
[INFO] k8s:  - wildfly-jar
[INFO] k8s:  - openliberty
[INFO] k8s:  - karaf
[INFO] k8s:  - vertx
[INFO] k8s:  - micronaut
[INFO] k8s:  - java-exec
[INFO] k8s:  - webapp
[WARNING] k8s: Dockerfile /shared-folders/lab/java/jkube-test/hello-world/src/main/docker/Dockerfile does not contain an ADD or COPY directive to include assembly created at target. Ignoring assembly.
[INFO] k8s: [asms/hello-world:0.1.0]: Created docker-build.tar in 1 second 
[INFO] k8s: Step 1/7 : FROM alpine:latest
[INFO] k8s: 
[INFO] k8s: ---> e50c909a8df2
[INFO] k8s: Step 2/7 : ARG JAR_FILE
[INFO] k8s: 
[INFO] k8s: ---> Running in 95c194382335
[INFO] k8s: Removing intermediate container 95c194382335
[INFO] k8s: ---> 9a6453b1999d
[INFO] k8s: Step 3/7 : RUN mkdir /application
[INFO] k8s: 
[INFO] k8s: ---> Running in 4b982d0f221b
[INFO] k8s: Removing intermediate container 4b982d0f221b
[INFO] k8s: ---> 82ca855a52ca
[INFO] k8s: Step 4/7 : COPY --chown=afa /${JAR_FILE} /application
[INFO] k8s: 
[ERROR] k8s: Failed to execute the build [Error while trying to build the image: Unable to build image [asms/hello-world:0.1.0] : "COPY failed: file not found in build context or excluded by .dockerignore: stat target/hello-world.jar: file does not exist" ]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.195s
[INFO] Finished at: Wed Feb 03 21:06:06 IST 2021
[INFO] Final Memory: 21M/42M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.1.0:build (default-cli) on project hello-world: Failed to execute the build: Error while trying to build the image: Unable to build image [asms/hello-world:0.1.0] : "COPY failed: file not found in build context or excluded by .dockerignore: stat target/hello-world.jar: file does not exist" -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
rohanKanojia commented 3 years ago

Thanks a lot, let me try to try it out tomorrow morning.

rohanKanojia commented 3 years ago

@yaakov-berkovitch: Hi, I was somehow able to get this working with minor changed in pom and Dockerfile.

hello-world : $ mvn k8s:build
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.springframework:hello-world >-------------------
[INFO] Building hello-world 0.1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.1.0:build (default-cli) @ hello-world ---
[INFO] k8s: Running in Kubernetes mode
[INFO] k8s: Building Docker image in Kubernetes mode
[INFO] k8s: Generators:
[INFO] k8s:  - quarkus
[INFO] k8s:  - spring-boot
[INFO] k8s:  - wildfly-swarm
[INFO] k8s:  - thorntail-v2
[INFO] k8s:  - wildfly-jar
[INFO] k8s:  - openliberty
[INFO] k8s:  - karaf
[INFO] k8s:  - vertx
[INFO] k8s:  - micronaut
[INFO] k8s:  - java-exec
[INFO] k8s:  - webapp
[INFO] k8s: [asms/hello-world:0.1.0]: Created docker-build.tar in 340 milliseconds
[INFO] k8s: Step 1/8 : FROM alpine:latest
[INFO] k8s: 
[INFO] k8s: ---> e50c909a8df2
[INFO] k8s: Step 2/8 : ARG JAR_FILE
[INFO] k8s: 
[INFO] k8s: ---> Using cache
[INFO] k8s: ---> 211025a08082
[INFO] k8s: Step 3/8 : ARG ASSEMBLY_PATH
[INFO] k8s: 
[INFO] k8s: ---> Using cache
[INFO] k8s: ---> b486f776d5df
[INFO] k8s: Step 4/8 : RUN mkdir /application
[INFO] k8s: 
[INFO] k8s: ---> Using cache
[INFO] k8s: ---> a3d9a819aef1
[INFO] k8s: Step 5/8 : COPY /${JAR_FILE} /application
[INFO] k8s: 
[INFO] k8s: ---> 0251e3470d7b
[INFO] k8s: Step 6/8 : ADD /${ASSEMBLY_PATH}/target/classes/hello/HelloWorld.class HelloWorld.class
[INFO] k8s: 
[INFO] k8s: ---> ce9698e6e10e
[INFO] k8s: Step 7/8 : RUN apk --update add openjdk8-jre
[INFO] k8s: 
[INFO] k8s: ---> Running in b7230a57fcb7
[INFO] k8s: fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
[INFO] k8s: fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
[INFO] k8s: (1/47) Installing expat (2.2.10-r1)
[INFO] k8s: (2/47) Installing brotli-libs (1.0.9-r3)
[INFO] k8s: (3/47) Installing libbz2 (1.0.8-r1)
[INFO] k8s: (4/47) Installing libpng (1.6.37-r1)
[INFO] k8s: (5/47) Installing freetype (2.10.4-r1)
[INFO] k8s: (6/47) Installing libuuid (2.36.1-r1)
[INFO] k8s: (7/47) Installing fontconfig (2.13.1-r3)
[INFO] k8s: (8/47) Installing encodings (1.0.5-r0)
[INFO] k8s: (9/47) Installing libfontenc (1.1.4-r0)
[INFO] k8s: (10/47) Installing mkfontscale (1.2.1-r1)
[INFO] k8s: (11/47) Installing ttf-dejavu (2.37-r1)
[INFO] k8s: (12/47) Installing libxau (1.0.9-r0)
[INFO] k8s: (13/47) Installing libbsd (0.10.0-r0)
[INFO] k8s: (14/47) Installing libxdmcp (1.1.3-r0)
[INFO] k8s: (15/47) Installing libxcb (1.14-r1)
[INFO] k8s: (16/47) Installing libx11 (1.7.0-r0)
[INFO] k8s: (17/47) Installing libxcomposite (0.4.5-r0)
[INFO] k8s: (18/47) Installing libxext (1.3.4-r0)
[INFO] k8s: (19/47) Installing libxi (1.7.10-r0)
[INFO] k8s: (20/47) Installing libxrender (0.9.10-r3)
[INFO] k8s: (21/47) Installing libxtst (1.2.3-r3)
[INFO] k8s: (22/47) Installing alsa-lib (1.2.4-r2)
[INFO] k8s: (23/47) Installing libgcc (10.2.1_pre1-r3)
[INFO] k8s: (24/47) Installing giflib (5.2.1-r0)
[INFO] k8s: (25/47) Installing libjpeg-turbo (2.0.6-r0)
[INFO] k8s: (26/47) Installing libstdc++ (10.2.1_pre1-r3)
[INFO] k8s: (27/47) Installing openjdk8-jre-lib (8.272.10-r4)
[INFO] k8s: (28/47) Installing java-common (0.2-r0)
[INFO] k8s: (29/47) Installing libffi (3.3-r2)
[INFO] k8s: (30/47) Installing p11-kit (0.23.22-r0)
[INFO] k8s: (31/47) Installing libtasn1 (4.16.0-r1)
[INFO] k8s: (32/47) Installing p11-kit-trust (0.23.22-r0)
[INFO] k8s: (33/47) Installing ca-certificates (20191127-r5)
[INFO] k8s: (34/47) Installing java-cacerts (1.0-r1)
[INFO] k8s: (35/47) Installing nspr (4.29-r0)
[INFO] k8s: (36/47) Installing sqlite-libs (3.34.1-r0)
[INFO] k8s: (37/47) Installing nss (3.60.1-r0)
[INFO] k8s: (38/47) Installing krb5-conf (1.0-r2)
[INFO] k8s: (39/47) Installing libcom_err (1.45.7-r0)
[INFO] k8s: (40/47) Installing keyutils-libs (1.6.3-r0)
[INFO] k8s: (41/47) Installing libverto (0.3.1-r1)
[INFO] k8s: (42/47) Installing krb5-libs (1.18.3-r1)
[INFO] k8s: (43/47) Installing lcms2 (2.11-r0)
[INFO] k8s: (44/47) Installing pcsc-lite-libs (1.9.0-r0)
[INFO] k8s: (45/47) Installing liblksctp (1.0.18-r1)
[INFO] k8s: (46/47) Installing openjdk8-jre-base (8.272.10-r4)
[INFO] k8s: (47/47) Installing openjdk8-jre (8.272.10-r4)
[INFO] k8s: Executing busybox-1.32.1-r2.trigger
[INFO] k8s: Executing fontconfig-2.13.1-r3.trigger
[INFO] k8s: Executing mkfontscale-1.2.1-r1.trigger
[INFO] k8s: Executing java-common-0.2-r0.trigger
[INFO] k8s: Executing ca-certificates-20191127-r5.trigger
[INFO] k8s: OK: 106 MiB in 61 packages
[INFO] k8s: Removing intermediate container b7230a57fcb7
[INFO] k8s: ---> f51ab6448fbd
[INFO] k8s: Step 8/8 : ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/application/hello-world-0.1.0.jar"]                                                                                           
[INFO] k8s: 
[INFO] k8s: ---> Running in 96c9add832fd
[INFO] k8s: Removing intermediate container 96c9add832fd
[INFO] k8s: ---> 6c309f5b9140
[INFO] k8s: Successfully built 6c309f5b9140
[INFO] k8s: Successfully tagged asms/hello-world:0.1.0
[INFO] k8s: [asms/hello-world:0.1.0]: Built image sha256:6c309
[INFO] k8s: [asms/hello-world:0.1.0]: Removed old image sha256:65845
[INFO] k8s: [asms/hello-world:0.1.0]: Tag with 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  47.442 s
[INFO] Finished at: 2021-02-04T16:23:09+05:30
[INFO] ------------------------------------------------------------------------
hello-world : $ docker run 6c309
The current local time is: 10:54:51.228

You can find my version of your project here: https://github.com/r0haaaan/jkube-dockerfile-assembly . Could you please check it's what you're expecting?

yaakov-berkovitch commented 3 years ago

Thanks so much - Will try and update. @rohanKanojia - Great job . It works like a charm. Thanks for your time, I'm very appreciate.