-
Notifications
You must be signed in to change notification settings - Fork 0
Jenkins pipeline
Omar Mokhtar edited this page Jun 15, 2023
·
3 revisions
Using the Jenkinsfile
the pipeline builds the app and creates a docker image and adds it to a docker hub.
The pipeline consists of 3 stages as follows.
at this stage, we build the app using the Dockerfile
and create a docker image that contains the latest version of our application.
The pipeline displays if any error happened during the build and reports that an error happened like the following example.
We login into the docker hub account using the saved credentials.
after a successful build, the new image will be pushed to omarmokhtar99/go-docker-app
.
Here's a full console of one successful run ..
Started by user [Omar Mokhtar](http://localhost:8080/user/omokhtar)
Obtained Jenkinsfile from git https://github.com/omarmoo5/GoDockerApp.git
[Pipeline] Start of Pipeline
[Pipeline] node
Running on [Jenkins](http://localhost:8080/computer/(built-in)/) in /Users/omarmokhtar/.jenkins/workspace/GoDockerApp-deployment
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
No credentials specified
> git rev-parse --resolve-git-dir /Users/omarmokhtar/.jenkins/workspace/GoDockerApp-deployment/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/omarmoo5/GoDockerApp.git # timeout=10
Fetching upstream changes from https://github.com/omarmoo5/GoDockerApp.git
> git --version # timeout=10
> git --version # 'git version 2.39.2 (Apple Git-143)'
> git fetch --tags --force --progress -- https://github.com/omarmoo5/GoDockerApp.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/main^{commit} # timeout=10
Checking out Revision b3011066d2ead41605a35564016fe92c171bcf05 (refs/remotes/origin/main)
> git config core.sparsecheckout # timeout=10
> git checkout -f b3011066d2ead41605a35564016fe92c171bcf05 # timeout=10
Commit message: "refactoring"
> git rev-list --no-walk b9414c51ddb1cd669dd8f274719004d0fc968029 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withCredentials
Masking supported pattern matches of $DOCKERHUB_CREDENTIALS or $DOCKERHUB_CREDENTIALS_PSW
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
+ docker build -t omarmokhtar99/go-docker-app:latest .
#2 [internal] load .dockerignore
#2 sha256:ec5031f9c417b7448dccc72daefbb6fb5563a71dd56fa6a982f55597dc6217e9
#2 transferring context: 2B 0.0s done
#2 DONE 0.0s
#1 [internal] load build definition from Dockerfile
#1 sha256:f28236451c2333fe8eada19d1ac2afdc6000a971fa43d50c4e0c615d967a8955
#1 transferring dockerfile: 664B 0.0s done
#1 DONE 0.0s
#4 [internal] load metadata for docker.io/library/golang:1.20-alpine
#4 sha256:a6f9cdc8389b02b82c4a29dd9bf0a1a7780872317e9a642f9c4ffbafee7d4b7f
#4 DONE 0.0s
#3 [internal] load metadata for docker.io/library/alpine:latest
#3 sha256:13549c58a76bcb5dac9d52bc368a8fb6b5cf7659f94e3fa6294917b85546978d
#3 DONE 0.0s
#7 [builder 1/6] FROM docker.io/library/golang:1.20-alpine
#7 sha256:9bece822ca2eb7e82c8860bce81558dbac35024ae1581dd5c69cbbeac5692810
#7 DONE 0.0s
#5 [stage-1 1/3] FROM docker.io/library/alpine:latest
#5 sha256:d20daa00e252bfb345a1b4f53b6bb332aafe702d8de5e583a76fcd09ba7ea1c1
#5 DONE 0.0s
#9 [internal] load build context
#9 sha256:fdd18ad5d74775206b75b4fccc9d41c0fc475e247fd5e2668b74dd6ab1de7111
#9 transferring context: 3.34kB done
#9 DONE 0.0s
#13 [builder 6/6] RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
#13 sha256:d6a5cba397b7186c41986a55c3c14a3468cfc669544b84e91e40f0eebec675bb
#13 CACHED
#11 [builder 4/6] RUN go mod download
#11 sha256:20e4831cd0f45508386b3710e46ebc6977dec74d5b3639cf24c23fb429f14e16
#11 CACHED
#10 [builder 3/6] COPY app/go.mod app/go.sum ./
#10 sha256:64b3c9e2ec372d7a0f916dd3db0721cdd7fcf9662968ed2f19c315a03c6e8173
#10 CACHED
#12 [builder 5/6] COPY app/*.go ./
#12 sha256:2f97483f580933638178016f164e8962947a4835e9a0eecd630678126a56f218
#12 CACHED
#6 [stage-1 2/3] WORKDIR /app
#6 sha256:bcbab5949deb7e4eee7ad30285ef7e80dcd86711263e0ae1e6a50635c2d7f23a
#6 CACHED
#8 [builder 2/6] WORKDIR /app
#8 sha256:6ccbd2e055d13369eb328fcaddf72332337ec0ac028f390e08a7955038286e75
#8 CACHED
#14 [stage-1 3/3] COPY --from=builder /app/app .
#14 sha256:e1c0800e455274f255f082d4f9e53e4e47b00d2a7e3a7d30b534be8bf3bde4d1
#14 CACHED
#15 exporting to image
#15 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#15 exporting layers done
#15 writing image sha256:3332823f3a22cac06523d853565df89dfe5ed6b8b9f6bf81a70d979b6699a2e4 done
#15 naming to docker.io/omarmokhtar99/go-docker-app:latest done
#15 DONE 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Login)
[Pipeline] sh
+ echo ****
+ docker login -u omarmokhtar99 --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] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Push)
[Pipeline] sh
+ docker push omarmokhtar99/go-docker-app
Using default tag: latest
The push refers to repository [docker.io/omarmokhtar99/go-docker-app]
57fc4a81b816: Preparing
b89e3d8bf0f8: Preparing
94dd7d531fa5: Preparing
b89e3d8bf0f8: Layer already exists
94dd7d531fa5: Layer already exists
57fc4a81b816: Layer already exists
latest: digest: sha256:3138ea9ceffcc21219550cf7de354210fc420413f2190bad319a926c969c6a74 size: 945
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] sh
+ docker logout
Removing login credentials for https://index.docker.io/v1/
[Pipeline] sh
+ docker rmi omarmokhtar99/go-docker-app:latest
Untagged: omarmokhtar99/go-docker-app:latest
Untagged: omarmokhtar99/go-docker-app@sha256:3138ea9ceffcc21219550cf7de354210fc420413f2190bad319a926c969c6a74
Deleted: sha256:3332823f3a22cac06523d853565df89dfe5ed6b8b9f6bf81a70d979b6699a2e4
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS