From dba3fbd582c08df4eae80931fdf7dd4c4dbaaa2b Mon Sep 17 00:00:00 2001 From: maxmwang Date: Sat, 28 Sep 2024 18:28:26 -0700 Subject: [PATCH] use reusable workflows in prod and stage --- .github/workflows/cd-prod.yaml | 46 ++++++-------------------------- .github/workflows/cd-stage.yaml | 47 ++++++--------------------------- 2 files changed, 16 insertions(+), 77 deletions(-) diff --git a/.github/workflows/cd-prod.yaml b/.github/workflows/cd-prod.yaml index 7844633d4..34a463592 100644 --- a/.github/workflows/cd-prod.yaml +++ b/.github/workflows/cd-prod.yaml @@ -15,47 +15,17 @@ jobs: - name: Pass run: echo "Passed check" - build-push-backend: - name: Build and Push Backend 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 --platform=linux/amd64 --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" . - docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" - - 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 --platform=linux/amd64 --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" . - docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" + build-push: + name: Build and Push Images + needs: [branch-check] + uses: ./.github/workflows/cd.yaml + with: + tag: prod + secrets: inherit deploy: name: Deploy with SSH - needs: [build-push-backend, build-push-frontend] + needs: [build-push] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/cd-stage.yaml b/.github/workflows/cd-stage.yaml index 1ccb7f5c7..090ae62b7 100644 --- a/.github/workflows/cd-stage.yaml +++ b/.github/workflows/cd-stage.yaml @@ -4,50 +4,19 @@ concurrency: stage on: push: - branches: [master] + branches: [master, gql] jobs: - build-push-backend: - name: Build and Push Backend 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 --platform=linux/amd64 --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:latest" . - docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:latest" - - 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 --platform=linux/amd64 --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:latest" . - docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:latest" + build-push: + name: Build and Push Images + uses: ./.github/workflows/cd.yaml + with: + tag: latest + secrets: inherit deploy: name: Deploy with SSH - needs: [build-push-backend, build-push-frontend] + needs: [build-push] runs-on: ubuntu-latest environment: staging