diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..4037f84 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,72 @@ +name: Continuous Deployment + +on: + workflow_call: + +jobs: + deploy-and-verify: + name: Deploy and Verify + 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: . + 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" + + # 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 5 + + echo "Running smoke test on /health endpoint..." + if curl -f http://localhost:3000/health; then + echo "✅ Smoke test passed - deployment successful!" + else + echo "❌ Smoke test failed - deployment issue detected!" + exit 1 + fi + + echo "✅ Deployment completed successfully!" + + - name: Cleanup on 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-and-verify] + if: failure() + steps: + - name: Send failure notification (mocked) + run: | + echo "DEPLOYMENT FAILED!" + echo "Repository: ${{ github.repository }}" + echo "Commit: ${{ github.sha }}" + echo "Author: ${{ github.actor }}" + 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 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/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 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