I have a CI/CD pipeline which is running perfectly, apart from the final deploy stage. When getting a shell in my deployment server and trying to run “docker stack deploy -c deploy-stack.yml reactclient” I am getting “No File Found” for deploy-stack.yml which causes the deployment to fail.
Prior to running this command I am running “ls” which prints out a list of files inside my container, one of which is deploy-stack.yml. However when running this next command deploy-stack.yml is not found?!
This is the deploy stage in my .gitlab-ci.yml which is failing:
deploy:
stage: deploy
services:
- docker:dind
tags:
- runner
only:
- master
when: manual
environment:
name: production
url: https://app.mydeployserver.com
before_script:
- mkdir -p ~/.ssh
- echo "$DEPLOY_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -H $DEPLOYMENT_SERVER_IP >> ~/.ssh/known_hosts
script:
- echo "Start deploy to production server"
- ssh root@$DEPLOYMENT_SERVER_IP "
echo $DEPLOYMENT_SERVER_IP;
echo $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY;
docker pull $IMAGE_TAG;
echo "Where am I? - $PWD";
echo "What files are in here? - $(ls)";
docker stack deploy -c deploy-stack.yml reactclient"
- echo "End deploy to production server"
As you can see right before docker stacker deploy, I am running echo "What files are in here? - $(ls)
which literally prints out deploy-stack.yml
Yet the job fails due to “No File Found”, here is the output from GitLab:
Status: Downloaded newer image for registry.gitlab.com/myusername/myimage:latest
Where am I? - /builds/myusername/myimage
What files are in here? - Dockerfile __mocks__ appspec.yml build config deploy-stack.yml jest.config.js local.Dockerfile nginx package-lock.json package.json scripts server src webpack.dev.js webpack.prod.config.js webpack.prod.js
open deploy-stack.yml: no such file or directory
ERROR: Job failed: exit code 1
Where am I going wrong? Is this something to do with the command being run by some other docker daemon? This gets really confusing with gitlab + docker vs dind + ssh to another server.
Any pointers much appreciated.