• 在线文档部署源码
  • Ansible入门系列视频:
    B站 https://space.bilibili.com/364122352/channel/detail?cid=125322

    build.yml文件

    1. name: docker image build and push
    2. on: [push]
    3. jobs:
    4. build:
    5. runs-on: ubuntu-latest
    6. steps:
    7. - name: Checkout
    8. uses: actions/checkout@v2
    9. - name: Set up QEMU
    10. uses: docker/setup-qemu-action@v1
    11. - name: Set up Docker Buildx
    12. id: buildx
    13. uses: docker/setup-buildx-action@v1
    14. - name: Login to DockerHub
    15. uses: docker/login-action@v1
    16. with:
    17. username: ${{ secrets.DOCKERHUB_USERNAME }}
    18. password: ${{ secrets.DOCKERHUB_PASSWORD }}
    19. - name: Build and push
    20. id: docker_build
    21. uses: docker/build-push-action@v2
    22. with:
    23. push: true
    24. platforms: linux/amd64,linux/arm64
    25. tags: insaneloafer/dockertips:latest
    26. deploy:
    27. runs-on: ubuntu-latest
    28. needs: build
    29. steps:
    30. - name: Checkout
    31. uses: actions/checkout@v2
    32. - name: deploy to aws
    33. run: |
    34. cd ansible/
    35. pip install ansible
    36. echo ${{ secrets.ANSIBLE_VAULT }} > vault_pass.txt
    37. export ANSIBLE_VAULT_PASSWORD_FILE=vault_pass.txt
    38. ansible-vault decrypt aws.pem
    39. 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 ```