.gitlab-ci.yml
workflow:
rules:
- if: $CI_COMMIT_BRANCH != "main" && $CI_PIPELINE_SOURCE != "merge_request_event"
when: never
- when: always
variables:
IMAGE_NAME: $CI_REGISTRY_IMAGE
stages:
- test
- build
run_unit_tests:
image: node:16-alpine3.17
stage: test
tags:
- txy
before_script:
- cd app
- npm install
script:
- npm test
artifacts:
when: always
paths:
- app/junit.xml
reports:
junit: app/junit.xml
build_image:
stage: build
tags:
- remoteone
before_script:
- echo "Docker registry url is $CI_REGISTRY"
- echo "Docker registry username is $CI_REGISTRY_USER"
- echo "Docker registry repo is $CI_REGISTRY_IMAGE"
script:
- docker build -t $IMAGE_NAME .
push_image:
stage: build
needs:
- build_image
tags:
- remoteone
before_script:
- echo "Docker registry url is $CI_REGISTRY"
- echo "Docker registry username is $CI_REGISTRY_USER"
- echo "Docker registry repo is $CI_REGISTRY_IMAGE"
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker push $IMAGE_NAME
correspondence of the above variables
$CI_REGISTRY_IMAGE = docker build -t registry.gitlab.com/komorebi-cqd/mynodeapp-cicd-project .
$CI_REGISTRY = docker push registry.gitlab.com/komorebi-cqd/mynodeapp-cicd-project
Dockerfile
FROM node:16-alpine
RUN apk add docker-cli
WORKDIR /usr/src/app
COPY ./app/package*.json ./
RUN npm install
COPY ./app .
EXPOSE 3000
CMD [ "npm" ,"start"]
cicd pipelines build_image error
Running with gitlab-runner 15.5.1 (7178588d)
on one-docker-runner fAyvKeBR
Preparing the "docker" executor
00:03
Using Docker executor with image alpine:3.14 ...
Pulling docker image alpine:3.14 ...
Using docker image sha256:dd53f409bf0bd55eac632f9e694fd190244fef5854a428bf3ae1e2b636577623 for alpine:3.14 with digest alpine@sha256:4c869a63e1b7c0722fed1e402a6466610327c3b83bdddb94bd94fb71da7f638a ...
Preparing environment
00:01
Running on runner-fayvkebr-project-41046722-concurrent-0 via VM-20-2-ubuntu...
Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /builds/komorebi-cqd/mynodeapp-cicd-project/.git/
Checking out 023ee3af as main...
Removing app/junit.xml
Skipping Git submodules setup
Downloading artifacts
00:03
Downloading artifacts for run_unit_tests (3502740847)...
Downloading artifacts from coordinator... ok id=3502740847 responseStatus=200 OK token=64_pVtH2
Executing "step_script" stage of the job script
00:01
Using docker image sha256:dd53f409bf0bd55eac632f9e694fd190244fef5854a428bf3ae1e2b636577623 for alpine:3.14 with digest alpine@sha256:4c869a63e1b7c0722fed1e402a6466610327c3b83bdddb94bd94fb71da7f638a ...
$ echo "Docker registry url is $CI_REGISTRY"
Docker registry url is registry.gitlab.com
$ echo "Docker registry username is $CI_REGISTRY_USER"
Docker registry username is gitlab-ci-token
$ echo "Docker registry repo is $CI_REGISTRY_IMAGE"
Docker registry repo is registry.gitlab.com/komorebi-cqd/mynodeapp-cicd-project
$ docker build -t $IMAGE_NAME .
/bin/sh: eval: line 137: docker: not found
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 127
It prompts docker: not found,i have been searching the Internet for a long time, but there is no specific solution
I have a Docker installed on my server, and there is no problem running Docker PS. However, when I use the gitlab registry, I will be prompted that the Docker does not exist. I do not know where the problem is, and there is no corresponding solution online. I hope someone can tell me why the Docker is not found and how to solve it.