ci/cd #203
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64 | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/klpbbs-survey-frontend:${{ 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://registry.cn-guangzhou.aliyuncs.com | |
username: "${{ secrets.REGISTRY_USERNAME }}" | |
password: "${{ secrets.REGISTRY_PASSWORD }}" | |
- name: Build and push image | |
run: | | |
docker build -t registry.cn-guangzhou.aliyuncs.com/teamvastsea/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} . | |
docker push registry.cn-guangzhou.aliyuncs.com/teamvastsea/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} | |
deploy: | |
name: Deploy | |
needs: [build_docker, build_docker_acr] | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' # Only run deploy if on main branch | |
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.PROJ_PATH }} | |
sudo bash ./deploy.sh |