|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + environment: |
| 9 | + description: 'Target environment' |
| 10 | + required: true |
| 11 | + type: choice |
| 12 | + options: |
| 13 | + - staging |
| 14 | + - production |
| 15 | + image_tag: |
| 16 | + description: 'Docker image tag to deploy' |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + |
| 20 | +env: |
| 21 | + REGISTRY: ghcr.io |
| 22 | + IMAGE_NAME: ${{ github.repository }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + prepare: |
| 26 | + name: Prepare Deployment |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + image_tag: ${{ steps.resolve-tag.outputs.tag }} |
| 30 | + version: ${{ steps.resolve-tag.outputs.version }} |
| 31 | + steps: |
| 32 | + - name: Resolve image tag |
| 33 | + id: resolve-tag |
| 34 | + run: | |
| 35 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 36 | + echo "tag=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT |
| 37 | + echo "version=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT |
| 38 | + else |
| 39 | + TAG="${GITHUB_REF#refs/tags/}" |
| 40 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 41 | + echo "version=${TAG}" >> $GITHUB_OUTPUT |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Verify image exists |
| 45 | + run: | |
| 46 | + echo "Verifying image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.resolve-tag.outputs.tag }}" |
| 47 | +
|
| 48 | + deploy-staging: |
| 49 | + name: Deploy to Staging |
| 50 | + needs: prepare |
| 51 | + runs-on: ubuntu-latest |
| 52 | + environment: |
| 53 | + name: staging |
| 54 | + url: https://ordermonitor-api.staging.printerpix.com/health |
| 55 | + steps: |
| 56 | + - name: Checkout code |
| 57 | + uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Set image tag in manifests |
| 60 | + run: | |
| 61 | + cd k8s/overlays/staging |
| 62 | + kustomize edit set image ghcr.io/printerpix/printerpix-backoffice-ordermonitor-api=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }} |
| 63 | +
|
| 64 | + - name: Deploy to staging |
| 65 | + run: | |
| 66 | + echo "Deploying ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }} to staging" |
| 67 | + echo "kubectl apply -k k8s/overlays/staging" |
| 68 | + # Uncomment when cluster credentials are configured: |
| 69 | + # kubectl apply -k k8s/overlays/staging |
| 70 | + # kubectl -n ordermonitor-staging rollout status deployment/staging-ordermonitor-api --timeout=300s |
| 71 | +
|
| 72 | + - name: Run smoke tests |
| 73 | + run: | |
| 74 | + echo "Running smoke tests against staging..." |
| 75 | + # Uncomment when staging is accessible: |
| 76 | + # chmod +x scripts/smoke-test.sh |
| 77 | + # ./scripts/smoke-test.sh https://ordermonitor-api.staging.printerpix.com |
| 78 | +
|
| 79 | + - name: Staging deployment summary |
| 80 | + run: | |
| 81 | + echo "## Staging Deployment" >> $GITHUB_STEP_SUMMARY |
| 82 | + echo "- **Image:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }}" >> $GITHUB_STEP_SUMMARY |
| 83 | + echo "- **Version:** ${{ needs.prepare.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 84 | + echo "- **Environment:** staging" >> $GITHUB_STEP_SUMMARY |
| 85 | +
|
| 86 | + deploy-production: |
| 87 | + name: Deploy to Production |
| 88 | + needs: [prepare, deploy-staging] |
| 89 | + runs-on: ubuntu-latest |
| 90 | + environment: |
| 91 | + name: production |
| 92 | + url: https://ordermonitor-api.printerpix.com/health |
| 93 | + steps: |
| 94 | + - name: Checkout code |
| 95 | + uses: actions/checkout@v4 |
| 96 | + |
| 97 | + - name: Set image tag in manifests |
| 98 | + run: | |
| 99 | + cd k8s/overlays/production |
| 100 | + kustomize edit set image ghcr.io/printerpix/printerpix-backoffice-ordermonitor-api=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }} |
| 101 | +
|
| 102 | + - name: Deploy to production |
| 103 | + run: | |
| 104 | + echo "Deploying ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }} to production" |
| 105 | + echo "kubectl apply -k k8s/overlays/production" |
| 106 | + # Uncomment when cluster credentials are configured: |
| 107 | + # kubectl apply -k k8s/overlays/production |
| 108 | + # kubectl -n ordermonitor rollout status deployment/ordermonitor-api --timeout=300s |
| 109 | +
|
| 110 | + - name: Run smoke tests |
| 111 | + run: | |
| 112 | + echo "Running smoke tests against production..." |
| 113 | + # Uncomment when production is accessible: |
| 114 | + # chmod +x scripts/smoke-test.sh |
| 115 | + # ./scripts/smoke-test.sh https://ordermonitor-api.printerpix.com |
| 116 | +
|
| 117 | + - name: Production deployment summary |
| 118 | + run: | |
| 119 | + echo "## Production Deployment" >> $GITHUB_STEP_SUMMARY |
| 120 | + echo "- **Image:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }}" >> $GITHUB_STEP_SUMMARY |
| 121 | + echo "- **Version:** ${{ needs.prepare.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 122 | + echo "- **Environment:** production" >> $GITHUB_STEP_SUMMARY |
0 commit comments