Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Aug 22, 2023
1 parent c4013e6 commit fd1e871
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 88 deletions.
106 changes: 20 additions & 86 deletions .github/workflows/media_proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ 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
Expand All @@ -67,77 +66,12 @@ jobs:
role-duration-seconds: 3600
aws-region: ap-southeast-1

- name: Build image
uses: aws-actions/aws-codebuild-run-build@v1
- name: Login to AWS Public ECR
uses: docker/login-action@v2
with:
project-name: somleng-switch-${{ matrix.platform }}
buildspec-override: |
version: 0.2
phases:
install:
commands:
# Temp fix: Remove this install phase. See: https://github.com/aws/aws-codebuild-docker-images/pull/642
- export BUILDX_VERSION=$(curl --silent "https://api.github.com/repos/docker/buildx/releases/latest" |jq -r .tag_name)
- curl -JLO "https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.linux-${{ matrix.platform }}"
- mkdir -p ~/.docker/cli-plugins
- mv "buildx-$BUILDX_VERSION.linux-${{ matrix.platform }}" ~/.docker/cli-plugins/docker-buildx
- chmod +x ~/.docker/cli-plugins/docker-buildx
build:
steps:
- name: Build
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
export DOCKER_BUILDKIT=1
cd components/media_proxy
docker build --cache-from ${{ env.ECR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-${{ matrix.platform }} --tag ${{ env.ECR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-${{ matrix.platform }} --push .
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@v2
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@v2

- name: Build Manifest
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
declare -a platforms=("amd64" "arm64")
source_images=$(printf "${{ env.ECR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-%s " "${platforms[@]}")
docker buildx imagetools create -t ${{ env.ECR_REGISTRY }}/media-proxy:${{ matrix.image_tag }} -t ${{ env.ECR_REGISTRY }}/media-proxy:${{ env.IMAGE_TAG }} $source_images
# Do this step in Github Actions because pushing to Github from AWS CodeBuild is slow
publish_images:
name: Publish Images
runs-on: ubuntu-latest

needs:
- build
- build-packages

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

steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
registry: ${{ env.ECR_PUBLIC_REGISTRY }}
env:
AWS_REGION: us-east-1

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
Expand All @@ -146,32 +80,32 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Images
run: |
declare -a platforms=("amd64" "arm64")
for platform in "${platforms[@]}"
do
docker image pull ${{ env.ECR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-$platform
docker tag ${{ env.ECR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-$platform ${{ env.GHCR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-$platform
docker push ${{ env.GHCR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-$platform
done
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

source_images=$(printf "${{ env.GHCR_REGISTRY }}/media-proxy:${{ matrix.image_tag }}-%s " "${platforms[@]}")
docker buildx imagetools create -t ${{ env.GHCR_REGISTRY }}/media-proxy:${{ matrix.image_tag }} $source_images
- name: Build and push Media Proxy
uses: docker/build-push-action@v4
with:
context: components/media_proxy
push: true
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 }}
deploy:
name: Deploy
runs-on: ubuntu-latest
if: needs.build.outputs.matrixLength > 0
defaults:
run:
working-directory: components/media_proxy

needs:
- build
- build-manifest

if: needs.build.outputs.matrixLength > 0
- build-packages

strategy:
matrix: ${{fromJson(needs.build.outputs.matrix)}}
Expand Down
2 changes: 0 additions & 2 deletions infrastructure/modules/somleng_switch/media_proxy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module media_proxy_container_instances {
instance_subnets = var.vpc.public_subnets
associate_public_ip_address = true
cluster_name = aws_ecs_cluster.cluster.name
instance_type = "t4g.small"
architecture = "arm64"
max_capacity = var.media_proxy_max_tasks * 2
user_data = var.assign_media_proxy_eips ? [
{
Expand Down

0 comments on commit fd1e871

Please sign in to comment.