I have a Node.js application that I want to containerize in Gitlab CI/CD.
This app includes a git submodule containing its Angular front-end.
Before proceeding with the "docker-build" job, the front-end must be generated.
My idea was to add a dedicated stage in my .gitlab-ci.yml
file that will generate the front-end in a cached "fe" directory:
stages:
- front-end
- build
- test
- package-build
front-end:
stage: front-end
image: "registry.hub.docker.com/trion/ng-cli-karma:latest"
script:
- npm run fe-install
- npm run fe-build
cache:
paths:
- fe
But, how to get this cached "fe" directory in subsequent "docker-build" job so that Dockerfile can copy the front-end into the container?
2
Answers
I consider you can use the artifacts keyword in your
.gitlab-ci.yml
. This way you can get the cachedfe
directory in subsequentdocker-build
job.Updated file:
GitLab CI/CD’s
cache
feature allows you to save dependencies and artifacts between jobs.Here’s an example of how you can modify your
.gitlab-ci.yml
file:In your Dockerfile, you can use the
COPY
command to copy the cached front-end directory into the container.With this configuration, the front-end will be generated in the
front-end
job and cached. Then, in thedocker-build
job, you can use the cached front-end directory in your Dockerfile. This ensures that your front-end is included in the Docker image.