infra: preview branches use self hosting #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker Images for Preview Branches | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
concurrency: | |
group: pr-${{ github.event.pull_request.number }}-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: blacksmith-2vcpu-ubuntu-2204 | |
- service: client | |
runner: blacksmith-4vcpu-ubuntu-2204 # no speed benefit of 4vcpu, 2vcpu runs out of memory | |
- service: connection | |
runner: blacksmith-2vcpu-ubuntu-2204 | |
- service: files | |
runner: blacksmith-2vcpu-ubuntu-2204 | |
- service: multiplayer | |
runner: blacksmith-2vcpu-ubuntu-2204 | |
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 | |
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: | |
driver-opts: | | |
image=moby/buildkit:latest | |
network=host | |
- name: Build and push | |
uses: useblacksmith/build-push-action@v1 | |
with: | |
context: . | |
file: quadratic-${{ matrix.service }}/Dockerfile | |
push: true | |
tags: ${{ steps.create-ecr.outputs.ECR_URL }}:pr-${{ github.event.pull_request.number }} | |
build-args: | | |
BUILDKIT_INLINE_CACHE=1 | |
BUILD_TIME=${{ steps.build-metadata.outputs.BUILD_TIME }} | |
GIT_SHA=${{ github.sha }} | |
BRANCH_NAME=${{ steps.build-metadata.outputs.BRANCH_NAME }} | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
labels: | | |
org.opencontainers.image.created=${{ steps.build-metadata.outputs.BUILD_TIME }} | |
org.opencontainers.image.revision=${{ github.sha }} |