From 55756c25b4b446ec59a2c0894680319ccc32f242 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 20:33:23 +1300 Subject: [PATCH 1/5] refactor: make ci workflow reusable --- .github/workflows/ci.yml | 25 ++----------------------- .github/workflows/pr-workflow.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/pr-workflow.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b124a60..5d1f6de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,7 @@ name: Continuous Integration on: - push: - branches: - - master - pull_request: - branches: - - master + workflow_call: jobs: test: @@ -42,20 +37,4 @@ jobs: push: false tags: interview-webapp:latest cache-from: type=gha - cache-to: type=gha,mode=max - - ci-status: - name: Validate CI Status - runs-on: ubuntu-latest - needs: test - if: always() - steps: - - name: Check all jobs succeeded - run: | - if [ "${{ needs.test.result }}" != "success" ]; then - echo "โŒ Pipeline failed: One or more jobs did not complete successfully" - echo "Test job result: ${{ needs.test.result }}" - exit 1 - else - echo "โœ… All pipeline steps completed successfully!" - fi \ No newline at end of file + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.github/workflows/pr-workflow.yml b/.github/workflows/pr-workflow.yml new file mode 100644 index 0000000..0eac5d8 --- /dev/null +++ b/.github/workflows/pr-workflow.yml @@ -0,0 +1,27 @@ +name: Pull Requests Workflow + +on: + pull_request: + branches: + - master + +jobs: + test-and-build: + name: Test and Build + uses: ./.github/workflows/ci.yml + + ci-status: + name: Validate CI Status + runs-on: ubuntu-latest + needs: test-and-build + if: always() + steps: + - name: Check all jobs succeeded + run: | + if [ "${{ needs.test-and-build.result }}" != "success" ]; then + echo "โŒ Pipeline failed: One or more jobs did not complete successfully" + echo "Test and Build job result: ${{ needs.test-and-build.result }}" + exit 1 + else + echo "โœ… All pipeline steps completed successfully!" + fi \ No newline at end of file From 22b62bb3e67c76645ac65b1abe8c10e06b6107f7 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 21:19:14 +1300 Subject: [PATCH 2/5] feat: implement cd and master workflow --- .github/workflows/cd.yml | 111 ++++++++++++++++++++++++++ .github/workflows/master-workflow.yml | 17 ++++ 2 files changed, 128 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/master-workflow.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..261fa60 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,111 @@ +name: Continuous Deployment + +on: + workflow_call: + +jobs: + deploy: + name: Deploy to Production + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 + + - name: Build Docker image for deployment + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 + with: + context: . + push: false + tags: interview-webapp:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Deploy application (mocked) + run: | + echo "๐Ÿš€ Starting deployment to production..." + echo "๐Ÿ“ฆ Deploying Docker image: interview-webapp:latest" + + # Mock deployment - in real scenario this would be: + # - Push to ECR registry + # - Deploy to ECS + # - Run smoke tests + + docker run -d --name production-app -p 3000:3000 interview-webapp:latest + + echo "โณ Waiting for application to start..." + sleep 10 + + echo "โœ… Deployment completed successfully!" + + post-deployment-verification: + name: Post-Deployment Verification + runs-on: ubuntu-latest + needs: deploy + + steps: + - name: Health check verification + run: | + echo "๐Ÿ” Starting post-deployment verification..." + + # Wait for application to be ready + sleep 15 + + echo "๐Ÿฅ Testing health endpoint..." + if curl -f http://localhost:3000/health; then + echo "โœ… Health check passed!" + else + echo "โŒ Health check failed!" + exit 1 + fi + + echo "๐ŸŒ Testing main endpoint..." + if curl -f http://localhost:3000/; then + echo "โœ… Application verification completed successfully!" + else + echo "โŒ Main endpoint check failed!" + exit 1 + fi + + - name: Cleanup on verification failure + if: failure() + run: | + echo "๐Ÿงน Cleaning up failed deployment..." + docker stop production-app || true + docker rm production-app || true + + notify-failure: + name: Notify Deployment Failure + runs-on: ubuntu-latest + needs: [deploy, post-deployment-verification] + if: failure() + steps: + - name: Send failure notification + run: | + echo "๐Ÿšจ DEPLOYMENT FAILED!" + echo "Repository: ${{ github.repository }}" + echo "Commit: ${{ github.sha }}" + echo "Author: ${{ github.actor }}" + echo "Deploy result: ${{ needs.deploy.result }}" + echo "Verification result: ${{ needs.post-deployment-verification.result }}" + echo "Action required: Check workflow logs and fix deployment issue." + + cleanup: + name: Cleanup Resources + runs-on: ubuntu-latest + needs: [deploy, post-deployment-verification] + if: always() + + steps: + - name: Clean up deployment resources + run: | + echo "๐Ÿงน Cleaning up deployment resources..." + + # Stop and remove the container (this is just for the mock deployment) + docker stop production-app || echo "Container was not running" + docker rm production-app || echo "Container was already removed" + + echo "โœ… Cleanup completed" \ No newline at end of file diff --git a/.github/workflows/master-workflow.yml b/.github/workflows/master-workflow.yml new file mode 100644 index 0000000..683d5f1 --- /dev/null +++ b/.github/workflows/master-workflow.yml @@ -0,0 +1,17 @@ +name: Master Workflow + +on: + push: + branches: + - master + +jobs: + continuous-integration: + name: Continuous Integration + uses: ./.github/workflows/ci.yml + + continuous-deployment: + name: Continuous Deployment + uses: ./.github/workflows/cd.yml + needs: continuous-integration + if: success() \ No newline at end of file From d0d5c9d4a0db96fd774fe289da26d0eded6e459b Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 21:19:32 +1300 Subject: [PATCH 3/5] test: trigger workflow --- .github/workflows/master-workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/master-workflow.yml b/.github/workflows/master-workflow.yml index 683d5f1..5dc5896 100644 --- a/.github/workflows/master-workflow.yml +++ b/.github/workflows/master-workflow.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - feat/* jobs: continuous-integration: From 9b3339a83bd43c4b4b89b7740cb666ced5e781d7 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 21:28:43 +1300 Subject: [PATCH 4/5] fix: workflow error --- .github/workflows/cd.yml | 75 ++++++++++------------------------------ 1 file changed, 18 insertions(+), 57 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 261fa60..4037f84 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -4,8 +4,8 @@ on: workflow_call: jobs: - deploy: - name: Deploy to Production + deploy-and-verify: + name: Deploy and Verify runs-on: ubuntu-latest steps: @@ -19,15 +19,15 @@ jobs: uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 with: context: . - push: false + load: true tags: interview-webapp:latest cache-from: type=gha cache-to: type=gha,mode=max - name: Deploy application (mocked) run: | - echo "๐Ÿš€ Starting deployment to production..." - echo "๐Ÿ“ฆ Deploying Docker image: interview-webapp:latest" + echo "Starting deployment to production..." + echo "Deploying Docker image: interview-webapp:latest" # Mock deployment - in real scenario this would be: # - Push to ECR registry @@ -36,76 +36,37 @@ jobs: docker run -d --name production-app -p 3000:3000 interview-webapp:latest - echo "โณ Waiting for application to start..." - sleep 10 + echo "Waiting for application to start..." + sleep 5 - echo "โœ… Deployment completed successfully!" - - post-deployment-verification: - name: Post-Deployment Verification - runs-on: ubuntu-latest - needs: deploy - - steps: - - name: Health check verification - run: | - echo "๐Ÿ” Starting post-deployment verification..." - - # Wait for application to be ready - sleep 15 - - echo "๐Ÿฅ Testing health endpoint..." + echo "Running smoke test on /health endpoint..." if curl -f http://localhost:3000/health; then - echo "โœ… Health check passed!" + echo "โœ… Smoke test passed - deployment successful!" else - echo "โŒ Health check failed!" + echo "โŒ Smoke test failed - deployment issue detected!" exit 1 fi - echo "๐ŸŒ Testing main endpoint..." - if curl -f http://localhost:3000/; then - echo "โœ… Application verification completed successfully!" - else - echo "โŒ Main endpoint check failed!" - exit 1 - fi + echo "โœ… Deployment completed successfully!" - - name: Cleanup on verification failure + - name: Cleanup on failure if: failure() run: | - echo "๐Ÿงน Cleaning up failed deployment..." + echo "Cleaning up failed deployment..." docker stop production-app || true docker rm production-app || true notify-failure: name: Notify Deployment Failure runs-on: ubuntu-latest - needs: [deploy, post-deployment-verification] + needs: [deploy-and-verify] if: failure() steps: - - name: Send failure notification + - name: Send failure notification (mocked) run: | - echo "๐Ÿšจ DEPLOYMENT FAILED!" + echo "DEPLOYMENT FAILED!" echo "Repository: ${{ github.repository }}" echo "Commit: ${{ github.sha }}" echo "Author: ${{ github.actor }}" - echo "Deploy result: ${{ needs.deploy.result }}" - echo "Verification result: ${{ needs.post-deployment-verification.result }}" - echo "Action required: Check workflow logs and fix deployment issue." - - cleanup: - name: Cleanup Resources - runs-on: ubuntu-latest - needs: [deploy, post-deployment-verification] - if: always() - - steps: - - name: Clean up deployment resources - run: | - echo "๐Ÿงน Cleaning up deployment resources..." - - # Stop and remove the container (this is just for the mock deployment) - docker stop production-app || echo "Container was not running" - docker rm production-app || echo "Container was already removed" - - echo "โœ… Cleanup completed" \ No newline at end of file + echo "Deploy and verify result: ${{ needs.deploy-and-verify.result }}" + echo "Action required: Check workflow logs and fix deployment issue." \ No newline at end of file From 4bd657f40da8129fb86d3ce850fe2b81ba9ee702 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 21:35:52 +1300 Subject: [PATCH 5/5] Revert "test: trigger workflow" This reverts commit d0d5c9d4a0db96fd774fe289da26d0eded6e459b. --- .github/workflows/master-workflow.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/master-workflow.yml b/.github/workflows/master-workflow.yml index 5dc5896..683d5f1 100644 --- a/.github/workflows/master-workflow.yml +++ b/.github/workflows/master-workflow.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - feat/* jobs: continuous-integration: