Skip to content

infra: preview branches use self hosting #17

infra: preview branches use self hosting

infra: preview branches use self hosting #17

name: Build Docker Images for Preview Branches
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ${{ github.head_ref }}-build-images
cancel-in-progress: true
jobs:
build_images:
permissions:
contents: read
timeout-minutes: 30
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- service: api
runner: ubuntu-latest-8-cores
- service: client
runner: ubuntu-latest-64-cores
- service: connection
runner: ubuntu-latest-8-cores
- service: files
runner: ubuntu-latest-8-cores
- service: multiplayer
runner: ubuntu-latest-8-cores
fail-fast: true
steps:
- uses: actions/checkout@v4
- name: Generate Build Metadata
id: build-metadata
run: |
echo "BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "GIT_SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "BRANCH_NAME=$(echo "${{ github.head_ref }}" | tr '/' '-')" >> $GITHUB_OUTPUT
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR Private
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Define repository name
id: repo-name
run: |
echo "REPO_NAME=quadratic-${{ matrix.service }}-development" >> $GITHUB_OUTPUT
- name: Create Private ECR Repository if not exists
id: create-ecr
env:
REPO_NAME: ${{ steps.repo-name.outputs.REPO_NAME }}
run: |
# Try to describe the repository first
if ! aws ecr describe-repositories --repository-names $REPO_NAME 2>/dev/null; then
# Repository doesn't exist, create it
aws ecr create-repository --repository-name $REPO_NAME || true
fi
# Get the repository URI either way
REPO_INFO=$(aws ecr describe-repositories --repository-names $REPO_NAME)
ECR_URL=$(echo $REPO_INFO | jq -r '.repositories[0].repositoryUri')
echo "ECR_URL=$ECR_URL" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Build, Tag, and Push Image to Amazon ECR Private
env:
ECR_URL: ${{ steps.create-ecr.outputs.ECR_URL }}
run: |
docker buildx build \
--cache-from=type=registry,ref=$ECR_URL:buildcache \
--cache-to=type=registry,ref=$ECR_URL:buildcache,mode=max \
--build-arg BUILD_TIME="${{ steps.build-metadata.outputs.BUILD_TIME }}" \
--build-arg GIT_SHA="${{ github.sha }}" \
--build-arg PR_NUMBER="${{ github.event.pull_request.number }}" \
--label "org.opencontainers.image.created=${{ steps.build-metadata.outputs.BUILD_TIME }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--push \
-t $ECR_URL:pr-${{ github.event.pull_request.number }} \
-f quadratic-${{ matrix.service }}/Dockerfile .