1

New version of kubernetes is without docker so we can not use Jenkins docker in docker with docker plugin:

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.2.0</version>
    <configuration>
        <imageName>${docker.image.name}</imageName>
        <imageTags>
            <imageTag>${project.version}</imageTag>
            <imageTag>latest</imageTag>
        </imageTags>
        <dockerDirectory>${basedir}/target/dockerfile</dockerDirectory>
        <resources>
            <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

with dockerfile:

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

What is the correct way to build image of spring boot application using kaniko ?

I know that kaniko support couple of context but I am not sure what is the best with spring boot application. Using git you still need to build all dependencies and then main application, using local dir/tar you can use same dockerfile but still you need to somehow copy archive to mounted volume in kaniko

I tried this kaniko pod which successfully push image to registry

apiVersion: v1
kind: Pod
metadata:
  name: kaniko
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:latest
    args: ["--dockerfile=/Dockerfile",
            "--context=dir:///workspace",
            "--destination=registry/image:version",
            "--skip-tls-verify"] 
    volumeMounts:
      - name: data
        mountPath: /workspace       
  restartPolicy: Never
  volumes:
    - name: data
      hostPath:
        path: /workspace/
        type: Directory

but before this I need to manually copy Dockerfile and jar to mounted volume. Is there some better way how I can use kaniko ?

hudi
  • 15,555
  • 47
  • 142
  • 246

0 Answers0