Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 70 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CD - Build & Deploy
on:
push:
branches:
- feature/bulk-v3
- feature/aggregator
# - main
workflow_dispatch:

Expand All @@ -25,6 +25,11 @@ env:
ERROR_STREAM_ECS_SERVICE: ${{ secrets.ERROR_STREAM_ECS_SERVICE }}
ERROR_STREAM_TASK_DEFINITION: ${{ secrets.ERROR_STREAM_TASK_DEFINITION }}
ERROR_STREAM_CONTAINER_NAME: ${{ secrets.ERROR_STREAM_CONTAINER_NAME }}
AGGREGATOR_ECR_REPOSITORY: ${{ secrets.AGGREGATOR_ECR_REPOSITORY }}
AGGREGATOR_ECS_CLUSTER: ${{ secrets.AGGREGATOR_ECS_CLUSTER }}
AGGREGATOR_ECS_SERVICE: ${{ secrets.AGGREGATOR_ECS_SERVICE }}
AGGREGATOR_TASK_DEFINITION: ${{ secrets.AGGREGATOR_TASK_DEFINITION }}
AGGREGATOR_CONTAINER_NAME: ${{ secrets.AGGREGATOR_CONTAINER_NAME }}

jobs:
detect:
Expand All @@ -34,6 +39,7 @@ jobs:
query_api: ${{ steps.filter.outputs.query_api }}
stream_processor: ${{ steps.filter.outputs.stream_processor }}
error_stream: ${{ steps.filter.outputs.error_stream }}
aggregator: ${{ steps.filter.outputs.aggregator }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -61,6 +67,12 @@ jobs:
- 'backend/package.json'
- 'backend/package-lock.json'
- 'backend/Dockerfile'
aggregator:
- 'backend/src/aggregator/**'
- 'backend/src/shared/**'
- 'backend/package.json'
- 'backend/package-lock.json'
- 'backend/Dockerfile'

deploy-query:
name: Build & deploy query API
Expand Down Expand Up @@ -232,3 +244,60 @@ jobs:
--service "$ERROR_STREAM_ECS_SERVICE" \
--task-definition "$ERROR_STREAM_TASK_DEF_ARN" \
--force-new-deployment

deploy-aggregator:
name: Build & deploy rollup aggregator
needs: detect
if: needs.detect.outputs.aggregator == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
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: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
run: |
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "${ECR_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"

- name: Build Docker image
working-directory: backend
env:
IMAGE_NAME: panopticon-aggregator
run: |
docker build -f Dockerfile --target aggregator -t "$IMAGE_NAME:${GITHUB_SHA}" .

- name: Push image to ECR
env:
IMAGE_NAME: panopticon-aggregator
run: |
ECR_URI="${ECR_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${AGGREGATOR_ECR_REPOSITORY}"
docker tag "$IMAGE_NAME:${GITHUB_SHA}" "${ECR_URI}:${GITHUB_SHA}"
docker tag "$IMAGE_NAME:${GITHUB_SHA}" "${ECR_URI}:latest"
docker push "${ECR_URI}:${GITHUB_SHA}"
docker push "${ECR_URI}:latest"
echo "AGGREGATOR_ECR_URI=${ECR_URI}" >> $GITHUB_ENV

- name: Register new task definition revision
run: |
aws ecs describe-task-definition --task-definition "$AGGREGATOR_TASK_DEFINITION" --query 'taskDefinition' --output json > task-def.json
IMAGE="${{ env.AGGREGATOR_ECR_URI }}:${GITHUB_SHA}"
cat task-def.json | jq --arg IMAGE "$IMAGE" --arg NAME "$AGGREGATOR_CONTAINER_NAME" '
.containerDefinitions |= map(if .name == $NAME then .image = $IMAGE else . end)
| del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .registeredAt, .registeredBy, .compatibilities)
' > new-task-def.json
NEW_TASK_DEF_ARN=$(aws ecs register-task-definition --cli-input-json file://new-task-def.json --query 'taskDefinition.taskDefinitionArn' --output text)
echo "AGGREGATOR_TASK_DEF_ARN=$NEW_TASK_DEF_ARN" >> $GITHUB_ENV

- name: Trigger ECS deployment
run: |
aws ecs update-service \
--cluster "$AGGREGATOR_ECS_CLUSTER" \
--service "$AGGREGATOR_ECS_SERVICE" \
--task-definition "$AGGREGATOR_TASK_DEF_ARN" \
--force-new-deployment
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pnpm-debug.log*
lerna-debug.log*
# Ignore all Markdown files repo-wide…
*.md
apm_query_api_spec_v2.yaml
# …but keep README.md files tracked
!README.md
# Keep project-specific ignores inside subdirectories (.gitignore within backend/, frontend/, etc.)
Expand Down
7 changes: 7 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ RUN npm run build:stream-processor
FROM base AS build-error
RUN npm run build:error-stream

FROM base AS build-aggregator
RUN npm run build:aggregator

FROM node:20-alpine AS runtime-base
WORKDIR /app
ENV NODE_ENV=production
Expand All @@ -35,3 +38,7 @@ FROM runtime-base AS error-stream
COPY --from=build-error /app/dist/error-stream ./dist
EXPOSE 3010
CMD ["node", "dist/error-stream/main"]

FROM runtime-base AS aggregator
COPY --from=build-aggregator /app/dist/aggregator ./dist
CMD ["node", "dist/aggregator/main"]
Loading