build.yml文件
name: docker image build and push
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
platforms: linux/amd64,linux/arm64
tags: insaneloafer/dockertips:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
- name: deploy to aws
run: |
cd ansible/
pip install ansible
echo ${{ secrets.ANSIBLE_VAULT }} > vault_pass.txt
export ANSIBLE_VAULT_PASSWORD_FILE=vault_pass.txt
ansible-vault decrypt aws.pem
ansible-playbook -i hosts deploy.yml
deploy.yml 文件
- name: deploy docker.tips
hosts: aws
gather_facts: no
vars:
ansible_connection: ssh
ansible_user: ubuntu
ansible_ssh_private_key_file: ./aws.pem
tasks:
- name: stop the old container
shell: docker container stop web
ignore_errors: yes
- name: update docker image
shell: docker image pull InsaneLoafer/dockertips:latest
- name: create new container
shell: docker container run --rm -d -p 80:80 --name web InsaneLoafer/dockertips:latest