Skip to content

Commit

Permalink
Conditionally deploy staging (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie authored Jul 4, 2024
1 parent ec462e5 commit ea02ec7
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions .github/workflows/public_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ jobs:
outputs:
matrix: ${{ steps.set-deployment-matrix.outputs.matrix }}
matrixLength: ${{ steps.set-deployment-matrix.outputs.matrixLength }}
deploy: ${{ steps.set-deployment-matrix.outputs.deploy }}

# Render task definition doesn't support working directory
# https://github.com/aws-actions/amazon-ecs-render-task-definition/issues/68#issuecomment-881407765
steps:
- name: Set Deployment Matrix
id: set-deployment-matrix
Expand All @@ -32,24 +31,28 @@ jobs:
"branch": "develop",
"image_tag": "staging",
"ecs_service": "public-gateway-staging",
"ecs_cluster": "somleng-switch-staging"
"ecs_cluster": "somleng-switch-staging",
"deploy": false
},
{
"identifier": "public-gateway",
"branch": "master",
"image_tag": "latest",
"ecs_service": "public-gateway",
"ecs_cluster": "somleng-switch"
"ecs_cluster": "somleng-switch",
"deploy": true
}
]
EOF
)
matrix=$(echo $matrixSource | jq --arg branchName "$branchName" 'map(. | select((.branch==$branchName)) )')
echo ::set-output name=matrix::{\"include\":$(echo $matrix)}\"
echo ::set-output name=matrixLength::$(echo $matrix | jq length)
echo "matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
echo "matrixLength=$(echo $matrix | jq length)" >> $GITHUB_OUTPUT
echo "deploy=$(echo $matrix | jq '.[0].deploy')" >> $GITHUB_OUTPUT
deploy:
name: Deploy
build_packages:
name: Build Packages
runs-on: ubuntu-latest
needs:
- integration_tests
Expand Down Expand Up @@ -102,9 +105,6 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -122,6 +122,26 @@ jobs:
${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.GHCR_REPOSITORY }}:${{ matrix.image_tag }}
deploy:
name: Deploy
runs-on: ubuntu-latest
needs:
- build
- build_packages

if: needs.build.outputs.deploy == 'true'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-southeast-1
ECR_REPOSITORY: public.ecr.aws/somleng/public-gateway
OPENSIPS_SCHEDULER_ECR_REPOSITORY: public.ecr.aws/somleng/opensips-scheduler
IMAGE_TAG: ${{ github.sha }}

strategy:
matrix: ${{fromJson(needs.build.outputs.matrix)}}

steps:
- name: Get current task definition
run: |
aws ecs describe-task-definition --task-definition "${{ matrix.identifier }}" --query 'taskDefinition' > task-definition.json
Expand All @@ -130,7 +150,7 @@ jobs:
id: render-opensips-scheduler-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: components/gateway/task-definition.json
task-definition: task-definition.json
container-name: opensips_scheduler
image: ${{ env.OPENSIPS_SCHEDULER_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}

Expand All @@ -149,4 +169,3 @@ jobs:
service: ${{ matrix.ecs_service }}
cluster: ${{ matrix.ecs_cluster }}
wait-for-service-stability: true

0 comments on commit ea02ec7

Please sign in to comment.