Hello,
I have two server:
GitLab (172.20.2.57) : GitLab Server
Runner (172.20.2.100) : GitLab Runner and Docker Compose
I created a NodeJS Express project using the Create from template option. I named this project test. The Dockerfile
of the project is as follows:
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
The .gitlab-ci.yml
of the project is as follows:
image: docker
services:
- docker:dind
stages:
- deploy
step-deploy-prod:
stage: deploy
script:
- docker build -t app/test .
- docker run -d -p 80:80 --rm --name todoapp app/test
To create a Runner, I went to Settings
and then to CI/CD
. Finally, the Runner settings are as follows:
And:
I ran the following command on the Runner server:
# gitlab-runner register --url http://172.20.2.57 --token glrt-x-ArBzXJcw3BsdYxKiX_
Output
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
I Clicked on Run Pipeline, but I got the following error:
Running with gitlab-runner 16.10.0 (81ab07f6)
on Runner GKbcoS1ku, system ID: s_a88f5fe318c9
Preparing the "shell" executor
00:00
Using Shell (bash) executor...
Preparing environment
00:01
Running on Runner...
Getting source from Git repository
00:00
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /home/gitlab-runner/builds/GKbcoS1ku/0/hack3rcon/test/.git/
Checking out 2eda86c8 as detached HEAD (ref is master)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
$ docker build -t /usr/src/app/test .
ERROR: invalid tag "/usr/src/app/test": invalid reference format
ERROR: Job failed: exit status 1
What is wrong?
Thanks you.
That command is wrong. You should be providing a name for your Docker container image and a tag, eg:
docker build -t myapp:latest .
or replace latest with a version number:
docker build -t myapp:1.1 .
A google search for how to build a docker image from dockerfile: docker how to build an image from dockerfile - Google Search
1 Like
Hi,
Thank you so much for your reply.
I modified the Dockerfile
as follows:
FROM node:latest as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:latest as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
And modified the .gitlab-ci.ym
as follows:
image: docker
services:
- docker:dind
stages:
- deploy
step-deploy-prod:
stage: deploy
script:
- docker build -t nginx:latest .
- docker run -d -p 80:80 --rm --name todoapp nginx:latest
I got the following error:
$ docker build -t nginx:latest .
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 307B done
#1 DONE 0.0s
#2 [internal] load metadata for docker.io/library/nginx:latest
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/node:latest
#3 DONE 0.0s
#4 [internal] load .dockerignore
#4 transferring context: 2B done
#4 DONE 0.0s
#5 [build-stage 1/6] FROM docker.io/library/node:latest
#5 DONE 0.0s
#6 [production-stage 1/2] FROM docker.io/library/nginx:latest
#6 CACHED
#7 [internal] load build context
#7 transferring context: 8.33kB 0.0s done
#7 DONE 0.0s
#8 [build-stage 3/6] COPY package*.json ./
#8 CACHED
#9 [build-stage 2/6] WORKDIR /app
#9 CACHED
#10 [build-stage 4/6] RUN npm install
#10 CACHED
#11 [build-stage 5/6] COPY . .
#11 DONE 0.1s
#12 [build-stage 6/6] RUN npm run build
#12 1.017 npm ERR! Missing script: "build"
#12 1.017 npm ERR!
#12 1.018 npm ERR! To see a list of scripts, run:
#12 1.018 npm ERR! npm run
#12 1.023
#12 1.023 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-04-14T13_42_06_780Z-debug-0.log
#12 ERROR: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1
------
> [build-stage 6/6] RUN npm run build:
ERR! Missing script: "build"
1.017 npm ERR!
1.018 npm ERR! To see a list of scripts, run:
1.018 npm ERR! npm run
1.023
1.023 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-04-14T13_42_06_780Z-debug-0.log
------
Dockerfile:6
--------------------
4 | RUN npm install
5 | COPY . .
6 | >>> RUN npm run build
7 |
8 | # production stage
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1
ERROR: Job failed: exit status 1
That’s an npm error. I suggest using google or your favourite search engine to find out what the problem is and how to fix it.
This forum is for Gitlab and Gitlab only. This is a docker build problem related with your npm app. If this is an app you have downloaded, ask the people who provide and support that application for assistance.
1 Like