Skip to content

CI/CD

CI/CD #210

Workflow file for this run

name: CI/CD
on:
push:
branches: ["main", "feat-user-manage"]
workflow_dispatch:
jobs:
build_docker:
name: Build Docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64
tags: |
${{ vars.DOCKERHUB_USERNAME }}/${{ vars.IMAGE_NAME }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }}
cache-from: type=gha
cache-to: type=gha,mode=max
build_docker_acr:
name: Build Docker ACR
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to ACR
uses: aliyun/acr-login@v1
with:
login-server: https://${{ vars.REGISTRY_ADDRESS }}
username: "${{ vars.REGISTRY_USERNAME }}"
password: "${{ secrets.REGISTRY_PASSWORD }}"
- name: Build and push image
run: |
docker build -t ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_NAMESPACE }}/${{ vars.IMAGE_NAME }}:latest .
docker push ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_NAMESPACE }}/${{ vars.IMAGE_NAME }}:latest
deploy:
name: Deploy
needs: [build_docker, build_docker_acr]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: SSH To Host
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ${{ secrets.PROJECT_PATH }}
sudo bash ./deploy.sh