Reputation: 492
Hi have Gitlab pipeline with multiple stages. I want to build a React project in a Nodejs container and then create another docker container with nginx on it for deployment on AWS.
Here is my gitlab-ci.yml file:
image:
name: node:14-alpine
cache:
key: '$CI_COMMIT_REF_SLUG'
paths:
- node_modules/
- .yarn
stages:
- install
- build
- deploy
job_install:
stage: install
script:
- echo 'yarn-offline-mirror ".yarn-cache/"' >> .yarnrc
- echo 'yarn-offline-mirror-pruning true' >> .yarnrc
- yarn install
cache:
key:
files:
- yarn.lock
paths:
- .yarn-cache/
tags:
- docker
job_build:
stage: build
cache:
key: '$CI_COMMIT_REF_SLUG'
paths:
- node_modules/
- .yarn
script:
- yarn build
artifacts:
paths:
- build
tags:
- docker
job_deploy:
stage: deploy
image: docker
services:
- docker:dind
cache:
key: "$CI_COMMIT_REF_SLUG"
script:
- apk update
- apk upgrade
- apk add bash
- chmod +x ./build-scripts/build_wrapper.sh
- ./build-scripts/build_wrapper.sh
artifacts:
paths:
- BUILDTAG.txt
- env.sh
- logs
when: always
resource_group: realizeui_deployment
tags:
- docker
Basically build_wrapper.sh file will exec docker build .
for a Dockerfile in the code repo.This Dockerfile will install nginx and other tools in it.
I want to pass artifacts: /build from stage:build to stage:deploy for using in nginx container.
I have tried finding solution in documentation with no luck. Thanks in advance.
Upvotes: 2
Views: 11299
Reputation: 492
So I found the solution. I just needed to add previous job as dependency in deploy. This makes gitlab download all the artifacts from the dependency job and make them available for deploy job.
Here is how the deploy job looks like:
job_deploy:
stage: deploy
image: docker
services:
- docker:dind
cache:
key: "$CI_COMMIT_REF_SLUG"
dependencies:
- job_build
script:
- apk update
- apk upgrade
- apk add bash
- chmod +x ./build-scripts/build_wrapper.sh
- ./build-scripts/build_wrapper.sh
artifacts:
paths:
- BUILDTAG.txt
- env.sh
- logs
when: always
resource_group: realizeui_deployment
tags:
- docker
Upvotes: 7