Issue
I'm trying to build and deploy my angular project with gitlab pipelines. There are two jobs. One for building the angular app and one for the deployment. My gitlab-ci.yml
looks like this.
image: node:latest
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
before_script:
- npm install > /dev/null
stages:
- build
- deploy
build:
stage: build
artifacts:
paths:
- dist/
expire_in: 1 week
script:
- npm run build --prod
deploy:
stage: deploy
dependencies:
- build
environment: production
image: mjsarfatti/gitlab-ci-pipeline-php-aws:latest
before_script:
- mkdir ~/.aws/
- touch ~/.aws/credentials
- printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" >> ~/.aws/credentials
script:
- git checkout master
- eb deploy my_project
only:
- master
The aws cli used in the deploy job builds the dockerfile located in my project root. My problem is that every time when I run the deploy job I get this error:
Step 3/7 : COPY dist/src /usr/share/nginx/html
44 COPY failed: stat /var/lib/docker/tmp/docker-builder648218383/dist/src: no such file or directory.
It seems like that the artifact from the previous build job is missing. What is wrong with my gitlab-ci.yaml
file?
Solution
When artifacts are extracted into other pipeline steps, it's extracted in a different location that your code that's pulled down via git. For me, I've seen the artifact(s) put in the parent directory from where my code is. So for example if I have this directory structure:
--- gitlab_ci_root
--- my_code
The extracted artifacts will be put under gitlab_ci_root
, not my_code
.
You can test this by putting a couple of ls
's into your deploy
step.
deploy:
stage: deploy
dependencies:
- build
environment: production
image: mjsarfatti/gitlab-ci-pipeline-php-aws:latest
before_script:
- ls # directory list of current directory, likely your code
- ls ../ # directory list of the parent directory.
- mkdir ~/.aws/
- touch ~/.aws/credentials
- printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" >> ~/.aws/credentials
script:
- git checkout master
- eb deploy my_project
only:
- master
Once you find where the dist/
directory is being extracted, then in your script you can mv the dist to wherever you need it to be.
Answered By - Adam Marshall
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.