Springboot books docker

Spring boot project

libraryH2command

from IDE & git push

H2 DB, Command Line Runner, api Rest and ready to CD/CI web


Spring Boot app build with Jenkins via Github and deployed to dockerHub

  1. create Spring Boots projects

  2. commit && push to GitHub

  3. create .jar executable from Github with Jenkins pipeline

  4. create docker executable from Github with Jenkins pipeline

  5. run (local) and monitor

  6. push to dockerhub

Create project and push to github

Create project from init spring boot and push to github: libraryH2command project on github. Publish data via api Rest on http://localhost:8090/api/books

Build .jar and docker with Jenkinsfile pipeline

We may create a docker with Spring Boot very easy ... Here some examples of jenkinsfile.

First at all, let's create a Jenkins Job Pipeline.

Jenkins Pipeline (or simply "Pipeline") is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins.

A continuous delivery pipeline is an automated expression of your process for getting software from version control right through to your users and customers.

DockerHub credentials: logging in with your password grants your terminal complete access to your account.

For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/

jenkinsfile build example: #20 to #57

#20

Be careful: this jenkinsfile does NOT work!!!

We must debug the output file to find mistakes in our pipeline ...


#23

Here you can check the right file and the mistake corrected

Error from build 20 has been corrected

There is a error to check: push docker to dockerhub.

Credentials in Dashboard > Configuració de Jenkins > Credentials

#34 & #35

There is a error to check: push docker to dockerhub (credentials)

ERROR: Could not find credentials entry with ID 'albertprofe@gmail.com'

Finished: FAILURE


ERROR: Credentials 'dockerhubcredentials' is of type 'Username with password' where 'org.jenkinsci.plugins.plaincredentials.StringCredentials' was expected

Finished: FAILURE

#37

pushing docker to dockerhub

[Pipeline] withCredentials

Masking supported pattern matches of %PASSWORD%

[Pipeline] {

[Pipeline] bat

Warning: A secret was passed to "bat" using Groovy String interpolation, which is insecure.

Affected argument(s) used the following variable(s): [PASSWORD]

See https://jenkins.io/redirect/groovy-string-interpolation for details.

C:\ProgramData\Jenkins\.jenkins\workspace\test3>docker login -u USERNAME -p ****

WARNING! Using --password via the CLI is insecure. Use --password-stdin.

Error response from daemon: Get "https://registry-1.docker.io/v2/": unauthorized: incorrect username or password



#38

pushing docker to dockerhub

C:\ProgramData\Jenkins\.jenkins\workspace\test3>docker login -u USERNAME --password-stdin

Error: Cannot perform an interactive login from a non TTY device


#39

pushing docker to dockerhub


C:\ProgramData\Jenkins\.jenkins\workspace\test3>docker login -u $DOCKER_COMMON_CREDS_USR --password-stdin

Error: Cannot perform an interactive login from a non TTY device


#48

pushing docker to dockerhub


C:\ProgramData\Jenkins\.jenkins\workspace\test3>echo albertprofedev

albertprofedev

[Pipeline] bat


C:\ProgramData\Jenkins\.jenkins\workspace\test3>echo ****

****

[Pipeline] bat


C:\ProgramData\Jenkins\.jenkins\workspace\test3>docker login -u albertprofedev -p ****

WARNING! Using --password via the CLI is insecure. Use --password-stdin.

Login Succeeded


Logging in with your password grants your terminal complete access to your account.

For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/

[Pipeline] bat

#48 & #51

pushing docker to dockerhub

C:\ProgramData\Jenkins\.jenkins\workspace\test3>docker push albertprofe/libraryh2command

Using default tag: latest

The push refers to repository [docker.io/albertprofe/libraryh2command]

a40e7e511e48: Preparing

0aa20a85da26: Preparing

b61e498b0317: Preparing

63493a9ab2d4: Preparing

denied: requested access to the resource is denied


#57

pushing docker to dockerhub with credentials and access granted tagging properly


C:\ProgramData\Jenkins\.jenkins\workspace\test3>docker push albertprofedev/libraryh2command:latest

The push refers to repository [docker.io/albertprofedev/libraryh2command]

13d947742594: Preparing

0aa20a85da26: Preparing

b61e498b0317: Preparing

63493a9ab2d4: Preparing

63493a9ab2d4: Pushed

b61e498b0317: Pushed

13d947742594: Pushed

0aa20a85da26: Pushed

latest: digest: sha256:d37d639d4ed36a9bd775799f4709187d9dcc65a756697e64712f79bd52996867 size: 1163

...

[Pipeline] // withCredentials

[Pipeline] }

[Pipeline] // node

[Pipeline] End of Pipeline

Finished: SUCCESS

Build #57 (17 de nov. 2022, 12:35:01)

Jenkinsfile_57.groovy

Docker desktop, runnimg docker and monitoring ...

Dockerhub webhook

We can use webhooks to cause an action in another service in response to a push event in the repository. Webhooks are POST requests sent to a URL you define in Docker Hub.