Skip to content

Add supervisor build pipeline #1772

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

Merged
merged 7 commits into from
Mar 6, 2025
Merged

Add supervisor build pipeline #1772

merged 7 commits into from
Mar 6, 2025

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Mar 6, 2025

Summary by CodeRabbit

  • Chores

    • Optimized dependency exclusion to streamline container builds.
  • New Features

    • Enhanced image tagging with additional naming conditions.
    • Introduced a new automated workflow for publishing container images.
    • Added a dedicated container build configuration for the supervisor module.
    • Included a build command for streamlined TypeScript compilation.

Copy link

changeset-bot bot commented Mar 6, 2025

⚠️ No Changeset found

Latest commit: 4e27ced

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request updates the project’s configuration and CI/CD workflows. The .dockerignore file now recursively ignores all node_modules directories. The GitHub Actions logic has been enhanced with a new condition to generate image tags based on a re2 naming pattern, and a new workflow has been added to handle the publication of worker images with branch validation. Additionally, a multi-stage Dockerfile and a new TypeScript build script have been introduced for the supervisor application.

Changes

File(s) Change Summary
.dockerignore Updated the ignore rule from node_modules to **/node_modules to recursively ignore directories.
.github/actions/get-image-tag/action.yml
.github/workflows/publish-worker-re2.yml
Added a new conditional branch for image tags matching re2-*-* in the image tag action and introduced a new workflow to publish worker images, which includes branch validation and a matrix build job for Docker image creation and deployment.
apps/supervisor/Containerfile
apps/supervisor/package.json
Introduced a new multi-stage Containerfile for building a Docker image for the Node.js supervisor app and added a new build script "build": "tsc" to compile TypeScript files directly.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant GH as GitHub Workflow
    participant CB as Check-Branch Job
    participant BI as Build Job
    participant GT as Get-Image-Tag Action
    participant DR as Docker Registry

    Dev->>GH: Push tag / Trigger workflow
    GH->>CB: Run check-branch job
    CB-->>GH: Validate branch & tag conditions
    GH->>BI: Trigger build job (after check passes)
    BI->>GT: Retrieve image tag (if ref matches re2 pattern)
    GT-->>BI: Return constructed tag
    BI->>DR: Build and push Docker image
Loading

Poem

I’m a rabbit in code fields, hopping along so free,
Updating rules and workflows—oh, what a jubilee!
Node modules hidden deep, and tags that now align,
Docker builds and push delights, a garden so divine.
With every line of code I leap, new features make me smile,
Celebrating changes big and small in every crafty style!
🐇💻🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (7)
.github/actions/get-image-tag/action.yml (1)

34-39: Consider refactoring duplicate tag generation logic

The logic for generating tags from re2-*-* pattern is identical to the one for infra-*-*. Consider extracting this common logic into a function to avoid duplication and make future maintenance easier.

-          elif [[ "${{ github.ref_name }}" == re2-*-* ]]; then
-            env=$(echo ${{ github.ref_name }} | cut -d- -f2)
-            sha=$(echo ${{ github.sha }} | head -c7)
-            ts=$(date +%s)
-            tag=${env}-${sha}-${ts}
+          elif [[ "${{ github.ref_name }}" == re2-*-* ]] || [[ "${{ github.ref_name }}" == infra-*-* ]]; then
+            env=$(echo ${{ github.ref_name }} | cut -d- -f2)
+            sha=$(echo ${{ github.sha }} | head -c7)
+            ts=$(date +%s)
+            tag=${env}-${sha}-${ts}
.github/workflows/publish-worker-re2.yml (1)

67-70: Use Docker Buildx build command for better caching

You're setting up Docker Buildx but not using it for the build command. Consider using the docker buildx build command to take advantage of Buildx's improved caching mechanisms.

-      - name: 🚢 Build Container Image
-        run: |
-          docker build -t infra_image -f ./apps/${{ matrix.package }}/Containerfile .
+      - name: 🚢 Build Container Image
+        run: |
+          docker buildx build --load -t infra_image -f ./apps/${{ matrix.package }}/Containerfile .
apps/supervisor/Containerfile (5)

8-9: Consider improving dependency pruning

The Turbo prune followed by a separate find command to remove node_modules seems redundant. Turbo prune should already handle excluding node_modules from the output directory.

RUN npx -q turbo@1.10.9 prune --scope=supervisor --docker
-RUN find . -name "node_modules" -type d -prune -exec rm -rf '{}' +

24-26: Consider using --frozen-lockfile for deterministic installations

You're using --no-frozen-lockfile which allows package versions to be updated during installation. For reproducible builds, consider using --frozen-lockfile instead.

-RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm fetch --no-frozen-lockfile
-RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --ignore-scripts --no-frozen-lockfile
+RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm fetch
+RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --ignore-scripts --frozen-lockfile

31-31: Consider using --frozen-lockfile for production dependencies

Same issue here - for reproducible builds, consider using --frozen-lockfile instead of --no-frozen-lockfile.

-RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --prod --no-frozen-lockfile
+RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --prod --frozen-lockfile

36-36: Consider using a version variable for Prisma

The Prisma version (5.4.1) is hardcoded. Consider defining it as a build argument or environment variable for easier maintenance.

+ARG PRISMA_VERSION=5.4.1
 ENV NPM_CONFIG_IGNORE_WORKSPACE_ROOT_CHECK true
-RUN pnpx prisma@5.4.1 generate --schema /app/internal-packages/database/prisma/schema.prisma
+RUN pnpx prisma@${PRISMA_VERSION} generate --schema /app/internal-packages/database/prisma/schema.prisma

63-63: Add a health check to improve container orchestration

Consider adding a HEALTHCHECK instruction to enable container orchestrators to monitor the application's health.

USER node

+# Add health check to the container
+HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
+  CMD wget --no-verbose --tries=1 --spider http://localhost:8000/health || exit 1
+
CMD [ "/usr/bin/dumb-init", "--", "pnpm", "run", "--filter", "supervisor", "start"]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3089caf and 4e27ced.

📒 Files selected for processing (5)
  • .dockerignore (1 hunks)
  • .github/actions/get-image-tag/action.yml (1 hunks)
  • .github/workflows/publish-worker-re2.yml (1 hunks)
  • apps/supervisor/Containerfile (1 hunks)
  • apps/supervisor/package.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
apps/supervisor/package.json (1)

8-8: Added build script looks good!

The "build": "tsc" script addition is straightforward and will enable TypeScript compilation for the Docker build process defined in the new Containerfile.

.dockerignore (1)

12-12: Good improvement to catch all node_modules directories!

Changing from node_modules to **/node_modules ensures that Docker ignores all node_modules directories at any level in the project tree, which is ideal for monorepos. This will help optimize Docker builds by reducing context size.

apps/supervisor/Containerfile (1)

1-1: Good practice pinning the base image with SHA

Using a SHA digest for the base image ensures build reproducibility and security. This is an excellent practice.

@nicktrn nicktrn merged commit e297c7f into main Mar 6, 2025
6 of 12 checks passed
@nicktrn nicktrn deleted the feat/supervisor-publish branch March 6, 2025 18:22
@coderabbitai coderabbitai bot mentioned this pull request Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants