我正在尝试为使用node和mongodb构建的typescript API添加一些持续部署。
我想通过我已经拥有的gitlab实例这样做:
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]
所以我的部署工作如下:
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 [无论]工作正常服务器端,这让我感到惊讶。
&&
正在绊倒你。您应引用整个远程命令。
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"