Skip to content

Commit

Permalink
CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
M397749490 committed Jan 7, 2025
1 parent a14c17c commit b2014bc
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Docker Image CI
name: CI/CD

on:
push:
branches: [ "main" ]
push:
branches: "main"
workflow_dispatch:

jobs:
build_docker:
name: Build docker
name: Build Docker
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -19,8 +19,8 @@ jobs:
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
Expand All @@ -29,12 +29,30 @@ jobs:
push: true
platforms: linux/amd64
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/toyou-frontend:latest
${{ 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 }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} .
docker push ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_NAMESPACE }}/${{ vars.IMAGE_NAME }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }}
deploy:
name: Deploy
needs: build_docker
needs: [build_docker, build_docker_acr]
runs-on: ubuntu-latest
steps:
- name: SSH To Host
Expand All @@ -45,6 +63,5 @@ jobs:
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ${{ secrets.PROJ_PATH }}
sudo docker compose down
cd ${{ secrets.PROJECT_PATH }}
sudo bash ./deploy.sh

0 comments on commit b2014bc

Please sign in to comment.