Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Sep 18, 2024
1 parent 9aae697 commit 0c2fa98
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 148 deletions.
88 changes: 49 additions & 39 deletions .github/workflows/client_gateway.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Client Gateway
on: push

env:
CI: true
GATEWAY_REPOSITORY_NAME: client-gateway
GATEWAY_SCHEDULER_REPOSITORY_NAME: gateway-scheduler

jobs:
integration_tests:
uses: ./.github/workflows/integration_tests.yml
Expand All @@ -26,46 +31,35 @@ jobs:
[
{
"identifier": "client-gateway-staging",
"branch": "develop",
"image_tag": "staging",
"branch": "ecr_private_for_gateways",
"friendly_image_tag": "beta",
"image_tag": "stag-${{ github.sha }}",
"ecs_service": "client-gateway-staging",
"ecs_cluster": "somleng-switch-staging"
},
{
"identifier": "client-gateway",
"branch": "master",
"image_tag": "latest",
"friendly_image_tag": "latest",
"image_tag": "prod-${{ github.sha }}",
"ecs_service": "client-gateway",
"ecs_cluster": "somleng-switch"
}
]
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
- build

if: needs.build.outputs.matrixLength > 0
defaults:
run:
working-directory: components/gateway

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_PUBLIC_REGISTRY: public.ecr.aws
ECR_REPOSITORY: public.ecr.aws/somleng/client-gateway
OPENSIPS_SCHEDULER_ECR_REPOSITORY: public.ecr.aws/somleng/opensips-scheduler
GHCR_REPOSITORY: ghcr.io/somleng/client-gateway
IMAGE_TAG: ${{ github.sha }}

strategy:
matrix: ${{fromJson(needs.build.outputs.matrix)}}
Expand All @@ -85,12 +79,8 @@ jobs:
role-duration-seconds: 3600
aws-region: ap-southeast-1

- name: Login to AWS Public ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_PUBLIC_REGISTRY }}
env:
AWS_REGION: us-east-1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -99,13 +89,12 @@ 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
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_REGISTRY }}

- name: Build and push Client Gateway
- name: Build and push Public Gateway
uses: docker/build-push-action@v6
with:
context: components/gateway
Expand All @@ -115,29 +104,50 @@ jobs:
cache-from: type=gha,scope=${{ matrix.identifier }}
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}
tags: |
${{ env.ECR_REPOSITORY }}:${{ matrix.image_tag }}
${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.GHCR_REPOSITORY }}:${{ matrix.image_tag }}
${{ env.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }}
${{ env.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}
deploy:
name: Deploy
runs-on: ubuntu-latest
needs:
- build
- build_packages

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

steps:
- name: Configure AWS credentials
id: aws-login
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-skip-session-tagging: true
role-duration-seconds: 3600
aws-region: ap-southeast-1

- name: Get current task definition
run: |
aws ecs describe-task-definition --task-definition "${{ matrix.identifier }}" --query 'taskDefinition' > task-definition.json
- name: Prepare task definition with OpenSIPS scheduler
- name: Prepare task definition with Gateway Scheduler
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 }}
image: ${{ env.ECR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_REPOSITORY_NAME }}:${{ matrix.image_tag }}

- name: Prepare task definition
id: render-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.render-opensips-scheduler-task-def.outputs.task-definition }}
container-name: client_gateway
image: ${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
image: ${{ env.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }}

- name: Deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
Expand Down
77 changes: 31 additions & 46 deletions .github/workflows/gateway_commons.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Gateway Commons
on: push
env:
ECR_REGISTRY: 324279636507.dkr.ecr.ap-southeast-1.amazonaws.com
GHCR_REGISTRY: ghcr.io/somleng
GATEWAY_REPOSITORY_NAME: gateway
GATEWAY_SCHEDULER_REPOSITORY_NAME: gateway-scheduler

jobs:
build:
Expand All @@ -18,13 +23,15 @@ jobs:
[
{
"identifier": "gateway-commons-staging",
"branch": "develop",
"image_tag": "staging"
"branch": "ecr_private_for_gateways",
"friendly_image_tag": "beta",
"image_tag": "stag-${{ github.sha }}"
},
{
"identifier": "gateway-commons",
"branch": "master",
"image_tag": "latest"
"friendly_image_tag": "latest",
"image_tag": "prod-${{ github.sha }}"
}
]
EOF
Expand All @@ -33,34 +40,19 @@ jobs:
echo "matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
echo "matrixLength=$(echo $matrix | jq length)" >> $GITHUB_OUTPUT
deploy:
name: Deploy Gateway Commons
build-packages:
name: Build Packages
runs-on: ubuntu-latest
needs:
- build

if: needs.build.outputs.matrixLength > 0

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_PUBLIC_REGISTRY: public.ecr.aws
GATEWAY_ECR_REPOSITORY: public.ecr.aws/somleng/gateway
GATEWAY_GHCR_REPOSITORY: ghcr.io/somleng/gateway
OPENSIPS_SCHEDULER_ECR_REPOSITORY: public.ecr.aws/somleng/opensips-scheduler
OPENSIPS_SCHEDULER_GHCR_REPOSITORY: ghcr.io/somleng/opensips-scheduler
IMAGE_TAG: ${{ github.sha }}

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

steps:
- name: Checkout
uses: actions/checkout@v4
needs:
- build

steps:
- name: Configure AWS credentials
id: aws-login
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand All @@ -70,12 +62,8 @@ jobs:
role-duration-seconds: 3600
aws-region: ap-southeast-1

- name: Login to AWS Public ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_PUBLIC_REGISTRY }}
env:
AWS_REGION: us-east-1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -84,34 +72,31 @@ 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
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_REGISTRY }}

- name: Build and push OpenSIPS Scheduler
- name: Build and push Gateway Scheduler
uses: docker/build-push-action@v6
with:
context: components/opensips_scheduler
push: true
platforms: linux/amd64
cache-from: type=gha,scope=${{ matrix.identifier }}-opensips-scheduler
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-opensips-scheduler
platforms: linux/amd64,linux/arm64
cache-from: type=gha,scope=${{ matrix.identifier }}-gateway-scheduler
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-gateway-scheduler
tags: |
${{ env.OPENSIPS_SCHEDULER_ECR_REPOSITORY }}:${{ matrix.image_tag }}
${{ env.OPENSIPS_SCHEDULER_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
${{ env.OPENSIPS_SCHEDULER_GHCR_REPOSITORY }}:${{ matrix.image_tag }}
${{ env.ECR_REGISTRY }}/${{ env.PUBLIC_GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }}
${{ env.GHCR_REGISTRY }}/${{ env.PUBLIC_GATEWAY_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}
- name: Build and push OpenSIPS Bootstrap
- name: Build and push Gateway
uses: docker/build-push-action@v6
with:
context: components/gateway
target: bootstrap
push: true
platforms: linux/amd64
cache-from: type=gha,scope=${{ matrix.identifier }}-bootstrap
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-bootstrap
cache-from: type=gha,scope=${{ matrix.identifier }}-gateway
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-gateway
tags: |
${{ env.GATEWAY_ECR_REPOSITORY }}:bootstrap
${{ env.GATEWAY_GHCR_REPOSITORY }}:bootstrap
${{ env.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:bootstrap
36 changes: 15 additions & 21 deletions .github/workflows/media_proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Media Proxy
on: push

env:
IMAGE_TAG: ${{ github.sha }}
ECR_REGISTRY: public.ecr.aws/somleng
GHCR_REGISTRY: ghcr.io/somleng
ECR_REPOSITORY: media-proxy

jobs:
build:
Expand All @@ -23,15 +23,17 @@ jobs:
[
{
"identifier": "media-proxy-staging",
"branch": "develop",
"image_tag": "staging",
"branch": "ecr_private_for_gateways",
"friendly_image_tag": "beta",
"image_tag": "stag-${{ github.sha }}",
"ecs_service": "media-proxy-staging",
"ecs_cluster": "somleng-switch-staging"
},
{
"identifier": "media-proxy",
"branch": "master",
"image_tag": "latest",
"friendly_image_tag": "latest",
"image_tag": "prod-${{ github.sha }}",
"ecs_service": "media-proxy",
"ecs_cluster": "somleng-switch"
}
Expand All @@ -47,16 +49,11 @@ jobs:
runs-on: ubuntu-latest
if: needs.build.outputs.matrixLength > 0

defaults:
run:
working-directory: components/media_proxy

needs:
- build

strategy:
matrix: ${{fromJSON(needs.build.outputs.matrix)}}
fail-fast: false

steps:
- name: Checkout
Expand All @@ -72,12 +69,8 @@ jobs:
role-duration-seconds: 3600
aws-region: ap-southeast-1

- name: Login to AWS Public ECR
uses: docker/login-action@v3
with:
registry: public.ecr.aws
env:
AWS_REGION: us-east-1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -86,8 +79,10 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_REGISTRY }}

- name: Build and push Media Proxy
uses: docker/build-push-action@v6
Expand All @@ -98,9 +93,8 @@ jobs:
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}
platforms: linux/amd64,linux/arm64
tags: |
${{ env.ECR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}
${{ env.ECR_REGISTRY }}/media-proxy:${{ env.IMAGE_TAG }}
${{ env.GHCR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}
${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}
deploy:
name: Deploy
Expand Down Expand Up @@ -136,7 +130,7 @@ jobs:
with:
task-definition: task-definition.json
container-name: media_proxy
image: ${{ env.ECR_REGISTRY }}/media-proxy:${{ env.IMAGE_TAG }}
image: ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}

- name: Deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
Expand Down
Loading

0 comments on commit 0c2fa98

Please sign in to comment.