Skip to content

Next remove#749

Closed
slugb0t wants to merge 20 commits intomainfrom
next-remove
Closed

Next remove#749
slugb0t wants to merge 20 commits intomainfrom
next-remove

Conversation

@slugb0t
Copy link
Member

@slugb0t slugb0t commented Mar 12, 2026

Summary by Sourcery

Add containerized Next.js deployment with Kamal and GitHub Actions workflows for production and per-branch preview environments.

New Features:

  • Introduce Docker-based build and runtime setup for the Next.js app using standalone output.
  • Add GitHub Actions workflows to deploy production and per-branch preview environments, including automatic preview cleanup and PR commenting.
  • Support configurable unoptimized Next.js image serving via environment flag for reverse-proxy/Docker setups.

Enhancements:

  • Enable Next.js standalone output and expand allowed remote image patterns, including additional GitHub-related hosts.
  • Upgrade Next.js, React, React DOM, and eslint-config-next to newer compatible versions.
  • Adjust lint-staged configuration and postinstall script to simplify local tooling and hooks.
  • Update home page hero title copy to reflect the new environment label.

CI:

  • Add production deployment workflow triggered from the next branch using Kamal.
  • Add preview deployment workflow that builds per-branch environments, manages GitHub deployment records, and updates PR comments.
  • Add scheduled workflow to detect and clean up stale preview environments, including registry images and GitHub environments.

Deployment:

  • Add Kamal deployment configuration for production and preview environments, including proxy/SSL and registry settings.
  • Introduce environment-specific Kamal secrets and hook files to support extensible deployment lifecycle scripting.

@slugb0t slugb0t requested a review from megasanjay as a code owner March 12, 2026 00:01
@fairdataihub-bot
Copy link

Thank you for submitting this pull request! We appreciate your contribution to the project. Before we can merge it, we need to review the changes you've made to ensure they align with our code standards and meet the requirements of the project. We'll get back to you as soon as we can with feedback. Thanks again!

@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fairdataihub-website Ready Ready Preview, Comment Mar 12, 2026 0:06am

Request Review

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 12, 2026

Reviewer's Guide

This PR introduces Docker/Kamal-based deployment pipelines for production and per-branch preview environments, updates Next.js configuration for standalone builds and image handling, bumps core frontend dependencies, and makes minor content and tooling adjustments.

Sequence diagram for preview environment deployment on branch push

sequenceDiagram
  actor Developer
  participant GitHubRepo
  participant GitHubActions
  participant Job_deploy_ui
  participant Kamal
  participant ContainerRegistry
  participant AppServer
  participant GitHubAPI

  Developer->>GitHubRepo: push_commit_to_feature_branch
  GitHubRepo-->>GitHubActions: push_event(branch_not_main_or_next)
  GitHubActions->>Job_deploy_ui: start_deploy-preview-app_workflow

  Job_deploy_ui->>Job_deploy_ui: compute_branch_slug_and_set_KAMAL_APP_NAME_DOMAIN

  Job_deploy_ui->>GitHubAPI: find_open_PR_for_branch
  GitHubAPI-->>Job_deploy_ui: PR_list
  Job_deploy_ui->>GitHubAPI: create_or_update_PR_comment(in_progress)

  Job_deploy_ui->>Kamal: kamal_deploy_preview
  Kamal->>ContainerRegistry: build_and_push_image
  Kamal->>AppServer: connect_via_ssh
  Kamal->>AppServer: pull_image_and_run_container
  AppServer->>AppServer: start_next_standalone_server

  Job_deploy_ui->>GitHubAPI: create_deployment_record
  GitHubAPI-->>Job_deploy_ui: deployment_id

  Job_deploy_ui->>GitHubAPI: set_deployment_status(success_or_failure)
  Job_deploy_ui->>GitHubAPI: mark_previous_deployments_inactive

  Job_deploy_ui->>GitHubAPI: update_PR_comment_with_preview_URL_or_failure
  GitHubActions-->>Developer: workflow_status_with_preview_URL
Loading

Sequence diagram for preview environment removal on PR close or branch delete

sequenceDiagram
  actor Developer
  participant GitHubRepo
  participant GitHubActions
  participant Job_remove_preview
  participant Kamal
  participant ContainerRegistry
  participant GitHubAPI

  Developer->>GitHubRepo: close_PR_or_delete_branch
  GitHubRepo-->>GitHubActions: pull_request_closed_or_delete_event
  GitHubActions->>Job_remove_preview: start_remove-preview_job

  Job_remove_preview->>Job_remove_preview: determine_branch_name
  Job_remove_preview->>Job_remove_preview: compute_branch_slug_and_KAMAL_APP_NAME

  Job_remove_preview->>Kamal: kamal_remove_preview
  Kamal->>Kamal: stop_and_remove_containers_for_branch

  Job_remove_preview->>ContainerRegistry: crane_auth_login
  Job_remove_preview->>ContainerRegistry: list_and_delete_images_for_KAMAL_APP_NAME

  Job_remove_preview->>GitHubAPI: list_deployments_for_environment
  GitHubAPI-->>Job_remove_preview: deployments_list

  Job_remove_preview->>GitHubAPI: set_deployment_status_inactive
  Job_remove_preview->>GitHubAPI: delete_environment

  alt event_is_pull_request_closed
    Job_remove_preview->>GitHubAPI: update_or_create_PR_comment_preview_removed
  end

  GitHubActions-->>Developer: workflow_status_preview_environment_removed
Loading

File-Level Changes

Change Details Files
Containerize the Next.js app and configure Kamal-based deployments for production and per-branch preview environments.
  • Add a multi-stage Dockerfile that installs dependencies, builds the Next.js app in standalone mode, and runs the standalone server as a non-root user.
  • Introduce Kamal deployment configuration for the main production service, including proxy/SSL, registry credentials, and environment variables.
  • Add a separate Kamal preview deployment config that marks preview environments, including disabling image optimization via NEXT_IMAGE_UNOPTIMIZED.
  • Stub out Kamal hook and secrets files for environment-specific configuration and lifecycle hooks.
Dockerfile
config/deploy.yml
config/deploy.preview.yml
.kamal/hooks/docker-setup.sample
.kamal/hooks/post-deploy.sample
.kamal/hooks/post-proxy-reboot.sample
.kamal/hooks/pre-build.sample
.kamal/hooks/pre-connect.sample
.kamal/hooks/pre-deploy.sample
.kamal/hooks/pre-proxy-reboot.sample
.kamal/secrets
.kamal/secrets-common
.kamal/secrets-preview
Add GitHub Actions workflows to deploy and clean up production and preview environments using Kamal.
  • Create a production deployment workflow that runs on pushes to the next branch, sets up Ruby and Kamal, manages deployment locks, and updates GitHub deployment status.
  • Create a preview deployment workflow that builds per-branch preview environments via Kamal, posts/updates PR comments with preview URLs, and manages GitHub deployment records.
  • Add logic to remove preview environments when PRs close or branches are deleted, including stopping Kamal deployments, deleting registry images, and cleaning up GitHub environments and comments.
  • Introduce a scheduled/dispatchable cleanup workflow that finds stale preview environments (by missing branches or last commit age) and removes their Kamal deployments, registry images, and GitHub environments.
.github/workflows/deploy-app.yml
.github/workflows/deploy-preview-app.yml
.github/workflows/cleanup-preview-envs.yml
Update Next.js configuration for standalone output and more flexible image handling, including preview-env behavior.
  • Enable Next.js standalone output to support Docker/Kamal deployment of a minimal runtime bundle.
  • Add an unoptimized images mode controlled by NEXT_IMAGE_UNOPTIMIZED to work around issues when running behind reverse proxies in containers.
  • Normalize and expand remote image patterns by explicitly setting port and pathname and adding additional GitHub-related hostnames commonly used for assets.
next.config.js
Adjust package tooling and bump core frontend dependencies to newer Next.js/React/eslint versions.
  • Remove the custom postinstall gallery_id script so postinstall only runs Husky installation.
  • Change the lint-staged glob pattern for src files (from a language-based pattern to a .mx glob) for lint/format steps.
  • Loosen and bump versions of next, react, react-dom, and eslint-config-next to newer compatible releases using caret ranges.
  • Regenerate yarn.lock to reflect the updated dependency versions and ranges.
package.json
yarn.lock
Minor content tweak on the home page hero heading to label the Next deployment.
  • Update the main hero heading text to include an explicit "(next-21)" suffix for the FAIR Data wave copy.
src/pages/index.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@fairdataihub-bot
Copy link

Thanks for making updates to your pull request. Our team will take a look and provide feedback as soon as possible. Please wait for any GitHub Actions to complete before editing your pull request. If you have any additional questions or concerns, feel free to let us know. Thank you for your contributions!

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The lint-staged pattern was changed from targeting TypeScript/JavaScript files to ./src/**/*.{mx}, which likely no longer matches your source files and will effectively disable lint/format on commits; consider reverting or adjusting the glob to the intended extensions.
  • The home page title was updated to The FAIR Data wave (next-21), which looks like a temporary marker for this branch or deployment and might be worth reverting or gating behind an environment variable before merging to a long-lived branch.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The lint-staged pattern was changed from targeting TypeScript/JavaScript files to `./src/**/*.{mx}`, which likely no longer matches your source files and will effectively disable lint/format on commits; consider reverting or adjusting the glob to the intended extensions.
- The home page title was updated to `The FAIR Data wave (next-21)`, which looks like a temporary marker for this branch or deployment and might be worth reverting or gating behind an environment variable before merging to a long-lived branch.

## Individual Comments

### Comment 1
<location path=".github/workflows/deploy-app.yml" line_range="93-97" />
<code_context>
+      # Step 9: Initial Kamal setup (only needed once per server)
+      # Note: This step might need to be run manually on the server first time
+      # to add the user to the docker group: `sudo usermod -aG docker $USER | newgrp docker | docker ps`
+      - id: kamal-deploy
+        run: kamal setup
+
+      # Step 10: Update GitHub deployment status based on outcome
</code_context>
<issue_to_address>
**suggestion (performance):** Running `kamal setup` on every production deploy may be heavier than necessary; `kamal deploy` is usually more appropriate.

Since `kamal setup` is generally required only once per server for initial provisioning, running it on every push to `next` adds unnecessary overhead and repeats setup work. For ongoing deployments, consider switching this step to `kamal deploy` (or `kamal deploy -d <env>`) and reserving `setup` for first-time server configuration.

```suggestion
      # Step 9: Deploy application with Kamal
      # Note: `kamal setup` is generally required only once per server for initial provisioning
      # (e.g. adding the user to the docker group). Run that manually or in a separate workflow.
      - id: kamal-deploy
        run: kamal deploy
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +93 to +97
# Step 9: Initial Kamal setup (only needed once per server)
# Note: This step might need to be run manually on the server first time
# to add the user to the docker group: `sudo usermod -aG docker $USER | newgrp docker | docker ps`
- id: kamal-deploy
run: kamal setup
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Running kamal setup on every production deploy may be heavier than necessary; kamal deploy is usually more appropriate.

Since kamal setup is generally required only once per server for initial provisioning, running it on every push to next adds unnecessary overhead and repeats setup work. For ongoing deployments, consider switching this step to kamal deploy (or kamal deploy -d <env>) and reserving setup for first-time server configuration.

Suggested change
# Step 9: Initial Kamal setup (only needed once per server)
# Note: This step might need to be run manually on the server first time
# to add the user to the docker group: `sudo usermod -aG docker $USER | newgrp docker | docker ps`
- id: kamal-deploy
run: kamal setup
# Step 9: Deploy application with Kamal
# Note: `kamal setup` is generally required only once per server for initial provisioning
# (e.g. adding the user to the docker group). Run that manually or in a separate workflow.
- id: kamal-deploy
run: kamal deploy

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

Preview deployment removed

The preview environment for this branch has been removed.

@megasanjay
Copy link
Member

megasanjay commented Mar 12, 2026

@fairdataihub-bot
Copy link

Thanks for closing this pull request! If you have any further questions, please feel free to open a new issue. We are always happy to help!

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