pipeline ci/cd for pushing a docker image to docker hub

70 Views Asked by At

i'm trying to create a pipeline ci/cd gitlab for a spring boot project to Build a Docker Image and Push to Docker Hub so i have 3 stages: build , build docker-image and push docker-image every time i pass the 2 first stage : build , build docker-image but the third stage no and i have this error: "$ docker push rajvis962/demo:latest An image does not exist locally with the tag: rajvis962/demo The push refers to repository [docker.io/rajvis962/demo] Cleaning up project directory and file based variables 00:00 ERROR: Job failed: exit code 1"

the output of build docker-image is:

#6 DONE 5.5s
#4 [2/2] COPY target/*.jar /
#4 DONE 4.2s
#7 exporting to image
#7 exporting layers 0.1s done
#7 writing image sha256:a6845b953aa0804e14d7ec86bf7d5ae6d0a735c89adb84881ecc2e7b2e2261bc done
#7 naming to docker.io/rajvis962/demo:latest done
#7 DONE 0.1s
Cleaning up project directory and file based variables
00:00
Job succeeded 

the output of the first stage is :

 [INFO] The original artifact has been renamed to /builds/krim_/pipeline-cicd-springboot-project/target/demo-0.0.1-SNAPSHOT.jar.original
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18.096 s
[INFO] Finished at: 2024-02-15T02:34:00Z
[INFO] ------------------------------------------------------------------------
Uploading artifacts for successful job
00:04
Uploading artifacts...
target/: found 36 matching artifact files and directories 
WARNING: Upload request redirected                  location=https://gitlab.com/api/v4/jobs/6176432077/artifacts?artifact_format=zip&artifact_type=archive new-url=https://gitlab.com
WARNING: Retrying...                                context=artifacts-uploader error=request redirected
Uploading artifacts as "archive" to coordinator... 201 Created  id=6176432077 responseStatus=201 Created token=glcbt-65
Cleaning up project directory and file based variables
00:01
Job succeeded

i have an account in docker hub named "rajvis962" and repository "helloworld" when i execute this command : docker images i just get this:

REPOSITORY TAG IMAGE ID CREATED SIZE docker/welcome-to-docker latest c1f619b6477e 3 months ago 18.6MB

my .gitlab-ci.yml file is:

image: maven:latest
stages:
  - build
  - build-docker-image
  - push-image-to-docker-hub

build-java-project:
  stage: build
  script:
    - "mvn package"
  artifacts:
    paths:
      - target/

build-docker-image:
  stage: build-docker-image
  script:
    - docker info
    - ls -l target/
    - docker build -t rajvis962/demo:latest  .
  image: docker:stable
  services:
    - docker:dind
Push Docker Image to DockerHub:
  stage: push-image-to-docker-hub
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
  script:
    - docker info
    - docker push rajvis962/demo:latest
  image: docker:stable
  services:
    - docker:dind

my dockerfile is:

FROM openjdk
COPY target/*.jar /
EXPOSE 8080
ENTRYPOINT ["java","-jar","/*.jar"]

An image does not exist locally with the tag while pushing image to local registry: how can i solve it i spent many time in search but with no solution

0

There are 0 best solutions below