i want to setup a pipeline in Gitlab CI for an Angular application.
This is my gitlab-ci.yml file:
variables:
CLI_VERSION: 9.1.4
stages:
- install_dependencies
- build
- test
- build-image-frontend
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- ./frontend/node_modules
- ./frontend/.npm
buildFrontend:
stage: build
image: trion/ng-cli
before_script:
- cd frontend
- npm ci --cache .npm --prefer-offline
script:
- ng build --prod
- mv ./dist ${CI_PROJECT_DIR}
- echo "after build structure in frontend folder:"
- ls
artifacts:
expire_in: 1 day
paths:
- ./dist
tags:
- docker
build-image-frontend:
stage: build-image-frontend
image: docker
services:
- docker:19.03.12-dind
before_script:
- echo "folder before cd:"
- ls
- cd frontend
script:
- docker build -t frontendproduction -f Dockerfile.ci .
- docker push frontendproduction
tags:
- docker
In the stage "build frontend" i build the application and create an artifact in the ./dist folder. This is the folder i want to use for my docker build in the stage "build-image-frontend". The dockerfile "Dockerfile.ci" i use in this stage is the following:
FROM nginx:1.14.1-alpine
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
RUN rm -rf /usr/share/nginx/html/*
COPY ./dist /usr/share/nginx/html
The issue i am facing occurs in the last line of the docker file where i want to copy the previously created ./dist folder. I am getting following error:
Step 4/4 : COPY ./dist /usr/share/nginx/html
COPY failed: stat /var/lib/docker/tmp/docker-builder820618559/dist: no such file or directory
So i guess in the execution of the build docker looks for the dist folder within the container but acutally the dist folder is located in the ${CI_PROJECT_DIR} directory.
Here is the output of the ls before the build(before_script in the buildFrontend stage):
folder before cd:
$ ls
README.md
backend
dist
docker-compose.yml
frontend
package-lock.json
How can i copy the dist folder that was generated and stored as artifact in the buildFrontend stage?