I’m beginner and i’m start using GitlabCICD. I have docker-compose.yml in my project directory. I want to upload it to remote server with scp command so that I can deploy remote server using docker-compose up. I did ssh to remote server successfully. Here’s what i’ve got so far.
In gitlab-ci.yml, i have
image: docker:19
services:
- docker:dind
stages:
- build
- package
- deploy
cache:
paths:
- .m2/repository
variables:
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
maven-build:
image: maven:3-jdk-8
stage: build
script: "mvn package -B"
artifacts:
paths:
- target/*.jar
docker-build:
stage: package
script:
- docker version
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
deploy:
stage: deploy
variables:
GIT_STRATEGY: none
only:
- master
before_script:
- apk update && apk add openssh-client bash
script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- echo "$PATH_TO_PROJECT"
- mkdir -p ~/.ssh
- ssh-keyscan -H $SSH_SERVER_IP >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- scp -o StrictHostKeyChecking=no docker-compose.yml $SSH_USER@$SSH_SERVER_IP:${PATH_TO_PROJECT};
- ssh $SSH_USER@$SSH_SERVER_IP
"docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} &&
cd ${PATH_TO_PROJECT} && docker-compose down && docker pull ${CI_REGISTRY_IMAGE}:latest && docker-compose up -d && docker image prune -f"
The problem is that at line scp -o StrictHostKeyChecking=no docker-compose.yml $SSH_USER@$SSH_SERVER_IP:${PATH_TO_PROJECT};
, error happens with “docker-compose.yml no such file or directory” although i have docker-compose.yml in my project directory. I tried with echo "$PATH_TO_PROJECT" && cd $PATH_TO_PROJECT
but error happens with “can not cd to … no such file or directory”.
How can i solve this?