diff --git a/.github/workflows/cleanup-packages.yml b/.github/workflows/cleanup-packages.yml new file mode 100644 index 000000000..87ad64c63 --- /dev/null +++ b/.github/workflows/cleanup-packages.yml @@ -0,0 +1,76 @@ +name: Cleanup Packages + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + cleanup_packages: + runs-on: ubuntu-latest + + steps: + - uses: actions/delete-package-versions@v5 + with: + package-name: 's3-mpeg' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'switch-services' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'media-proxy' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'client-gateway' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'public-gateway' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'gateway' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'gateway-scheduler' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'switch-app' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'switch-webserver' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'freeswitch' + package-type: 'container' + delete-only-untagged-versions: 'true' + + - uses: actions/delete-package-versions@v5 + with: + package-name: 'freeswitch-events' + package-type: 'container' + delete-only-untagged-versions: 'true' diff --git a/.github/workflows/client_gateway.yml b/.github/workflows/client_gateway.yml index a7b449dc1..d700d5d7e 100644 --- a/.github/workflows/client_gateway.yml +++ b/.github/workflows/client_gateway.yml @@ -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 @@ -27,14 +32,16 @@ jobs: { "identifier": "client-gateway-staging", "branch": "develop", - "image_tag": "staging", + "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" } @@ -42,30 +49,17 @@ jobs: 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)}} @@ -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 @@ -99,11 +89,10 @@ 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: ${{ secrets.ECR_REGISTRY }} - name: Build and push Client Gateway uses: docker/build-push-action@v6 @@ -115,21 +104,42 @@ 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 }} + ${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.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: ${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Prepare task definition id: render-task-def @@ -137,7 +147,7 @@ jobs: with: task-definition: ${{ steps.render-opensips-scheduler-task-def.outputs.task-definition }} container-name: client_gateway - image: ${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Deploy uses: aws-actions/amazon-ecs-deploy-task-definition@v2 diff --git a/.github/workflows/gateway_commons.yml b/.github/workflows/gateway_commons.yml index 6015b406c..d4c394f2a 100644 --- a/.github/workflows/gateway_commons.yml +++ b/.github/workflows/gateway_commons.yml @@ -1,5 +1,8 @@ name: Gateway Commons on: push +env: + GATEWAY_REPOSITORY_NAME: gateway + GATEWAY_SCHEDULER_REPOSITORY_NAME: gateway-scheduler jobs: build: @@ -19,12 +22,14 @@ jobs: { "identifier": "gateway-commons-staging", "branch": "develop", - "image_tag": "staging" + "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 @@ -33,34 +38,22 @@ 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)}} + needs: + - build + steps: - name: Checkout uses: actions/checkout@v4 - name: Configure AWS credentials - id: aws-login uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} @@ -70,12 +63,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 @@ -84,34 +73,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: ${{ secrets.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 }} + ${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_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 + ${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:bootstrap diff --git a/.github/workflows/media_proxy.yml b/.github/workflows/media_proxy.yml index 6e7f6bfee..8c01150a1 100644 --- a/.github/workflows/media_proxy.yml +++ b/.github/workflows/media_proxy.yml @@ -2,9 +2,7 @@ name: Media Proxy on: push env: - IMAGE_TAG: ${{ github.sha }} - ECR_REGISTRY: public.ecr.aws/somleng - GHCR_REGISTRY: ghcr.io/somleng + REPOSITORY_NAME: media-proxy jobs: build: @@ -24,14 +22,16 @@ jobs: { "identifier": "media-proxy-staging", "branch": "develop", - "image_tag": "staging", + "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" } @@ -47,16 +47,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 @@ -72,12 +67,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 @@ -86,8 +77,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: ${{ secrets.ECR_REGISTRY }} - name: Build and push Media Proxy uses: docker/build-push-action@v6 @@ -98,9 +91,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 }} + ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} deploy: name: Deploy @@ -136,7 +128,7 @@ jobs: with: task-definition: task-definition.json container-name: media_proxy - image: ${{ env.ECR_REGISTRY }}/media-proxy:${{ env.IMAGE_TAG }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Deploy uses: aws-actions/amazon-ecs-deploy-task-definition@v2 diff --git a/.github/workflows/public_gateway.yml b/.github/workflows/public_gateway.yml index b1effd03a..b2d2c949c 100644 --- a/.github/workflows/public_gateway.yml +++ b/.github/workflows/public_gateway.yml @@ -3,6 +3,8 @@ name: Public Gateway env: CI: true + GATEWAY_REPOSITORY_NAME: public-gateway + GATEWAY_SCHEDULER_REPOSITORY_NAME: gateway-scheduler jobs: integration_tests: @@ -29,7 +31,8 @@ jobs: { "identifier": "public-gateway-staging", "branch": "develop", - "image_tag": "staging", + "friendly_image_tag": "beta", + "image_tag": "stag-${{ github.sha }}", "ecs_service": "public-gateway-staging", "ecs_cluster": "somleng-switch-staging", "deploy": false @@ -37,7 +40,8 @@ jobs: { "identifier": "public-gateway", "branch": "master", - "image_tag": "latest", + "friendly_image_tag": "latest", + "image_tag": "prod-${{ github.sha }}", "ecs_service": "public-gateway", "ecs_cluster": "somleng-switch", "deploy": true @@ -58,19 +62,6 @@ jobs: - 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/public-gateway - GHCR_REPOSITORY: ghcr.io/somleng/public-gateway - OPENSIPS_SCHEDULER_ECR_REPOSITORY: public.ecr.aws/somleng/opensips-scheduler - IMAGE_TAG: ${{ github.sha }} strategy: matrix: ${{fromJson(needs.build.outputs.matrix)}} @@ -90,12 +81,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 @@ -104,8 +91,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: ${{ secrets.ECR_REGISTRY }} - name: Build and push Public Gateway uses: docker/build-push-action@v6 @@ -117,9 +106,8 @@ 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 }} + ${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} deploy: name: Deploy @@ -129,13 +117,6 @@ jobs: - 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)}} @@ -156,13 +137,13 @@ jobs: 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: task-definition.json container-name: opensips_scheduler - image: ${{ env.OPENSIPS_SCHEDULER_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Prepare task definition id: render-task-def @@ -170,7 +151,7 @@ jobs: with: task-definition: ${{ steps.render-opensips-scheduler-task-def.outputs.task-definition }} container-name: public_gateway - image: ${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Deploy uses: aws-actions/amazon-ecs-deploy-task-definition@v2 diff --git a/.github/workflows/s3_mpeg.yml b/.github/workflows/s3_mpeg.yml index 03f536c8b..4c3398c39 100644 --- a/.github/workflows/s3_mpeg.yml +++ b/.github/workflows/s3_mpeg.yml @@ -3,8 +3,6 @@ name: S3 MPEG env: CI: true - ECR_REGISTRY: 324279636507.dkr.ecr.ap-southeast-1.amazonaws.com - GHCR_REGISTRY: ghcr.io/somleng REPOSITORY_NAME: s3-mpeg jobs: @@ -100,10 +98,9 @@ jobs: - name: Build run: | cd components/s3_mpeg - aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }} + aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }} export DOCKER_BUILDKIT=1 - docker buildx build --cache-from ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 --push . - docker buildx imagetools create -t ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} -t ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }} ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker buildx build --cache-from ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 --push . publish_images: name: Publish Images runs-on: ubuntu-latest @@ -139,14 +136,14 @@ jobs: - name: Login to ECR uses: docker/login-action@v3 with: - registry: ${{ env.ECR_REGISTRY }} + registry: ${{ secrets.ECR_REGISTRY }} - name: Publish Images run: | - docker image pull ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 - docker tag ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 - docker push ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 - docker buildx imagetools create -t ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} "${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64" + docker image pull ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker push ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker buildx imagetools create -t ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} "${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64" deploy: name: Deploy @@ -154,19 +151,8 @@ jobs: needs: - build - build-packages - if: needs.build.outputs.matrixLength > 0 - defaults: - run: - working-directory: components/s3_mpeg - 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_REGISTRY: 324279636507.dkr.ecr.ap-southeast-1.amazonaws.com - ECR_REPOSITORY: 324279636507.dkr.ecr.ap-southeast-1.amazonaws.com/s3-mpeg - GHCR_REPOSITORY: ghcr.io/somleng/s3-mpeg - IMAGE_TAG: ${{ github.sha }} + if: needs.build.outputs.matrixLength > 0 strategy: matrix: ${{fromJson(needs.build.outputs.matrix)}} @@ -189,7 +175,7 @@ jobs: - name: Deploy Lambda run: | aws lambda update-function-code --function-name ${{ matrix.identifier }} \ - --image-uri ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 \ + --image-uri ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 \ --architectures "arm64" \ --publish - name: Create Sentry release diff --git a/.github/workflows/services.yml b/.github/workflows/services.yml index 5f1f5be35..584809903 100644 --- a/.github/workflows/services.yml +++ b/.github/workflows/services.yml @@ -3,8 +3,6 @@ name: Services env: CI: true - ECR_REGISTRY: 324279636507.dkr.ecr.ap-southeast-1.amazonaws.com - GHCR_REGISTRY: ghcr.io/somleng REPOSITORY_NAME: switch-services jobs: @@ -117,10 +115,9 @@ jobs: - name: Build run: | cd components/services - aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }} + aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }} export DOCKER_BUILDKIT=1 - docker buildx build --cache-from ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 --push . - docker buildx imagetools create -t ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} -t ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }} ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker buildx build --cache-from ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 --tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 --push . publish_images: name: Publish Images @@ -157,14 +154,14 @@ jobs: - name: Login to ECR uses: docker/login-action@v3 with: - registry: ${{ env.ECR_REGISTRY }} + registry: ${{ secrets.ECR_REGISTRY }} - name: Publish Images run: | - docker image pull ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 - docker tag ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 - docker push ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 - docker buildx imagetools create -t ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} "${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64" + docker image pull ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker push ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64 + docker buildx imagetools create -t ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} "${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-arm64" deploy: name: Deploy @@ -204,7 +201,7 @@ jobs: - name: Deploy Lambda run: | aws lambda update-function-code --function-name ${{ matrix.identifier }} \ - --image-uri ${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 \ + --image-uri ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}-arm64 \ --architectures "arm64" \ --publish diff --git a/.github/workflows/switch.yml b/.github/workflows/switch.yml index 4f577c8ef..7deb018ed 100644 --- a/.github/workflows/switch.yml +++ b/.github/workflows/switch.yml @@ -3,8 +3,6 @@ name: Switch env: CI: true - ECR_REGISTRY: 324279636507.dkr.ecr.ap-southeast-1.amazonaws.com - GHCR_REGISTRY: ghcr.io/somleng APP_REPOSITORY_NAME: switch-app WEBSERVER_REPOSITORY_NAME: switch-webserver FREESWITCH_REPOSITORY_NAME: freeswitch @@ -134,7 +132,7 @@ jobs: - name: Login to ECR uses: docker/login-action@v3 with: - registry: ${{ env.ECR_REGISTRY }} + registry: ${{ secrets.ECR_REGISTRY }} - name: Export Polly Voices run: | @@ -149,9 +147,8 @@ jobs: cache-from: type=gha,scope=${{ matrix.identifier }}-nginx cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-nginx tags: | - ${{ env.ECR_REGISTRY }}/${{ env.WEBSERVER_REPOSITORY_NAME }}:${{ matrix.image_tag }} - ${{ env.ECR_REGISTRY }}/${{ env.WEBSERVER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} - ${{ env.GHCR_REGISTRY }}/${{ env.WEBSERVER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} + ${{ secrets.ECR_REGISTRY }}/${{ env.WEBSERVER_REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.GHCR_REGISTRY }}/${{ env.WEBSERVER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} - name: Build and push FreeSWITCH uses: docker/build-push-action@v6 @@ -164,9 +161,8 @@ jobs: cache-from: type=gha,scope=${{ matrix.identifier }}-freeswitch cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-freeswitch tags: | - ${{ env.ECR_REGISTRY }}/${{ env.FREESWITCH_REPOSITORY_NAME }}:${{ matrix.image_tag }} - ${{ env.ECR_REGISTRY }}/${{ env.FREESWITCH_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} - ${{ env.GHCR_REGISTRY }}/${{ env.FREESWITCH_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} + ${{ secrets.ECR_REGISTRY }}/${{ env.FREESWITCH_REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.GHCR_REGISTRY }}/${{ env.FREESWITCH_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} - name: Build and push FreeSWITCH Event Logger uses: docker/build-push-action@v6 @@ -177,9 +173,8 @@ jobs: cache-from: type=gha,scope=${{ matrix.identifier }}-freeswitch-event-logger cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-freeswitch-event-logger tags: | - ${{ env.ECR_REGISTRY }}/${{ env.FREESWITCH_EVENT_LOGGER_REPOSITORY_NAME }}:${{ matrix.image_tag }} - ${{ env.ECR_REGISTRY }}/${{ env.FREESWITCH_EVENT_LOGGER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} - ${{ env.GHCR_REGISTRY }}/${{ env.FREESWITCH_EVENT_LOGGER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} + ${{ secrets.ECR_REGISTRY }}/${{ env.FREESWITCH_EVENT_LOGGER_REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.GHCR_REGISTRY }}/${{ env.FREESWITCH_EVENT_LOGGER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} - name: Build and push Switch App uses: docker/build-push-action@v6 @@ -190,9 +185,8 @@ jobs: cache-from: type=gha,scope=${{ matrix.identifier }} cache-to: type=gha,mode=max,scope=${{ matrix.identifier }} tags: | - ${{ env.ECR_REGISTRY }}/${{ env.APP_REPOSITORY_NAME }}:${{ matrix.image_tag }} - ${{ env.ECR_REGISTRY }}/${{ env.APP_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} - ${{ env.GHCR_REGISTRY }}/${{ env.APP_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} + ${{ secrets.ECR_REGISTRY }}/${{ env.APP_REPOSITORY_NAME }}:${{ matrix.image_tag }} + ${{ secrets.GHCR_REGISTRY }}/${{ env.APP_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} deploy: name: Deploy @@ -229,7 +223,7 @@ jobs: with: task-definition: task-definition.json container-name: nginx - image: ${{ env.ECR_REGISTRY }}/${{ env.WEBSERVER_REPOSITORY_NAME }}:${{ matrix.image_tag }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.WEBSERVER_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Prepare FreeSWITCH task definition id: render-freeswitch-task-def @@ -237,7 +231,7 @@ jobs: with: task-definition: ${{ steps.render-nginx-task-def.outputs.task-definition }} container-name: freeswitch - image: ${{ env.ECR_REGISTRY }}/${{ env.FREESWITCH_REPOSITORY_NAME }}:${{ matrix.image_tag }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.FREESWITCH_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Prepare FreeSWITCH event logger task definition id: render-freeswitch-event-logger-task-def @@ -245,7 +239,7 @@ jobs: with: task-definition: ${{ steps.render-freeswitch-task-def.outputs.task-definition }} container-name: freeswitch-event-logger - image: ${{ env.ECR_REGISTRY }}/${{ env.FREESWITCH_EVENT_LOGGER_REPOSITORY_NAME }}:${{ matrix.image_tag }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.FREESWITCH_EVENT_LOGGER_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Prepare App task definition id: render-app-task-def @@ -253,7 +247,7 @@ jobs: with: task-definition: ${{ steps.render-freeswitch-event-logger-task-def.outputs.task-definition }} container-name: app - image: ${{ env.ECR_REGISTRY }}/${{ env.APP_REPOSITORY_NAME }}:${{ matrix.image_tag }} + image: ${{ secrets.ECR_REGISTRY }}/${{ env.APP_REPOSITORY_NAME }}:${{ matrix.image_tag }} - name: Deploy Switch uses: aws-actions/amazon-ecs-deploy-task-definition@v2 diff --git a/infrastructure/core/ecr.tf b/infrastructure/core/ecr.tf index cba177479..c87562a58 100644 --- a/infrastructure/core/ecr.tf +++ b/infrastructure/core/ecr.tf @@ -67,6 +67,26 @@ resource "aws_ecrpublic_repository" "gateway" { } } +module "public_gateway_ecr_repository" { + source = "../modules/ecr_repository" + name = "public-gateway" +} + +module "client_gateway_ecr_repository" { + source = "../modules/ecr_repository" + name = "client-gateway" +} + +module "media_proxy_ecr_repository" { + source = "../modules/ecr_repository" + name = "media-proxy" +} + +module "gateway_scheduler_ecr_repository" { + source = "../modules/ecr_repository" + name = "gateway-scheduler" +} + module "app_ecr_repository" { source = "../modules/ecr_repository" name = "switch-app" diff --git a/infrastructure/core/outputs.tf b/infrastructure/core/outputs.tf index 847a15874..b15ad8746 100644 --- a/infrastructure/core/outputs.tf +++ b/infrastructure/core/outputs.tf @@ -1,17 +1,17 @@ output "public_gateway_ecr_repository" { - value = aws_ecrpublic_repository.public_gateway + value = module.public_gateway_ecr_repository } output "client_gateway_ecr_repository" { - value = aws_ecrpublic_repository.client_gateway + value = module.client_gateway_ecr_repository } output "media_proxy_ecr_repository" { - value = aws_ecrpublic_repository.media_proxy + value = module.media_proxy_ecr_repository } -output "opensips_scheduler_ecr_repository" { - value = aws_ecrpublic_repository.opensips_scheduler +output "gateway_scheduler_ecr_repository" { + value = module.gateway_scheduler_ecr_repository } output "app_ecr_repository" { diff --git a/infrastructure/production/client_gateway.tf b/infrastructure/production/client_gateway.tf index 35c1e83f1..807950d9a 100644 --- a/infrastructure/production/client_gateway.tf +++ b/infrastructure/production/client_gateway.tf @@ -11,8 +11,8 @@ module "client_gateway" { ecs_cluster = aws_ecs_cluster.this route53_zone = data.terraform_remote_state.core_infrastructure.outputs.route53_zone_somleng_org - app_image = data.terraform_remote_state.core.outputs.client_gateway_ecr_repository.repository_uri - scheduler_image = data.terraform_remote_state.core.outputs.opensips_scheduler_ecr_repository.repository_uri + app_image = data.terraform_remote_state.core.outputs.client_gateway_ecr_repository.this.repository_url + scheduler_image = data.terraform_remote_state.core.outputs.gateway_scheduler_ecr_repository.this.repository_url db_security_group = data.terraform_remote_state.core_infrastructure.outputs.db_security_group sip_port = var.sip_port diff --git a/infrastructure/production/media_proxy.tf b/infrastructure/production/media_proxy.tf index 1741b62de..4331e186f 100644 --- a/infrastructure/production/media_proxy.tf +++ b/infrastructure/production/media_proxy.tf @@ -7,5 +7,5 @@ module "media_proxy" { vpc = data.terraform_remote_state.core_infrastructure.outputs.hydrogen_region.vpc ecs_cluster = aws_ecs_cluster.this - app_image = data.terraform_remote_state.core.outputs.media_proxy_ecr_repository.repository_uri + app_image = data.terraform_remote_state.core.outputs.media_proxy_ecr_repository.this.repository_url } diff --git a/infrastructure/production/public_gateway.tf b/infrastructure/production/public_gateway.tf index 8b5d6d6dc..aec03f096 100644 --- a/infrastructure/production/public_gateway.tf +++ b/infrastructure/production/public_gateway.tf @@ -8,8 +8,8 @@ module "public_gateway" { vpc = data.terraform_remote_state.core_infrastructure.outputs.hydrogen_region.vpc ecs_cluster = aws_ecs_cluster.this - app_image = data.terraform_remote_state.core.outputs.public_gateway_ecr_repository.repository_uri - scheduler_image = data.terraform_remote_state.core.outputs.opensips_scheduler_ecr_repository.repository_uri + app_image = data.terraform_remote_state.core.outputs.public_gateway_ecr_repository.this.repository_url + scheduler_image = data.terraform_remote_state.core.outputs.gateway_scheduler_ecr_repository.this.repository_url sip_port = var.sip_port sip_alternative_port = var.sip_alternative_port diff --git a/infrastructure/staging/client_gateway.tf b/infrastructure/staging/client_gateway.tf index 5e67550a4..f2bd2bb97 100644 --- a/infrastructure/staging/client_gateway.tf +++ b/infrastructure/staging/client_gateway.tf @@ -11,8 +11,8 @@ module "client_gateway" { ecs_cluster = aws_ecs_cluster.this route53_zone = data.terraform_remote_state.core_infrastructure.outputs.route53_zone_somleng_org - app_image = data.terraform_remote_state.core.outputs.client_gateway_ecr_repository.repository_uri - scheduler_image = data.terraform_remote_state.core.outputs.opensips_scheduler_ecr_repository.repository_uri + app_image = data.terraform_remote_state.core.outputs.client_gateway_ecr_repository.this.repository_url + scheduler_image = data.terraform_remote_state.core.outputs.gateway_scheduler_ecr_repository.this.repository_url min_tasks = 0 max_tasks = 2 diff --git a/infrastructure/staging/media_proxy.tf b/infrastructure/staging/media_proxy.tf index 78aae89e6..b08ce4c7a 100644 --- a/infrastructure/staging/media_proxy.tf +++ b/infrastructure/staging/media_proxy.tf @@ -7,7 +7,7 @@ module "media_proxy" { aws_region = var.aws_default_region vpc = data.terraform_remote_state.core_infrastructure.outputs.hydrogen_region.vpc ecs_cluster = aws_ecs_cluster.this - app_image = data.terraform_remote_state.core.outputs.media_proxy_ecr_repository.repository_uri + app_image = data.terraform_remote_state.core.outputs.media_proxy_ecr_repository.this.repository_url min_tasks = 0 max_tasks = 2 diff --git a/infrastructure/staging/public_gateway.tf b/infrastructure/staging/public_gateway.tf index 6b304f5b3..c153d3593 100644 --- a/infrastructure/staging/public_gateway.tf +++ b/infrastructure/staging/public_gateway.tf @@ -9,8 +9,8 @@ module "public_gateway" { ecs_cluster = aws_ecs_cluster.this - app_image = data.terraform_remote_state.core.outputs.public_gateway_ecr_repository.repository_uri - scheduler_image = data.terraform_remote_state.core.outputs.opensips_scheduler_ecr_repository.repository_uri + app_image = data.terraform_remote_state.core.outputs.public_gateway_ecr_repository.this.repository_url + scheduler_image = data.terraform_remote_state.core.outputs.gateway_scheduler_ecr_repository.this.repository_url min_tasks = 0 max_tasks = 2