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

Move off lambda and to ECS #4026

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fac93bb
Move off lambda and to ECS
marcoacierno Sep 1, 2024
b3483b4
change test
marcoacierno Sep 1, 2024
1ecca8a
test
marcoacierno Sep 1, 2024
60959a2
s
marcoacierno Sep 2, 2024
963c982
changes
marcoacierno Sep 5, 2024
1170238
test
marcoacierno Sep 5, 2024
3760d50
changes
marcoacierno Sep 6, 2024
bc76668
pretix arm
marcoacierno Sep 6, 2024
b548a1f
changes
marcoacierno Sep 6, 2024
bb394f4
changes
marcoacierno Sep 6, 2024
51cda1c
test
marcoacierno Sep 6, 2024
4bad797
c
marcoacierno Sep 6, 2024
95b47b1
aa
marcoacierno Sep 6, 2024
f0199f1
c
marcoacierno Sep 6, 2024
f64a2ed
fix
marcoacierno Sep 6, 2024
e46b22d
change
marcoacierno Sep 7, 2024
b9e23cb
c
marcoacierno Sep 7, 2024
1c19b83
test
marcoacierno Sep 7, 2024
e81e891
a
marcoacierno Sep 7, 2024
9af5888
t
marcoacierno Sep 7, 2024
ef6ee7f
change
marcoacierno Sep 7, 2024
1a440cc
a
marcoacierno Sep 7, 2024
5c23660
c
marcoacierno Sep 7, 2024
6303b59
ee
marcoacierno Sep 7, 2024
15e0e71
ee
marcoacierno Sep 7, 2024
ab7685d
ee
marcoacierno Sep 7, 2024
ea6a51c
ee
marcoacierno Sep 7, 2024
f7238d7
ee
marcoacierno Sep 7, 2024
00c8d2d
ee
marcoacierno Sep 7, 2024
32c6d28
ee
marcoacierno Sep 7, 2024
95815a3
ee
marcoacierno Sep 7, 2024
277ff08
ee
marcoacierno Sep 7, 2024
75d2b69
ee
marcoacierno Sep 8, 2024
6f051b8
ee
marcoacierno Sep 8, 2024
335ab98
ee
marcoacierno Sep 8, 2024
ec5e252
ee
marcoacierno Sep 8, 2024
5ac736f
ee
marcoacierno Sep 8, 2024
6734180
ee
marcoacierno Sep 8, 2024
e09e892
ee
marcoacierno Sep 8, 2024
1118643
ee
marcoacierno Sep 8, 2024
54e17f1
ee
marcoacierno Sep 8, 2024
9ea7654
ee
marcoacierno Sep 8, 2024
6da5d2f
ee
marcoacierno Sep 8, 2024
62ff044
ee
marcoacierno Sep 8, 2024
3f7ef70
ee
marcoacierno Sep 8, 2024
650f749
ee
marcoacierno Sep 8, 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
69 changes: 30 additions & 39 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,17 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1

build-and-push-service:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

strategy:
fail-fast: false
matrix:
service:
- name: pycon-backend
dir: backend
- name: pretix
dir: pretix

build-pretix:
runs-on: [self-hosted]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- uses: actions/checkout@v4
with:
repository: pretix/pretix
ref: v2024.8.0
path: ./pretix-clone
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -79,56 +70,56 @@ jobs:
- name: Get service githash
id: git
run: |
hash=$(git rev-list -1 HEAD -- ${{ matrix.service.dir }})
hash=$(git rev-list -1 HEAD -- pretix)
echo "githash=$hash" >> $GITHUB_OUTPUT
- name: Check if commit is already on ECR
id: image
run: |
set +e
aws ecr describe-images --repository-name=pythonit/${{ matrix.service.name }} --image-ids=imageTag=${{ steps.git.outputs.githash }}
aws ecr describe-images --repository-name=pythonit/pretix --image-ids=imageTag=arm-${{ steps.git.outputs.githash }}
if [[ $? == 0 ]]; then
echo "image_exists=1" >> $GITHUB_OUTPUT
else
echo "image_exists=0" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU dependency
if: ${{ steps.image.outputs.image_exists == 0 }}
uses: docker/setup-qemu-action@v3
- name: Login to GitHub Packages
if: ${{ steps.image.outputs.image_exists == 0 }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Amazon ECR
if: ${{ steps.image.outputs.image_exists == 0 }}
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
id: buildx
if: ${{ steps.image.outputs.image_exists == 0 }}
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
- name: Build pretix base
if: ${{ steps.image.outputs.image_exists == 0 }}
uses: actions/cache@v4
uses: docker/build-push-action@v6
id: build-pretix-base
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.service.name }}
- name: Build and push
context: ./pretix-clone
file: ./pretix-clone/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
provenance: false
push: true
tags: |
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/pythonit/pretix:pretix-base-${{ steps.git.outputs.githash }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
platforms: linux/arm64
- name: Build and push pretix
if: ${{ steps.image.outputs.image_exists == 0 }}
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.service.dir }}
file: ./${{ matrix.service.dir }}/Dockerfile
context: ./pretix
file: ./pretix/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
provenance: false
push: true
tags: |
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/pythonit/${{ matrix.service.name }}:${{ steps.git.outputs.githash }}
ghcr.io/pythonitalia/pycon/${{ matrix.service.name }}:${{ steps.git.outputs.githash }}
${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/pythonit/pretix:arm-${{ steps.git.outputs.githash }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
platforms: linux/amd64
platforms: linux/arm64
build-args: |
PRETIX_IMAGE=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/pythonit/pretix:pretix-base-${{ steps.git.outputs.githash }}

build-and-push-arm-service:
runs-on: [self-hosted]
Expand Down Expand Up @@ -226,7 +217,7 @@ jobs:

terraform:
runs-on: ubuntu-latest
needs: [build-emails, build-and-push-service, build-and-push-arm-service, create-db]
needs: [build-emails, build-and-push-arm-service, build-pretix, create-db]
environment:
name: ${{ fromJSON('["pastaporto", "production"]')[github.ref == 'refs/heads/main'] }}
defaults:
Expand Down
2 changes: 2 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ ARG FUNCTION_DIR

WORKDIR ${FUNCTION_DIR}

RUN apt-get update -y && apt install -y curl

COPY --from=js-stage ${FUNCTION_DIR}/dist/*.html ${FUNCTION_DIR}/custom_admin/templates/astro/
COPY --from=js-stage ${FUNCTION_DIR}/dist/_astro ${FUNCTION_DIR}/custom_admin/static/_astro/

Expand Down
2 changes: 1 addition & 1 deletion backend/custom_admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib import admin
from django.urls import path

SITE_NAME = "PyCon Italia"
SITE_NAME = "Change Test PyCon Italia"

admin.site.site_header = SITE_NAME
admin.site.site_title = SITE_NAME
Expand Down
34 changes: 17 additions & 17 deletions infrastructure/applications/.terraform.lock.hcl

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

15 changes: 15 additions & 0 deletions infrastructure/applications/applications.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ module "emails" {
aws.us = aws.us
}
}

module "server" {
source = "./server"
ecs_arm_ami = local.ecs_arm_ami

providers = {
aws = aws
aws.us = aws.us
}
}

module "pretix_arm" {
source = "./pretix_arm"
ecs_arm_ami = local.ecs_arm_ami
}
2 changes: 1 addition & 1 deletion infrastructure/applications/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.64.0"
version = "5.66.0"
configuration_aliases = [aws.us]
}
}
Expand Down
13 changes: 13 additions & 0 deletions infrastructure/applications/pretix_arm/ecr.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
data "aws_ecr_repository" "repo" {
name = "pythonit/pretix"
}

data "aws_ecr_image" "image" {
repository_name = data.aws_ecr_repository.repo.name
image_tag = "arm-${data.external.githash.result.githash}"
}

data "external" "githash" {
program = ["python", abspath("${path.module}/githash.py")]
working_dir = abspath("${path.root}/../../pretix")
}
12 changes: 12 additions & 0 deletions infrastructure/applications/pretix_arm/githash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
import subprocess
import sys

git_output = subprocess.check_output(
["git", "rev-list", "-1", "HEAD", "--", "."],
)
githash = git_output.decode().strip()

output = {"githash": githash}
output_json = json.dumps(output)
sys.stdout.write(output_json)
3 changes: 3 additions & 0 deletions infrastructure/applications/pretix_arm/rds.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "aws_db_instance" "database" {
db_instance_identifier = "pythonit-${terraform.workspace}"
}
8 changes: 8 additions & 0 deletions infrastructure/applications/pretix_arm/s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
locals {
is_prod = terraform.workspace == "production"
}

resource "aws_s3_bucket" "media" {
bucket = "${terraform.workspace}-pretix-media"
force_destroy = !local.is_prod
}
8 changes: 8 additions & 0 deletions infrastructure/applications/pretix_arm/secrets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "secrets" {
source = "../../components/secrets"
service = "pretix"
}

module "common_secrets" {
source = "../../components/secrets"
}
Loading
Loading