Skip to content

Commit

Permalink
Fix docker tagging (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie authored Sep 20, 2024
1 parent fe7e144 commit ce9646f
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 92 deletions.
1 change: 1 addition & 0 deletions .github/workflows/client_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ jobs:
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}
tags: |
${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }}
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-amd64
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}
deploy:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/gateway_commons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ jobs:
with:
context: components/opensips_scheduler
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
cache-from: type=gha,scope=${{ matrix.identifier }}-gateway-scheduler
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-gateway-scheduler
tags: |
${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_REPOSITORY_NAME }}:${{ matrix.image_tag }}
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-amd64
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_SCHEDULER_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}
- name: Build and push Gateway
Expand All @@ -100,4 +101,5 @@ jobs:
cache-from: type=gha,scope=${{ matrix.identifier }}-gateway
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}-gateway
tags: |
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:bootstrap-amd64
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:bootstrap
104 changes: 91 additions & 13 deletions .github/workflows/media_proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
outputs:
matrix: ${{ steps.set-deployment-matrix.outputs.matrix }}
matrixLength: ${{ steps.set-deployment-matrix.outputs.matrixLength }}
packageMatrix: ${{ steps.set-deployment-matrix.outputs.packageMatrix }}

steps:
- name: Set Deployment Matrix
Expand Down Expand Up @@ -41,17 +42,19 @@ jobs:
matrix=$(echo $matrixSource | jq --arg branchName "$branchName" 'map(. | select((.branch==$branchName)) )')
echo "matrix={\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
echo "matrixLength=$(echo $matrix | jq length)" >> $GITHUB_OUTPUT
echo "packageMatrix={\"platform\":[\"amd64\",\"arm64\"],\"include\":$(echo $matrix)}" >> $GITHUB_OUTPUT
build-packages:
name: Build Packages
runs-on: ubuntu-latest

if: needs.build.outputs.matrixLength > 0

needs:
- build

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

steps:
- name: Checkout
Expand All @@ -67,6 +70,80 @@ jobs:
role-duration-seconds: 3600
aws-region: ap-southeast-1

- name: Build images
uses: aws-actions/aws-codebuild-run-build@v1
with:
project-name: somleng-switch-${{ matrix.platform }}
buildspec-override: |
version: 0.2
phases:
build:
steps:
- name: Build
run: |
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 ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-${{ matrix.platform }} --tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-${{ matrix.platform }} --push components/media_proxy
build-manifest:
name: Build Manifest
runs-on: ubuntu-latest

needs:
- build
- build-packages

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

steps:
- name: Configure AWS credentials
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: 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 Manifest
run: |
declare -a platforms=("amd64" "arm64")
source_images=$(printf "${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-%s " "${platforms[@]}")
docker buildx imagetools create -t ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} -t ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }} $source_images
publish_images:
name: Publish Images
runs-on: ubuntu-latest

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

needs:
- build
- build-packages


steps:
- name: Configure AWS credentials
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: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -82,17 +159,18 @@ jobs:
with:
registry: ${{ secrets.ECR_REGISTRY }}

- name: Build and push Media Proxy
uses: docker/build-push-action@v6
with:
context: components/media_proxy
push: true
cache-from: type=gha,scope=${{ matrix.identifier }}
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}
platforms: linux/amd64,linux/arm64
tags: |
${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.image_tag }}
${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}
- name: Publish Images
run: |
declare -a platforms=("amd64" "arm64")
for platform in "${platforms[@]}"
do
docker image pull ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-$platform
docker tag ${{ secrets.ECR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-$platform ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-$platform
docker push ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-$platform
done
source_images=$(printf "${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-%s " "${platforms[@]}")
docker buildx imagetools create -t ${{ secrets.GHCR_REGISTRY }}/${{ env.REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }} $source_images
deploy:
name: Deploy
Expand All @@ -101,7 +179,7 @@ jobs:

needs:
- build
- build-packages
- build-manifest

strategy:
matrix: ${{fromJson(needs.build.outputs.matrix)}}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/public_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
cache-to: type=gha,mode=max,scope=${{ matrix.identifier }}
tags: |
${{ secrets.ECR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.image_tag }}
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}-amd64
${{ secrets.GHCR_REGISTRY }}/${{ env.GATEWAY_REPOSITORY_NAME }}:${{ matrix.friendly_image_tag }}
deploy:
Expand Down
Loading

0 comments on commit ce9646f

Please sign in to comment.