Skip to content

Commit

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

# 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 @@ -29,27 +27,30 @@ jobs:
[
{
"identifier": "public-gateway-staging",
"branch": "develop",
"branch": "fix_deploy_on_staging",
"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
deploy:
name: Deploy
build_packages:
name: Build Packages
runs-on: ubuntu-latest
needs:
- integration_tests
Expand Down Expand Up @@ -102,9 +103,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 +120,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.matrixLength.deploy
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 +148,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 +167,3 @@ jobs:
service: ${{ matrix.ecs_service }}
cluster: ${{ matrix.ecs_cluster }}
wait-for-service-stability: true

0 comments on commit d845a04

Please sign in to comment.