Skip to content

Build and Push Docker Images #20

Build and Push Docker Images

Build and Push Docker Images #20

Workflow file for this run

name: Build and Push Docker Images
#on:
# push:
# branches:
# - main
on:
workflow_dispatch: # 手动触发工作流
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ secrets.DOCKER_HUB_ADDR }}
- name: Build and push web Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./deployment/web/Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_ADDR }}/${{ secrets.DOCKER_NAMESPACE }}/web:${{ vars.VERSION }}
platforms: linux/amd64
- name: Build and push django Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./deployment/django/Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_ADDR }}/${{ secrets.DOCKER_NAMESPACE }}/django:${{ vars.VERSION }}
platforms: linux/amd64
- name: Build and push celery Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./deployment/celery/Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_ADDR }}/${{ secrets.DOCKER_NAMESPACE }}/celery:${{ vars.VERSION }}
platforms: linux/amd64
- name: Build and push proxy Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./deployment/proxy/Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_ADDR }}/${{ secrets.DOCKER_NAMESPACE }}/proxy:${{ vars.VERSION }}
platforms: linux/amd64
- name: SSH and Deploy to Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ${{ secrets.SSH_DIR }}
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rmi $(docker images -q)
sudo docker compose up -d