diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5ba513a..4de4b3e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,6 +18,10 @@ on: OTEL_TAG: type: 'string' required: true + PUSH_TO_ECR: + type: 'boolean' + required: false + default: true secrets: AWS_ACCESS_KEY_ID: required: true @@ -40,6 +44,7 @@ jobs: chmod +x $HOME/.local/bin/ecs-deploy - name: Login to GitHub Container Registry + if: ${{ inputs.PUSH_TO_ECR == true }} uses: docker/login-action@v2 with: registry: ghcr.io @@ -47,6 +52,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Pull from GHCR + if: ${{ inputs.PUSH_TO_ECR == true }} run: | docker pull ${{ inputs.BUILD_ENGINE_TAG }} docker pull ${{ inputs.OTEL_TAG }} @@ -62,18 +68,21 @@ jobs: - name: Login to AWS ECR id: ecr + if: ${{ inputs.PUSH_TO_ECR == true }} uses: aws-actions/amazon-ecr-login@v2 with: registries: ${{ secrets.AWS_ECR_ACCOUNT }} - name: Build deployment target variables id: vars + if: ${{ inputs.PUSH_TO_ECR == true }} run: | echo "Setting up deployment variables..." echo "IMAGE_URL=${{ steps.ecr.outputs.registry }}/appbuilder-buildengine-api" >> $GITHUB_OUTPUT echo "OTEL_URL=${{ steps.ecr.outputs.registry }}/appbuilder-buildengine-otel" >> $GITHUB_OUTPUT - name: Push to AWS ECR + if: ${{ inputs.PUSH_TO_ECR == true }} run: | docker tag ${{ inputs.BUILD_ENGINE_TAG}} "${{ steps.vars.outputs.IMAGE_URL }}:${{ inputs.DOCKER_TAG }}" docker tag ${{ inputs.BUILD_ENGINE_TAG}} "${{ steps.vars.outputs.IMAGE_URL }}:${{ inputs.BUILD_NUMBER }}" @@ -92,6 +101,8 @@ jobs: - name: Deploy to ECS if: ${{ inputs.ECS_CLUSTER != 'none' }} run: | - echo "Deploying ${{ inputs.BUILD_NUMBER }} to ${{ inputs.ECS_CLUSTER }}" + echo "Deploying ${{ inputs.PUSH_TO_ECR && inputs.BUILD_NUMBER || inputs.DOCKER_TAG }} from ${{ inputs.PUSH_TO_ECR && 'ECR' || 'GHCR' }} to ${{ inputs.ECS_CLUSTER }}" # Deploy to ECS cluster with service name 'build-engine', setting all images to the latest tag - ecs-deploy -c ${{ inputs.ECS_CLUSTER }} -n buildengine -i ignore -to ${{ inputs.BUILD_NUMBER }} --max-definitions 20 --timeout 600 + # Some deployments use images from GHCR, some from ECR. If PUSH_TO_ECR is true, we use the ECR images; otherwise, we use the GHCR images. + # GHCR images are tagged with DOCKER_TAG ("staging" or "production"), while ECR images are tagged with BUILD_NUMBER (the GitHub Actions run number). + ecs-deploy -c ${{ inputs.ECS_CLUSTER }} -n buildengine -i ignore -to ${{ inputs.PUSH_TO_ECR && inputs.BUILD_NUMBER || inputs.DOCKER_TAG }} --max-definitions 20 --timeout 600 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cc32933..8b7699f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -90,33 +90,21 @@ jobs: AWS_ECR_ACCOUNT: ${{ secrets.SIL__AWS_ECR_ACCOUNT }} deploy-fcbh: needs: push-to-ghcr - if: false # Temporarily disabled - remove this line to re-enable - # if: ${{ needs.push-to-ghcr.outputs.ECS_CLUSTER == 'scriptoria-prd' }} # Restore this when re-enabling + if: ${{ needs.push-to-ghcr.outputs.ECS_CLUSTER == 'scriptoria-prd' }} uses: "./.github/workflows/deploy.yml" with: - BUILD_NUMBER: ${{ github.run_number }} ECS_CLUSTER: ${{ needs.push-to-ghcr.outputs.ECS_CLUSTER }} DOCKER_TAG: ${{ needs.push-to-ghcr.outputs.DOCKER_TAG }} + PUSH_TO_ECR: false + + # Unused + BUILD_NUMBER: ${{ github.run_number }} + # Unused BUILD_ENGINE_TAG: ${{ needs.push-to-ghcr.outputs.BUILD_ENGINE_TAG }} + # Unused OTEL_TAG: ${{ needs.push-to-ghcr.outputs.OTEL_TAG }} secrets: AWS_ACCESS_KEY_ID: ${{ secrets.FCBH__AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.FCBH__AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: ${{ secrets.FCBH__AWS_DEFAULT_REGION }} AWS_ECR_ACCOUNT: ${{ secrets.FCBH__AWS_ECR_ACCOUNT }} - deploy-lu: - needs: push-to-ghcr - if: false # Temporarily disabled - remove this line to re-enable - # if: ${{ needs.push-to-ghcr.outputs.ECS_CLUSTER == 'scriptoria-stg' }} # Restore this when re-enabling - uses: "./.github/workflows/deploy.yml" - with: - BUILD_NUMBER: ${{ github.run_number }} - ECS_CLUSTER: ${{ needs.push-to-ghcr.outputs.ECS_CLUSTER }} - DOCKER_TAG: ${{ needs.push-to-ghcr.outputs.DOCKER_TAG }} - BUILD_ENGINE_TAG: ${{ needs.push-to-ghcr.outputs.BUILD_ENGINE_TAG }} - OTEL_TAG: ${{ needs.push-to-ghcr.outputs.OTEL_TAG }} - secrets: - AWS_ACCESS_KEY_ID: ${{ secrets.LU__AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.LU__AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: ${{ secrets.LU__AWS_DEFAULT_REGION }} - AWS_ECR_ACCOUNT: ${{ secrets.LU__AWS_ECR_ACCOUNT }}