我正在使用Circle CI将微服务部署到Digital Ocean Drop,并对我的方法是否正确存在一些疑问。
我的微服务是使用docker-compose
构建的,因此需要docker-compose.yml文件来拉,启动构成它的映像。
简而言之,我的部署方法是:
docker-compose build
和docker-compose
被推送到Docker Hub docker-compose.yml
,Dockerfile
和docker-compose.env
文件。docker-compose pull
docker-compose up
我正在CircleCI中使用此配置:
version: 2.1
jobs:
build:
docker:
- image: "circleci/node:10.16.0"
steps:
- checkout
- run:
name: Update to latest npm version
command: "sudo npm install -g npm@latest"
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Install dependencies
command: npm install
- run:
name: Install `docker-compose`
command: |
curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
chmod +x ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
- setup_remote_docker:
docker_layer_caching: false
- run:
name: Build using `docker-compose`
command: |
docker-compose build
- run:
name: Login for Docker Hub
command: |
echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USERNAME --password-stdin
- run:
name: Push to Docker Hub
command: |
docker-compose push
- run: ssh-keyscan $DIGITALOCEAN_HOST >> ~/.ssh/known_hosts
- add_ssh_keys:
fingerprints:
- fo:of:fe:ef:af
- run:
name: Remove currently running containers
command: |
ssh root@$DIGITALOCEAN_HOST ./deploy_image.sh
我正计划创建一个bash脚本来处理以上列表中的步骤4
至8
。
让脚本处理Docker步骤是一个好主意吗?
还是有更好的方法来拥有更“原生”的CircleCI配置?