Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: preview branches use self hosting #2140

Draft
wants to merge 49 commits into
base: qa
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
cdbb72f
build images on pr open/push
AyushAgrawal-A2 Dec 20, 2024
f7d6910
fix branch name
AyushAgrawal-A2 Dec 20, 2024
e80308a
create cache directory
AyushAgrawal-A2 Dec 20, 2024
997c4f6
init cache dir
AyushAgrawal-A2 Dec 20, 2024
4cd4859
cache init bug
AyushAgrawal-A2 Dec 20, 2024
51f6334
fix private ecr login
AyushAgrawal-A2 Dec 20, 2024
037d36f
use existing ecr repo
AyushAgrawal-A2 Dec 20, 2024
e297eb4
try ecr public
AyushAgrawal-A2 Dec 20, 2024
c880b63
use us-east-1 for public gallery
AyushAgrawal-A2 Dec 20, 2024
8fc918b
try 64 cores
AyushAgrawal-A2 Dec 20, 2024
6ea1712
increase timeout
AyushAgrawal-A2 Dec 20, 2024
24a44dc
try 64 again
AyushAgrawal-A2 Dec 20, 2024
7802f17
4 core
AyushAgrawal-A2 Dec 20, 2024
44a3861
try blacksmith
AyushAgrawal-A2 Dec 21, 2024
06eed50
blacksmith 32 core
AyushAgrawal-A2 Dec 21, 2024
6395c9f
try changing build script
AyushAgrawal-A2 Dec 21, 2024
a6bf30f
revert changes, add cache
AyushAgrawal-A2 Dec 21, 2024
ce65f36
try
AyushAgrawal-A2 Dec 21, 2024
cb04f4b
try
AyushAgrawal-A2 Dec 21, 2024
7dc5f3c
try caching again
AyushAgrawal-A2 Dec 21, 2024
5e04cf7
build image caching done
AyushAgrawal-A2 Dec 21, 2024
23413df
fix api dockerfile
AyushAgrawal-A2 Dec 21, 2024
bbe0cab
really fix api dockerfile
AyushAgrawal-A2 Dec 21, 2024
9d00b87
try BuildKit inline cache
AyushAgrawal-A2 Dec 21, 2024
1f61596
more cache trial and blacksmith 2 core
AyushAgrawal-A2 Dec 21, 2024
49bd52d
reduce docker layers, use package scripts
AyushAgrawal-A2 Dec 21, 2024
167c702
try blacksmith 2 core for other services
AyushAgrawal-A2 Dec 21, 2024
7b41e43
try blacksmith cache
AyushAgrawal-A2 Dec 21, 2024
f2a27f2
add cache compression
AyushAgrawal-A2 Dec 21, 2024
3e137c4
try default compression level
AyushAgrawal-A2 Dec 21, 2024
92a8728
revert to max cache compression
AyushAgrawal-A2 Dec 21, 2024
1473500
reduce build layer of connections, files and multiplayer
AyushAgrawal-A2 Dec 21, 2024
3cd98ee
fix docker ignore
AyushAgrawal-A2 Dec 22, 2024
63d33b2
seperate TS and rust layers
AyushAgrawal-A2 Dec 22, 2024
ebc70a5
use blacksmith build and push action
AyushAgrawal-A2 Dec 22, 2024
b1f4876
prefer caching rust layers over npm dependencies
AyushAgrawal-A2 Dec 22, 2024
b51c290
add service name in tag
AyushAgrawal-A2 Dec 22, 2024
70af95b
revert: add service name in tag, cache work without it
AyushAgrawal-A2 Dec 22, 2024
8b612ae
try cloudformation from github actions
AyushAgrawal-A2 Dec 22, 2024
0384d50
trigger CI
AyushAgrawal-A2 Dec 22, 2024
deaa275
concurrency group
AyushAgrawal-A2 Dec 22, 2024
0a995cc
fix HostedZoneName
AyushAgrawal-A2 Dec 22, 2024
55c770b
fix InputTemplate
AyushAgrawal-A2 Dec 22, 2024
3155209
fix login script
AyushAgrawal-A2 Dec 22, 2024
e17e267
fix github comment
AyushAgrawal-A2 Dec 22, 2024
ad15f68
remove tag on ec2 profile
AyushAgrawal-A2 Dec 22, 2024
6555269
use aws-cloudformation-github-deploy action
AyushAgrawal-A2 Dec 22, 2024
74ec7ce
remove rollback and delete attributes
AyushAgrawal-A2 Dec 22, 2024
8bafe87
add write permission for comment
AyushAgrawal-A2 Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# Environment files
.env*
**/.env*

# Docker files
.dockerignore
**/.dockerignore
Dockerfile*
**/Dockerfile*
docker-compose*
**/docker-compose*

# Build outputs
build/
**/build/
dist/
**/dist/
target/
**/target/
**/target/

# Dependencies
node_modules/
**/node_modules/
vendor/
**/vendor/

# Version control
.git/
.gitignore
.gitattributes

# IDE and editor files
.idea/
.vscode/
*.swp
*.swo
.DS_Store

# TS/Rust types, this is generated during the build process
quadratic-client/src/app/quadratic-core/
quadratic-client/src/app/quadratic-core-types/
quadratic-client/src/app/quadratic-rust-client/
64 changes: 64 additions & 0 deletions .github/workflows/preview-cloudformation-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Deploy to AWS CloudFormation - Preview

on:
pull_request:
types: [opened, synchronize, reopened]

concurrency:
group: pr-${{ github.event.pull_request.number }}-deploy-cloudformation

jobs:
deploy_cloudformation:
permissions:
contents: read
id-token: write
pull-requests: write

runs-on: blacksmith-2vcpu-ubuntu-2204

env:
STACK_NAME: pr-${{ github.event.pull_request.number }}

steps:
- uses: actions/checkout@v4

- 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: Deploy CloudFormation Stack
id: deploy-stack
uses: aws-actions/aws-cloudformation-github-deploy@v1
with:
name: ${{ env.STACK_NAME }}
template: infra/aws-cloudformation/preview.yml
parameter-overrides: >-
LicenseKey=5a32bd8a-409e-4733-8846-1868c568a813,
ImageTag=pr-${{ github.event.pull_request.number }}
capabilities: CAPABILITY_IAM
no-fail-on-empty-changeset: "1"
disable-rollback: false
termination-protection: false

- name: Find Comment
uses: peter-evans/find-comment@v3
id: preview-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'Preview Deployment'

- name: Create or update comment
if: steps.deploy-stack.outputs.DnsRecord != ''
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.preview-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Preview Deployment
Preview URL: https://${{ steps.deploy-stack.outputs.DnsRecord }}
edit-mode: replace

99 changes: 99 additions & 0 deletions .github/workflows/preview-publish-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Build and Publish Images to ECR - Preview

on:
pull_request:
types: [opened, synchronize, reopened]

concurrency:
group: pr-${{ github.event.pull_request.number }}-publish-images
cancel-in-progress: true

jobs:
publish_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 }}-${{ steps.build-metadata.outputs.GIT_SHA_SHORT }}
build-args: |
BUILDKIT_INLINE_CACHE=1
BUILD_TIME=${{ steps.build-metadata.outputs.BUILD_TIME }}
GIT_SHA_SHORT=${{ steps.build-metadata.outputs.GIT_SHA_SHORT }}
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=${{ steps.build-metadata.outputs.GIT_SHA_SHORT }}
85 changes: 42 additions & 43 deletions .github/workflows/production-publish-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Build and Publish Images to ECR
on:
push:
branches:
- self-hosting-setup #remove
- main

concurrency:
Expand All @@ -16,45 +15,45 @@ jobs:
matrix:
service: [multiplayer, files, connection, client, api]
steps:
- uses: actions/checkout@v4

- 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 }}
aws-region: us-east-1

- name: Login to Amazon ECR Public
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Define repository name
id: repo-name
run: |
echo "REPO_NAME=quadratic-${{ matrix.service }}" >> $GITHUB_OUTPUT

- name: Create Public ECR Repository if not exists
id: create-ecr
env:
REPO_NAME: ${{ steps.repo-name.outputs.REPO_NAME }}
run: |
aws ecr-public create-repository --repository-name $REPO_NAME || true
REPO_INFO=$(aws ecr-public describe-repositories --repository-names $REPO_NAME)
ECR_URL=$(echo $REPO_INFO | jq -r '.repositories[0].repositoryUri')
echo "ECR_URL=$ECR_URL" >> $GITHUB_OUTPUT
- name: Read VERSION file
id: version
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_OUTPUT

- name: Build, Tag, and Push Image to Amazon ECR Public
env:
ECR_URL: ${{ steps.create-ecr.outputs.ECR_URL }}
IMAGE_TAG: ${{ steps.version.outputs.VERSION }}
run: |
docker build -t $ECR_URL:$IMAGE_TAG -t $ECR_URL:latest -f quadratic-${{ matrix.service }}/Dockerfile .
docker push $ECR_URL:$IMAGE_TAG
docker push $ECR_URL:latest
- uses: actions/checkout@v4

- 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 }}
aws-region: us-east-1

- name: Login to Amazon ECR Public
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

- name: Define repository name
id: repo-name
run: |
echo "REPO_NAME=quadratic-${{ matrix.service }}" >> $GITHUB_OUTPUT

- name: Create Public ECR Repository if not exists
id: create-ecr
env:
REPO_NAME: ${{ steps.repo-name.outputs.REPO_NAME }}
run: |
aws ecr-public create-repository --repository-name $REPO_NAME || true
REPO_INFO=$(aws ecr-public describe-repositories --repository-names $REPO_NAME)
ECR_URL=$(echo $REPO_INFO | jq -r '.repositories[0].repositoryUri')
echo "ECR_URL=$ECR_URL" >> $GITHUB_OUTPUT

- name: Read VERSION file
id: version
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_OUTPUT

- name: Build, Tag, and Push Image to Amazon ECR Public
env:
ECR_URL: ${{ steps.create-ecr.outputs.ECR_URL }}
IMAGE_TAG: ${{ steps.version.outputs.VERSION }}
run: |
docker build -t $ECR_URL:$IMAGE_TAG -t $ECR_URL:latest -f quadratic-${{ matrix.service }}/Dockerfile .
docker push $ECR_URL:$IMAGE_TAG
docker push $ECR_URL:latest
16 changes: 15 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
"editor.formatOnSave": true,
"cSpell.words": [
"actix",
"awscliv",
"ayush",
"bigdecimal",
"bincode",
"bindgen",
"buildkit",
"Buildx",
"containerd",
"CRPXNLSKVLJFHH",
"dashmap",
"dbgjs",
"dcell",
"ddimaria",
"dearmor",
"dgraph",
"dotenv",
"dpkg",
"endregion",
"finitize",
"Fuzzysort",
Expand All @@ -29,9 +35,11 @@
"indicies",
"itertools",
"jwks",
"keyrings",
"MDSL",
"micropip",
"minmax",
"moby",
"msdf",
"nonblank",
"Northbridge",
Expand All @@ -48,6 +56,8 @@
"relcells",
"reqwest",
"scrollend",
"selfhost",
"selfhosted",
"shadcn",
"Signin",
"smallpop",
Expand All @@ -59,9 +69,13 @@
"trackpad",
"undoable",
"unspill",
"useblacksmith",
"usermod",
"vals",
"vcpu",
"websockets",
"Westborough"
"Westborough",
"zstd"
],
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading