-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lambda): adding in lambda building
- Loading branch information
Showing
8 changed files
with
264 additions
and
17 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: 'Re-usable Lambda Build and Upload Flow' | ||
description: 'Used to setup and build a docker image' | ||
inputs: | ||
scope: | ||
description: 'Turbo Repo scope to run the build for' | ||
required: true | ||
sentry-org: | ||
description: 'The org name used in sentry. Used to upload source maps' | ||
required: false | ||
default: pocket | ||
sentry-project: | ||
description: 'The project name used in sentry. Used to upload source maps' | ||
required: false | ||
default: '' | ||
sentry-token: | ||
description: 'The token used for sentry. Used to upload source maps' | ||
required: true | ||
s3-bucket: | ||
description: 'The s3 bucket to upload to' | ||
required: false | ||
default: '' | ||
s3-key: | ||
description: 'The s3 bucket key to upload to' | ||
required: false | ||
default: '' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Install pnpm & node | ||
uses: ./.github/actions/install-pnpm-and-node | ||
with: | ||
scope: ${{ inputs['scope'] }} | ||
# Theres a really annoying bug in PNPM deploy command that will try and create a folder at /home/pruned which we are not allowed to do, | ||
# so we move it under 1 directory to let it do its thing. | ||
# https://github.com/pnpm/pnpm/issues/5086 | ||
- name: Build lambda | ||
shell: bash | ||
run: | | ||
pnpm run build --filter=${{inputs.scope}}... | ||
mkdir -p ~/bug/project | ||
cp -R . ~/bug/project/ | ||
cd ~/bug/project/ | ||
pnpm deploy --filter=${{inputs.scope}} --prod pruned | ||
- name: Upload Sentry Source maps | ||
if: inputs.sentry-project != '' | ||
shell: bash | ||
run: | | ||
cd ~/bug/project/ | ||
pnpx @sentry/cli sourcemaps inject pruned/dist | ||
pnpx @sentry/cli sourcemaps upload pruned/dist --release ${{ github.sha }} --auth-token ${{ inputs.sentry-token }} --org ${{ inputs.sentry-org }} --project ${{ inputs.sentry-project }} | ||
- name: Package Lambda | ||
shell: bash | ||
run: | | ||
cd ~/bug/project/pruned | ||
cp -r package.json dist/ | ||
cp -r node_modules/ dist/node_modules/ | ||
cd dist | ||
zip --symlinks -r9 ~/project/${{ github.sha }}.zip . | ||
mkdir -p /tmp | ||
mkdir -p /tmp/artifacts | ||
cp ~/project/${{ github.sha }}.zip /tmp/artifacts/ | ||
cd .. | ||
maxFileSize=256000 # Get the size of the directory in kilobytes | ||
export dirSize=$(du -s dist | cut -f1) | ||
echo "Size is: $dirSize" | ||
if ((dirSize > maxFileSize)); then | ||
echo "Directory size is equal to or larger than $maxFileSize KB. which is the lambda limit" | ||
exit 1 | ||
fi | ||
- name: Upload to S3 | ||
if: inputs.s3-bucket != '' | ||
shell: bash | ||
run: | | ||
s3Key="${{inputs.s3-key}}" | ||
if [[ -z $s3Key ]]; then | ||
s3Key="${{ github.sha }}.zip" | ||
fi | ||
aws s3 cp ${{ github.sha }}.zip s3://${{inputs.s3-bucket}}/${s3Key} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Account Data Deleter | ||
on: | ||
# Only run the tests for this service when any of the following file paths change | ||
pull_request: | ||
paths: | ||
- 'infrastructure/account-data-deleter/**' | ||
- 'packages/**' | ||
- 'servers/account-data-deleter/**' | ||
- 'lambdas/account-data-deleter-batch-delete/**' | ||
- 'lambdas/account-data-deleter-events/**' | ||
- 'pnpm-lock.yaml' | ||
- '.github/actions/**' | ||
- '.github/workflows/account-data-deleter.yml' | ||
- '.github/workflows/reuse-*.yml' | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
# Let's test the service against some real life and mocked docker services. | ||
test-integrations: | ||
# Only run this job on a pull request event | ||
if: github.event_name == 'pull_request' | ||
# Use our re-usable test integrations workflow which will use our docker compose file | ||
uses: ./.github/workflows/reuse-test-integrations.yml | ||
with: | ||
# Only run the tests for our service | ||
scope: 'account-data-deleter' | ||
# Ensure the re-usable workflow is allowed to access the secrets | ||
secrets: inherit | ||
|
||
# It's infrastructure time, run the infrastructure update commands | ||
infrastructure: | ||
uses: ./.github/workflows/reuse-infrastructure.yml | ||
with: | ||
scope: account-data-deleter-api-cdk | ||
stack-output-path: infrastructure/user-api/cdktf.out/stacks/user-api | ||
# Ensure the re-usable workflow is allowed to access the secrets | ||
secrets: inherit | ||
|
||
# Let's try building and conidtionally pushing our docker image to the necessary account. | ||
build-and-push-image: | ||
uses: ./.github/workflows/reuse-build-and-push-image.yml | ||
#needs: [infrastructure] | ||
with: | ||
scope: account-data-deleter | ||
app-path: servers/account-data-deleter | ||
app-port: 4015 | ||
sentry-project: account-data-deleter | ||
docker-repo-name-short-hand: accountdatadeleter | ||
# Ensure the re-usable workflow is allowed to access the secrets | ||
secrets: inherit | ||
|
||
build-and-push-lambda-events: | ||
uses: ./.github/workflows/reuse-build-and-push-lambda.yml | ||
#needs: [infrastructure] | ||
with: | ||
scope: account-data-deleter-events | ||
sentry-project: account-data-deleter | ||
s3-bucket-pattern: pocket-accountdatadeleter-<<environment>>-sqs-event-consumer | ||
# Ensure the re-usable workflow is allowed to access the secrets | ||
secrets: inherit | ||
|
||
build-and-push-lambda-batch-delete: | ||
uses: ./.github/workflows/reuse-build-and-push-lambda.yml | ||
#needs: [infrastructure] | ||
with: | ||
scope: account-data-deleter-batch-delete | ||
sentry-project: account-data-deleter | ||
s3-bucket-pattern: pocket-accountdatadeleter-<<environment>>-batchdeletelambda | ||
# Ensure the re-usable workflow is allowed to access the secrets | ||
secrets: inherit | ||
|
||
# deploy: | ||
# needs: [infrastructure] | ||
# with: | ||
# terraform-output: ${{ needs.infrastructure.outputs.terraform-output }} | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: 'Re-usable Lambda Build Flow' | ||
on: | ||
workflow_call: | ||
inputs: | ||
scope: | ||
description: 'Turbo Repo scope to run the build for' | ||
required: true | ||
type: string | ||
s3-bucket-pattern: | ||
description: 'Lambda S3 bucket pattern to use' | ||
required: true | ||
type: string | ||
sentry-org: | ||
description: 'The org name used in sentry. Used to upload source maps' | ||
required: false | ||
type: string | ||
default: pocket | ||
sentry-project: | ||
description: 'The project name used in sentry. Used to upload source maps' | ||
required: true | ||
type: string | ||
|
||
permissions: | ||
contents: read # This is required for actions/checkout | ||
id-token: write # Access the Github JWT for AWS access | ||
|
||
|
||
jobs: | ||
# Let's build the image on every pull request just like we would on production | ||
pull-request: | ||
# Only run this job on a pull request event | ||
if: github.event_name == 'pull_request' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build Lambda | ||
uses: ./.github/actions/build-lambda | ||
with: | ||
sentry-project: ${{inputs['sentry-project']}} | ||
sentry-org: ${{inputs['sentry-org']}} | ||
sentry-token: ${{secrets.SENTRY_BEARER}} | ||
scope: ${{inputs['scope']}} | ||
|
||
# TODO: These need to request AWS ECR Credentials to push the Docker Image | ||
development: | ||
if: github.ref == 'refs/heads/dev' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build Lambda | ||
uses: ./.github/actions/build-lambda | ||
with: | ||
sentry-project: ${{inputs['sentry-project']}} | ||
sentry-org: ${{inputs['sentry-org']}} | ||
sentry-token: ${{secrets.SENTRY_BEARER}} | ||
scope: ${{inputs['scope']}} | ||
|
||
|
||
production: | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build Lambda | ||
uses: ./.github/actions/build-lambda | ||
with: | ||
sentry-project: ${{inputs['sentry-project']}} | ||
sentry-org: ${{inputs['sentry-org']}} | ||
sentry-token: ${{secrets.SENTRY_BEARER}} | ||
scope: ${{inputs['scope']}} |
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
File renamed without changes.
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