1

I am trying to add some continuous deployment for a typescript API built with node, and mongodb.

I would like to do so via the gitlab instance that I already have :

Runner config (/etc/gitlab-runner/config.toml) :

[[runners]]
  name = "runner"
  url = "https://git.[DOMAIN].[EXT]"
  token = "[ID]"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "mhart/alpine-node:6.5"
    privileged = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]

So my deploy job looks as follow :

Deployment_preprod:
  stage: Deploy
  before_script:
    # https://docs.gitlab.com/ee/ci/ssh_keys/
    - 'which ssh-agent || ( apk add --no-cache --virtual openssh-client )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - chmod 700 ~/.ssh
  script:
    - scp -r dist  user@[IP]:/home/[user]/preprod-back
    - ssh -tt user@[IP] cd /home/[user]/preprod-back && yarn run doc && docker-compose restart
  environment:
    name: preprod
    url: https://preprod.api.[DOMAIN].[EXT]
  only:
    - develop

Question : this job fail on /bin/sh: eval: line 91: docker-compose: not found which suprise me since running docker-compose [whatever] just works fine server-side when I log in the server via ssh.

2
  • ssh ... && docker-compose ... makes an outbound ssh connection and waits for it to finish; then after it’s done it tries to run docker-compose locally. Commented Sep 18, 2018 at 19:33
  • Would using a bash script solves this issue ? I guess not but sooner or later I will have to rebuild the image in order to have the nodes_modules up to date, so running docker/docker-compose commands on the server-side would seems very usefull for me. I might have started on a wrong process though Commented Sep 18, 2018 at 19:47

1 Answer 1

1

The && are tripping you up. You should quote the entire remote command.

script:
  - scp -r dist  user@[IP]:/home/[user]/preprod-back
  - ssh -tt user@[IP] "cd /home/[user]/preprod-back && yarn run doc && docker-compose restart"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.