From ac05421519ec64b8f718dfacee2689215826b5fd Mon Sep 17 00:00:00 2001 From: maxmwang Date: Sun, 17 Nov 2024 23:36:04 -0800 Subject: [PATCH] cicd use matrix strategy --- .github/workflows/cd.yaml | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 87d4dcde1..ca4a326a5 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -9,9 +9,12 @@ on: type: string jobs: - build-push-backend: - name: Build and Push Backend Image + build-push-image: + name: Build and Push Backend/Frontend Images runs-on: ubuntu-latest + strategy: + matrix: + image: [backend, frontend] steps: - name: Checkout Repository @@ -25,24 +28,5 @@ jobs: - name: Build and Push Image with Tag run: | - docker build --no-cache --platform=linux/amd64 --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ inputs.tag }}" . - docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ inputs.tag }}" - - build-push-frontend: - name: Build and Push Frontend Image - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and Push Image with Tag - run: | - docker build --no-cache --platform=linux/amd64 --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ inputs.tag }}" . - docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ inputs.tag }}" + docker build --no-cache --platform=linux/amd64 --target ${{ matrix.image }}-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-${{ matrix.image }}:${{ inputs.tag }}" . + docker push "${{ secrets.DOCKER_USERNAME }}/bt-${{ matrix.image }}:${{ inputs.tag }}"