machine:
services:
- docker
dependencies:
override:
- docker info
- docker build -t pgeiss/appname .
test:
override:
- docker run -d -p 8080:8080 pgeiss/appname; sleep 10
- curl --retry 10 --retry-delay 5 -v http://localhost:8080/res.json
#1 楼
为了使其正常工作,需要发生一些事情。首先,将一个deployment
部分添加到circle.yml:deployment:
main: # or whatever your deployment is called
branch: master # or whatever branch you want to deploy
commands:
- docker login -e (your email here) -u (your username here) -p (your password here)
- docker push pgeiss/appname
- ./start.sh
感谢此博客文章提供以下脚本。然后,在存储库的顶层创建一个名为start.sh的文件(如果使用其他名称,请更改circle.yml的最后一行),该文件包含以下内容:
#!/usr/bin/env bash
echo "stopping running application"
ssh $DEPLOY_USER@$DEPLOY_HOST 'docker stop dodsv'
ssh $DEPLOY_USER@$DEPLOY_HOST 'docker rm dodsv'
echo "pulling latest version of the code"
ssh $DEPLOY_USER@$DEPLOY_HOST 'docker pull pgeiss/appname-webapp:latest'
echo "starting the new version"
ssh $DEPLOY_USER@$DEPLOY_HOST 'docker run -d --restart=always --name dodsv -p 80:5432 pgeiss/appname:latest'
echo "success!"
exit 0
最后,要使脚本能够工作,您需要将脚本设置为可与
chmod
一起执行,并将环境变量和DEPLOY_USER
的ssh密钥(最好)或凭据(如果没有ssh密钥)添加到CircleCI 。这样做之后,CircleCI应该在成功构建后部署您的应用程序。