在gitlab作业中使用SSH重新启动docker-container

时间:2018-09-18 19:14:31

标签: docker ssh gitlab

我正在尝试为使用node和mongodb构建的打字稿API添加一些连续部署。

我想通过已经拥有的gitlab实例来这样做:

Runner配置(/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]

所以我的部署工作如下:

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

问题: 这项工作在/bin/sh: eval: line 91: docker-compose: not found上失败,这使我感到惊讶,因为当我通过ssh登录服务器时,运行docker-compose [whatever]只能在服务器端正常工作。

1 个答案:

答案 0 :(得分:0)

<div>使您绊倒。您应该引用整个远程命令。

&&