Building a Spring Native application on my Docker Image - spring

I am building my spring boot native application on an alpine (openjdk:13-alpine) docker image.
./mvnw spring-boot:build-image -DskipTests
When doing this I got an error :
[INFO] Building image 'docker.io/library/bff-distributor:0.0.1-SNAPSHOT'
[INFO]
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' 100%
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:54 min
[INFO] Finished at: 2021-04-16T15:26:34Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image (default-cli) on project bff-distributor: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image failed: Connection to the Docker daemon at 'localhost' failed with error "[2] No such file or directory"; ensure the Docker daemon is running and accessible: com.sun.jna.LastErrorException: [2] No such file or directory -> [Help 1]
My gitlab.ci configuration
build:
image: openjdk:13-alpine
stage: build
script:
- chmod 755 ./mvnw
- ./mvnw spring-boot:build-image -DskipTests
For information : I need it to be running on a docker image as the building it's part of my gitlab ci/cd stage.

As the link provided Scott says, you should use Docker in Docker to do what you want.
So, replace the openjdk image by the docker image (https://hub.docker.com/_/docker) and activate the dind service.
As you need Java for the Maven execution, you can simply install jdk in the "before_script" section.
Here is my gitlab-ci script for the same kind of project :
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
image: docker:20.10.8-dind-alpine3.13
services:
- docker:20.10.8-dind
stage: build_push
before_script:
- apk add --update openjdk11
script:
- chmod 755 ./mvnw
- ./mvnw spring-boot:build-image

Related

create spring boot 2.7 'mvn spring-boot:build-image' with podman on macOS failed

I try to create an image with mvn spring-boot:build-image using podman but got
[INFO] --- spring-boot-maven-plugin:2.7.0:build-image (default-cli) # sample-spring-service ---
[INFO] Building image 'docker.io/library/sample-spring-service:1.0.0-SNAPSHOT'
[INFO]
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
[INFO] > Pulled builder image 'docker.io/paketobuildpacks/builder#sha256:94e65320ba1682bc68cbbf1d4f63693bb62cc06c7077bfa3e3bccac7fdc10628'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 100%
[INFO] > Pulled run image 'docker.io/paketobuildpacks/run#sha256:3e889016680c0e2ef1e8b1bfdad2d6d34966c860a53ccfcfb3e269d48ed65fed'
[INFO] > Executing lifecycle version v0.14.1
[INFO] > Using build cache volume 'pack-cache-744ddec35876.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ERROR: initializing analyzer: getting previous image: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied
podman info:
host:
arch: amd64
buildahVersion: 1.26.1
cgroupControllers:
...
version:
APIVersion: 4.1.0
Built: 1651853754
BuiltTime: Fri May 6 18:15:54 2022
GitCommit: ""
GoVersion: go1.18
Os: linux
OsArch: linux/amd64
Version: 4.1.0
I already tried a lot. Set permissions on socket, run podman with root. The same with docker is working well.
podman create alpine ls works fine.
In my pom.xml I tried:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<!-- <host>unix:///Users/mike/.local/share/containers/podman/machine/podman-machine-default/podman.sock</host>
<host>unix:///run/user/1000/podman/podman.sock</host>
-->
<bindHostToBuilder>true</bindHostToBuilder>
</docker>
</configuration>
</plugin>
Any idea?
Update:
If I enable this line in pom.xml:
unix:///run/user/1000/podman/podman.sock
I get:
[INFO] --- spring-boot-maven-plugin:2.7.0:build-image (default-cli) # sample-spring-service ---
[INFO] Building image 'docker.io/library/sample-spring-service:1.0.0-SNAPSHOT'
[INFO]
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
For anyone who runs into a similar issue with spring boot build-image, for example when using remote docker hosts
From what I understand:
the pull is done using your docker parameters in pom.xml or environment variables like DOCKER_HOST
Once the pull has been completed, creator will start a new container and run the next commands in this newly container
The connection to docker in the new container might not work, as the DOCKER_HOST might need to be different for access to docker within a new container. Within the "creator" container, /var/run/docker.sock is automatically mounted from the host system.
If you enable bindHostToBuilder, it'll pass the DOCKER_HOST (or the parameter in pom.xml) to the new container, but that might not be the correct docker hostname that is accessible from within the new container.
For me the solution was to not use bindHostToBuilder, but ensure that /var/run/docker.sock exists on the host system so that it can be mapped within the "creator" container, even though the pull happens with a different DOCKER_HOST (a remote docker)

what is the cause of this openliberty docker error

Just following Product documentation instructions:
Please see Error log message.
Not sure what the error is and how to fix it.
mvn liberty:devc
[INFO] Scanning for projects...
[INFO]
[INFO] ------------< io.openliberty.guides:guide-getting-started >-------------
[INFO] Building guide-getting-started 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- liberty-maven-plugin:3.3.4:devc (default-cli) # guide-getting-started ---
[INFO] CWWKM2102I: Using artifact based assembly archive : io.openliberty:openliberty- kernel:null:21.0.0.3:zip.
[INFO] CWWKM2102I: Using installDirectory : /home/zahid/Liberty-eclipse/guide-getting-started/start/target/liberty/wlp.
[INFO] CWWKM2102I: Using serverName : defaultServer.
[INFO] CWWKM2102I: Using serverDirectory : /home/zahid/Liberty-eclipse/guide-getting-started/start/target/liberty/wlp/usr/servers/defaultServer.
[INFO] Running maven-compiler-plugin:compile
[INFO] Copying 1 file to /home/zahid/Liberty-eclipse/guide-getting-started/start/target/liberty/wlp/usr/servers/defaultServer
[INFO] CWWKM2144I: Update server configuration file server.xml from /home/zahid/Liberty-eclipse/guide-getting-started/start/src/main/liberty/config/server.xml.
[INFO] Building Docker image...
[INFO] docker build --pull -f /tmp/tempDockerfile17415566016391532686 -t guide-getting-started-dev-mode /home/zahid/Liberty-eclipse/guide-getting-started/start
[ERROR] unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /tmp/tempDockerfile17415566016391532686: no such file or directory
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.343 s
[INFO] Finished at: 2021-03-20T16:28:39Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.openliberty.tools:liberty-maven-plugin:3.3.4:devc (default-cli) on project guide-getting-started: Could not build Docker image using Dockerfile: /home/zahid/Liberty-eclipse/guide-getting-started/start/Dockerfile. Address the following docker build error and then start dev mode again: unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /tmp/tempDockerfile17415566016391532686: no such file or directory RC=1 -> [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
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat
Resolution: Remove the snappy version from Ubuntu 20.04
$ sudo snap remove docker
then install using these instructions
https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine
Problem: Snappy installation of docker was broken.

Skaffold dev works with minikube only. Other on-prem cluster fails

I have a Spring Boot app with jib-maven configured
POM
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.1.0</version>
<configuration>
<from>
<image>openjdk:11-jre-slim</image>
</from>
<to>
<image>registry.demo/${project.artifactId}</image>
<tags>
<tag>${project.version}</tag>
</tags>
<tags>
<tag>latest</tag>
</tags>
</to>
<container>
<jvmFlags>
<jvmFlag>-XX:+UseContainerSupport</jvmFlag>
<jvmFlag>-XX:MinRAMPercentage=60.0</jvmFlag>
<jvmFlag>-XX:MaxRAMPercentage=90.0</jvmFlag>
<jvmFlag> -XshowSettings:vm</jvmFlag>
</jvmFlags>
<mainClass>com.demo.DemoApplication</mainClass>
</container>
</configuration>
SKAFFOLD.YAML
apiVersion: skaffold/v2beta1
kind: Config
metadata:
name: springtokube
build:
artifacts:
- image: registry.demo/springtokube
jib:
project: com.demo:springtokube
local:
push: true
concurrency: 1
useBuildkit: false
useDockerCLI: true
deploy:
kubectl:
manifests:
- deployment.yaml
ALSO SET INSECURE REGISTRY
skaffold config set --global insecure-registries registry.demo
But when using minikube I can run successfully
skaffold dev
When using other cluster (ON-PREM) I get
FATA[0016] exiting dev mode because first build failed: build failed: building [registry.demo/springtokube]: build artifact: getting image: GET http://registry.demo/v2/: : Not Found
What might be the problem?
I restarted today using kubectl context
skaffold debug --no-prune=false --cache-artifacts=false
And It Failed
Listing files to watch...
Generating tags...
- registry.demo/springtokube -> registry.demo/springtokube:cf60c31
Found [minikube] context, using local docker daemon.
Building [registry.demo/springtokube]...
.............
...............
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.294 s - in com.demo.springtokube.SpringtokubeApplicationTests
2020-04-15 08:45:48.277 INFO 30662 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) # springtokube ---
[INFO] Building jar: ....../springtokube/target/springtokube.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.6.RELEASE:repackage (repackage) # springtokube ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- jib-maven-plugin:2.1.0:build (default-cli) # springtokube ---
[INFO]
[INFO] Containerizing application to registry.demo/springtokube:cf60c31, registry.demo/springtokube...
[WARNING] Base image 'openjdk:11-jre-slim' does not use a specific image digest - build may not be reproducible
[INFO] Getting manifest for base image openjdk:11-jre-slim...
[INFO] Building dependencies layer...
[INFO] Building resources layer...
[INFO] Building classes layer...
[INFO] Using credentials from Docker config (~/.docker/config.json) for registry.demo/springtokube:cf60c31
[WARNING] Cannot verify server at https://registry.demo/v2/. Attempting again with no TLS verification.
[WARNING] Cannot verify server at https://registry.demo/v2/springtokube/blobs/sha256:1fb3fb86aa52691fa3705554da5ba07dcb556f62a93ba7efab0e397ca3db092c. Attempting again with no TLS verification.
[WARNING] Cannot verify server at https://registry.demo/v2/springtokube/blobs/sha256:88a7d9887f9fdeb5a4736d07c64818453e00e71fe916b13f413eb6e545445a68. Attempting again with no TLS verification.
[WARNING] Cannot verify server at https://registry.demo/v2/springtokube/blobs/sha256:a6c851c4b90b9eb7af89d240dd4f438dba9feba5c78600fed7eadddf8cb7b647. Attempting again with no TLS verification.
[INFO] The base image requires auth. Trying again for openjdk:11-jre-slim...
[INFO] Using credentials from Docker config (~/.docker/config.json) for openjdk:11-jre-slim
[INFO] Using base image with digest: sha256:01669f539159a1b5dd69c4782be9cc7da0ac1f4ddc5e2c2d871ef1481efd693e
[INFO]
[INFO] Container entrypoint set to [java, -XX:+UseContainerSupport, -XX:MinRAMPercentage=60.0, -XX:MaxRAMPercentage=90.0, -XshowSettings:vm, -cp, /app/resources:/app/classes:/app/libs/*, com.demo.springtokube.SpringtokubeApplication]
[INFO]
[INFO] Built and pushed image as registry.demo/springtokube:cf60c31, registry.demo/springtokube
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.058 s
[INFO] Finished at: 2020-04-15T08:45:57+03:00
[INFO] ------------------------------------------------------------------------
Pruning images...
FATA[0024] exiting dev mode because first build failed: build failed: building [registry.demo/springtokube]: build artifact: getting image: GET http://registry.demo/v2/: : Not Found
I thought the minikube works. But disabling cache fails to build
if I run
skaffold debug OR skaffold dev
Works Fine
But if I run with cache disabled
skaffold debug --no-prune=false --cache-artifacts=false
FAILS it shows the logs above
After days of struggling I found a solution.
Following Brian de Alwis suggestions I was able to make Skaffold work with Self Signed Certificate.
Skaffold build or dev does not use certificate put in.
/etc/docker/certs.d/myregistrydomain.com/ca.crt
The path is used by docker client only.
The solution was to put yout registry certificate into
/usr/local/share/ca-certificates/myregistrydomain.com.crt
Then
update-ca-certificates
Check The link for more info
If you are using self signed certificate no need for insecure registry in your scaffold yaml file
apiVersion: skaffold/v2beta1
kind: Config
metadata:
name: springtokube
build:
# insecureRegistries:
# - myregistrydomain.com
Or Running skaffold with
skaffold dev --insecure-registry=myregistrydomain.com
Hope this help someone else struggling to make skaffold works with self signed certificate

GCloud permission error when deploying to Google app engine flexible

I am trying to deploy my spring boot app to app engine via Jenkins using Maven. After maven has built the package, I am using "mvn install appengine: deploy" in the execute shell in the Build step. However, I get the following error when it is built,
GCLOUD: ERROR: (gcloud.app.deploy) Permissions error fetching application [apps/microservice-qa]. Please make sure you are using the correct project ID and that you have permission to view applications on the project.
Detailed error trace:
[INFO] Detected App Engine flexible environment application.
Sep 12, 2017 7:54:14 AM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
INFO: submitting command: /usr/lib/google-cloud-sdk/bin/gcloud app deploy
[INFO] GCLOUD: Services to deploy:
[INFO] GCLOUD:
[INFO] GCLOUD: descriptor: [/opt/bitnami/apps/jenkins/jenkins_home/workspace/demo-test/target/appengine-staging/app.yaml]
[INFO] GCLOUD: source: [/opt/bitnami/apps/jenkins/jenkins_home/workspace/demo-test/target/appengine-staging]
[INFO] GCLOUD: target project: [xxxx]
[INFO] GCLOUD: target service: [xxxxx]
[INFO] GCLOUD: target version: [20170912t075415]
[INFO] GCLOUD: target url: [https://xxxxx-dot-microservice-qa.appspot.com]
[INFO] GCLOUD:
[INFO] GCLOUD:
[INFO] GCLOUD: If this is your first deployment, this may take a while...
[INFO] GCLOUD: ....done.
[INFO] GCLOUD:
[INFO] GCLOUD: Beginning deployment of service [another-pub-sub-service]...
[INFO] GCLOUD: Building and pushing image for service [another-pub-sub-service]
[INFO] GCLOUD: ERROR: (gcloud.app.deploy) You do not have permission to access project [xxxx] (or it may not exist): The caller does not have permission
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.198s
[INFO] Finished at: Tue Sep 12 07:54:27 UTC 2017
[INFO] Final Memory: 21M/51M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy (default-cli) on project demo-test1: Execution default-cli of goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy failed: Non zero exit: 1 -> [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/PluginExecutionException
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal com.google.cloud.tools:appengine-maven-plugin:1.3.1:deploy failed: Non zero exit: 1
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: com.google.cloud.tools.appengine.api.AppEngineException: Non zero exit: 1
at com.google.cloud.tools.appengine.cloudsdk.process.NonZeroExceptionExitListener.onExit(NonZeroExceptionExitListener.java:30)
at com.google.cloud.tools.appengine.cloudsdk.internal.process.DefaultProcessRunner.syncRun(DefaultProcessRunner.java:211)
at com.google.cloud.tools.appengine.cloudsdk.internal.process.DefaultProcessRunner.run(DefaultProcessRunner.java:137)
at com.google.cloud.tools.appengine.cloudsdk.CloudSdk.runGcloudCommand(CloudSdk.java:193)
at com.google.cloud.tools.appengine.cloudsdk.CloudSdk.runAppCommandInWorkingDirectory(CloudSdk.java:136)
at com.google.cloud.tools.appengine.cloudsdk.CloudSdkAppEngineDeployment.deploy(CloudSdkAppEngineDeployment.java:90)
at com.google.cloud.tools.maven.DeployMojo.execute(DeployMojo.java:107)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
... 20 more
I have checked the permissions in the server for the key/user used to run gcloud commands, they both have full rights. However I still get the above error.
Also, is there any other plugin in Jenkins or any other tool (like jenkins to manage builds and deploy to app engine) to do the same?
Any help would be greatly appreciated. Thanks.
Since your Jenkins Server might not be configured with your project, use following commands in your jenkins job configuration:
Execute shell:
#!/bin/sh
gcloud -q auth activate-service-account --key-file=${PROJECT_KEY.JSON}
gcloud -q config set project ${PROJECT_ID}
mvn appengine:deploy
Also, for 'gcloud' to be available on Jenkins server, you would have to install plugin 'Google Deployment Manager Jenkins Plugin' in Jenkins.

Jenkins maven build from stash issue

While running a maven build from Jenkins using stash/bitbucket repo i am getting error. This is first time set of this project in stash/bitbucket and jenkins job as well
21:00:30 [INFO] Executing: /bin/sh -c cd /home/jenkins/workspace/project/folder && git push https://stash.xxx.com/scm/repo/folder refs/heads/develop:refs/heads/develop
21:00:30 [INFO] Working directory: /home/jenkins/workspace/project/folder
21:00:30 [INFO] -------------------------------------------------------------
21:00:30 [INFO] BUILD FAILURE
21:00:30 [INFO] -------------------------------------------------------------
21:00:30 [INFO] Total time: 41.539 s
21:00:30 [INFO] Finished at: 2017-10-01T16:00:30-04:00
21:00:31 [INFO] Final Memory: 14M/179M
21:00:31 [INFO] -------------------------------------------------------------
21:00:31 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project ifaview: Unable to commit files
21:00:31 [ERROR] Provider message:
21:00:31 [ERROR] The git-push command failed.
21:00:31 [ERROR] Command output:
21:00:31 [ERROR] fatal: could not read Username for 'https://stash.xxxx.com': No such device or address
jenkins configuration #Source Code Management>Git>Repositories>
Repository URL=https://stash.xxx.com/scm/repo/folder.git
Credentials: jenkins_user/xxxxx
In stash repo settings for jenkins_user
Repository permission: read, write
Branch permission: Changes without a pull request except jenkins_user
Pull request : merge and squash
Any one came across this problem, tried many other options as well...though no luck yet.

Resources