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

[DOP-4170]: Create AWS ECS Task definition to process Snooty Parser cache updates #951

Merged
merged 69 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
e07b7fc
[DOP-4170]: Create lambda and Dockerfile for custom environment
branberry Dec 8, 2023
c7183b8
[DOP-4170]: Create stack to deploy cache updater
branberry Dec 8, 2023
12b8170
[DOP-4170]: Update lambda dockerfile
branberry Dec 12, 2023
095abe4
[DOP-4170]: Update workflow
branberry Dec 12, 2023
f6805d7
[DOP-4170]: Fix typo
branberry Dec 12, 2023
22900c9
[DOP-4170]: Increase timeout
branberry Dec 12, 2023
239efe3
[DOP-4170]: Use arm 💪
branberry Dec 12, 2023
f635fc4
[DOP-4170]: Use arm 💪
branberry Dec 12, 2023
c1626e7
[DOP-4170]: Use arm64 💪
branberry Dec 12, 2023
32a006b
Merge branch 'master' into DOP-4170
branberry Dec 12, 2023
b34ff29
[DOP-4170]: Use arm64 💪
branberry Dec 12, 2023
2202f13
[DOP-4170]: Format names correctly
branberry Dec 12, 2023
4ae5813
[DOP-4170]: Revert arch
branberry Dec 12, 2023
bf54b45
[DOP-4170]: Log event
branberry Dec 12, 2023
42f9a55
[DOP-4170]: Add git
branberry Dec 12, 2023
cee1b5a
[DOP-4170]: Clone repo and run cache build
branberry Dec 12, 2023
eea1dc6
[DOP-4170]: Refactor pipeline a bit
branberry Dec 12, 2023
66d70ee
[DOP-4170]: Add credentials
branberry Dec 12, 2023
b0e1cb2
[DOP-4170]: Refactor each step into a separate function for simplicity
branberry Dec 13, 2023
0c4ac5d
[DOP-4170]: Refactor each step into a separate function for simplicity
branberry Dec 13, 2023
9cec7db
[DOP-4170]: Clone to tmp directory
branberry Dec 13, 2023
670e751
[DOP-4170]: Update dependencies
branberry Dec 13, 2023
ed72ef7
[DOP-4170]: Add S3 and uploadCache starting code
branberry Dec 13, 2023
69842d3
[DOP-4170]: Small changes
branberry Dec 13, 2023
bee1ed4
[DOP-4170]: Add s3 upload library
branberry Dec 14, 2023
01a9d71
[DOP-4170]: Add cache upload
branberry Dec 14, 2023
6d6a891
[DOP-4170]: Add try catch
branberry Dec 18, 2023
b56ee4c
[DOP-4170]: Update snooty parser version
branberry Jan 2, 2024
81e481c
[DOP-4170]: Reorder no caching flag
branberry Jan 2, 2024
78c4b07
[DOP-4170]: Use latest snooty parser version
branberry Jan 3, 2024
ed5ab71
[DOP-4170]: Refactor caching
branberry Jan 3, 2024
27db8f0
[DOP-4170]: Use debugging snooty branch
branberry Jan 3, 2024
8645e7b
[DOP-4170]: Use worker instead of lambda
branberry Jan 3, 2024
46e0aa4
[DOP-4170]: Add fargate task def and custer
branberry Jan 4, 2024
fc10500
[DOP-4170]: Refactor cache updater to be used for ecs task
branberry Jan 5, 2024
ccb9f7e
[DOP-4170]: Clean up
branberry Jan 5, 2024
491cb8c
[DOP-4170]: Clean up
branberry Jan 5, 2024
f8eeb4a
[DOP-4170]: Move cache updater to src directory and add logic to buil…
branberry Jan 8, 2024
6ca4987
[DOP-4170]: Add readme and refactor cdk constructs
branberry Jan 8, 2024
9536fb3
Resolve merge conflicts
branberry Jan 8, 2024
05170bb
[DOP-4170]: Add VPC for cache updater stack
branberry Jan 8, 2024
09e2d45
[DOP-4170]: Üse correct path
branberry Jan 8, 2024
b7a3fd5
[DOP-4170]: Üse correct path
branberry Jan 8, 2024
192c8b8
[DOP-4170]: Update cpu architecture
branberry Jan 8, 2024
0747354
[DOP-4170]: Add QEMU
branberry Jan 8, 2024
1b515c5
[DOP-4170]: Add Snooty parser version
branberry Jan 8, 2024
42fd7b4
[DOP-4170]: Don't use arm
branberry Jan 8, 2024
1956316
[DOP-4170]: use buildkit action
branberry Jan 8, 2024
06389e9
[DOP-4170]: Remove buildkit setup
branberry Jan 8, 2024
728b779
[DOP-4170]: don't use slim
branberry Jan 8, 2024
a054885
[DOP-4170]: Add log group and update workflow conditions
branberry Jan 9, 2024
0509b58
[DOP-4170]: Add echo statements
branberry Jan 9, 2024
105eac6
[DOP-4170]: Add echo statements
branberry Jan 9, 2024
4e0a2ca
[DOP-4170]: Add echo statements
branberry Jan 9, 2024
c7392aa
[DOP-4170]: Update filter to include base
branberry Jan 9, 2024
bb90a87
[DOP-4170]: Update filter to only look at previous commit
branberry Jan 9, 2024
2f6a867
[DOP-4170]: Revert and figure out later
branberry Jan 9, 2024
d210e65
[DOP-4170]: Grant task permission to write to S3
branberry Jan 9, 2024
2ffe4d6
[DOP-4170]: Add readmes
branberry Jan 10, 2024
c680ab1
[DOP-4170]: Add throw statements
branberry Jan 10, 2024
e9a0fce
Merge branch 'master' into DOP-4170
branberry Jan 10, 2024
0a25fbd
[DOP-4170]: PR feedback
branberry Jan 10, 2024
f41f86b
[DOP-4170]: Undo to check if build passes now
branberry Jan 10, 2024
dd483fb
[DOP-4170]: Add import back in
branberry Jan 10, 2024
5b4daa6
[DOP-4170]: Remove cross project imports
branberry Jan 10, 2024
b2b8319
[DOP-4170]: Update environment
branberry Jan 10, 2024
7bcf409
[DOP-4170]: Remove api from dockerfile
branberry Jan 11, 2024
e6648aa
[DOP-4170]: Remove unused imports
branberry Jan 12, 2024
5bd3e5f
Merge branch 'master' into DOP-4170
branberry Jan 16, 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
15 changes: 15 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Docs Worker Pool Workflows

This README describes the various workflows defined for the docs-worker-pool repository.

## Feature Branch Deploys

The feature branch deploy process occurs whenever a developer opens a pull request. It consists of three separate workflows:

1. `deploy-feature-branch.yml` - Creates the initial infrastructure when a PR is opened, this includes draft PRs
2. `update-feature-branch.yml` - Ran whenever a commit is made to the branch for the PR, and conditionally deploys each stack depending on changes made
3. `clean-feature-branch.yml` - Ran whenever a PR is merged or closed; deletes all of the infrastructure for the feature branch

### Bugs

Right now, there is a small bug with the `update-feature-branch.yml` workflow. This workflow conditionally deploys the various stacks depending on what files have changed from a commit. The issue is that the custom filter action compares the PR branch to master for every workflow run. This means that if you make a change to `src/app.ts` in the first commit, but only make changes to files in the `api/` directory in subsequent commits, it will still run the deploy for the worker.
121 changes: 107 additions & 14 deletions .github/workflows/update-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,57 @@ concurrency:
cancel-in-progress: true
name: Update Feature Branch Infrastructure
jobs:
deploy:
prep-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
dependencies:
- 'package-lock.json'
- 'cdk-infra/package-lock.json'
- name: Install dependencies
if: steps.filter.outputs.dependencies == 'true' || (github.event_name == 'pull_request' && github.event.action == 'opened')
run: |
npm ci
cd cdk-infra/
npm ci
- name: Cache root node_modules
id: cache-root
uses: actions/cache@v3
with:
path: |
node_modules
cdk-infra/node_modules
key: ${{ github.head_ref }}
build-webhooks:
needs: prep-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- uses: actions/cache/restore@v3
id: cache-restore
with:
path: |
node_modules
cdk-infra/node_modules
key: ${{ github.head_ref }}
- uses: dorny/paths-filter@v2
id: filter
with:
Expand All @@ -34,24 +69,82 @@ jobs:
- 'api/**'
- 'cdk-infra/lib/constructs/api/**'
- 'cdk-infra/utils/**'
worker:
- 'src/**'
- 'cdk-infra/lib/constructs/worker/**'
- 'Dockerfile.enhanced'
- 'modules/**'
- name: Update Webhook Stack
if: steps.filter.outputs.webhooks == 'true'
run: |
npm ci
cd cdk-infra/
npm ci
npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \
auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhooks
build-worker:
needs: prep-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- uses: actions/cache/restore@v3
id: cache-restore
with:
path: |
node_modules
cdk-infra/node_modules
key: ${{ github.head_ref }}
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
worker:
- 'src/!(cache-updater/**)/**'
- 'cdk-infra/lib/constructs/worker/**'
- 'Dockerfile.enhanced'
- 'modules/**'
- name: Update Worker Stack
if: steps.filter.outputs.worker == 'true'
run: |
npm ci
cd cdk-infra/
npm ci
npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \
auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-worker


build-cache-updater:
needs: prep-build
runs-on: ubuntu-latest
steps:

- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
cache:
- 'src/cache-updater/**'
- 'cdk-infra/lib/constructs/cache-updater/**'
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- uses: actions/setup-node@v4
with:
node-version: '18.x'
- uses: actions/cache/restore@v3
id: cache-restore
with:
path: |
node_modules
cdk-infra/node_modules
key: ${{ github.head_ref }}
- name: Update Cache Updater
if: steps.filter.outputs.cache == 'true'
run: |
cd cdk-infra/
npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \
cache-updater
3 changes: 3 additions & 0 deletions cdk-infra/bin/cdk-infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AutoBuilderQueueStack } from '../lib/stacks/auto-builder-queue-stack';
import { WorkerStack } from '../lib/stacks/worker-stack';
import { WebhookStack } from '../lib/stacks/webhook-stack';
import { AutoBuilderVpcStack } from '../lib/stacks/auto-builder-vpc-stack';
import { CacheUpdaterStack } from '../lib/stacks/cache-updater-stack';

async function main() {
const app = new cdk.App();
Expand Down Expand Up @@ -44,6 +45,8 @@ async function main() {
webhookSecureStrings,
env,
});

new CacheUpdaterStack(app, 'cache-updater', { vpc });
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { IVpc } from 'aws-cdk-lib/aws-ec2';
import { Cluster, ContainerImage, FargateTaskDefinition, LogDrivers } from 'aws-cdk-lib/aws-ecs';
import { Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { LogGroup } from 'aws-cdk-lib/aws-logs';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import path from 'path';

const SNOOTY_CACHE_BUCKET_NAME = 'snooty-parse-cache';

interface CacheUpdaterWorkerConstructProps {
vpc: IVpc;
}

export class CacheUpdaterWorkerConstruct extends Construct {
clusterName: string;

constructor(scope: Construct, id: string, { vpc }: CacheUpdaterWorkerConstructProps) {
super(scope, id);

const cluster = new Cluster(this, 'cacheUpdaterCluster', {
vpc,
});

const taskRole = new Role(this, 'cacheUpdateWorkerTaskRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com'),
});

const snootyParseCacheBucket = Bucket.fromBucketName(this, SNOOTY_CACHE_BUCKET_NAME, SNOOTY_CACHE_BUCKET_NAME);

snootyParseCacheBucket.grantWrite(taskRole);

const taskDefinition = new FargateTaskDefinition(this, 'cacheUpdaterWorker', {
cpu: 2048,
memoryLimitMiB: 4096,
taskRole,
});

const taskDefLogGroup = new LogGroup(this, 'cacheUpdaterWorkerLogGroup');

taskDefinition.addContainer('cacheUpdaterWorkerImage', {
image: ContainerImage.fromAsset(path.join(__dirname, '../../../../'), {
file: 'src/cache-updater/Dockerfile.cacheUpdater',
buildArgs: { SNOOTY_PARSER_VERSION: '0.15.2' },
exclude: ['tests/', 'node_modules/', 'cdk-infra/'], // adding this just in case it doesn't pick up our dockerignore
}),
environment: {
SNOOTY_CACHE_BUCKET_NAME,
},
logging: LogDrivers.awsLogs({
streamPrefix: 'cacheupdater',
logGroup: taskDefLogGroup,
}),
});

this.clusterName = cluster.clusterName;
}
}
15 changes: 15 additions & 0 deletions cdk-infra/lib/stacks/cache-updater-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CacheUpdaterWorkerConstruct } from '../constructs/cache-updater/cache-updater-worker-construct';
import { IVpc } from 'aws-cdk-lib/aws-ec2';

interface CacheUpdaterStackProps {
vpc: IVpc;
}
export class CacheUpdaterStack extends Stack {
constructor(scope: Construct, id: string, { vpc }: CacheUpdaterStackProps) {
super(scope, id);

new CacheUpdaterWorkerConstruct(this, 'cache-updater-resources', { vpc });
}
}
Loading
Loading