[PR #3193] [MERGED] feat: container registry friendly docker images and all-in-one container #4278

Closed
opened 2026-03-17 01:49:44 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/3193
Author: @AndrewBastin
Created: 7/17/2023
Status: Merged
Merged: 8/23/2023
Merged by: @AndrewBastin

Base: release/2023.8.0Head: chore/docker-fixes


📝 Commits (10+)

  • dd61f40 chore: simplify prod docker build process
  • a720d98 feat: updated frontend docker containers to allow for runtime environment variable definitions
  • b86d08d feat: initial aio container implementation
  • ae3e1ee chore: small corrections
  • 581b7d4 chore: correct VITE env prefix to APP
  • 7104801 chore: rename frontend prod docker target into app
  • a727aae chore: revert back environment variable prefixes to VITE_
  • 7ae2437 fix: pass production and port environment variables for the backend functioning
  • d01df5d fix: add tini as the init process for a clean signal handling for the aio container
  • 536c453 feat: exit the container if any of the child processes exit out

📊 Changes

23 files changed (+680 additions, -42 deletions)

View changed files

📝 .dockerignore (+2 -1)
aio.Caddyfile (+11 -0)
aio_run.mjs (+72 -0)
📝 docker-compose.yml (+76 -7)
healthcheck.sh (+14 -0)
📝 packages/hoppscotch-backend/package.json (+2 -2)
📝 packages/hoppscotch-backend/prisma/schema.prisma (+1 -1)
packages/hoppscotch-backend/src/app.controller.ts (+9 -0)
📝 packages/hoppscotch-backend/src/app.module.ts (+2 -0)
📝 packages/hoppscotch-backend/src/user-history/user-history.service.spec.ts (+4 -2)
packages/hoppscotch-common/src/helpers/strategies/AxiosStrategy.ts (+163 -0)
📝 packages/hoppscotch-selfhost-web/index.html (+3 -0)
📝 packages/hoppscotch-selfhost-web/meta.ts (+4 -4)
📝 packages/hoppscotch-selfhost-web/package.json (+2 -0)
packages/hoppscotch-selfhost-web/prod_run.mjs (+17 -0)
📝 packages/hoppscotch-selfhost-web/vite.config.ts (+10 -3)
📝 packages/hoppscotch-sh-admin/index.html (+4 -1)
📝 packages/hoppscotch-sh-admin/package.json (+3 -0)
packages/hoppscotch-sh-admin/prod_run.mjs (+18 -0)
📝 packages/hoppscotch-sh-admin/src/components.d.ts (+23 -0)

...and 3 more files

📄 Description

Introduction

This PR intends to do the following things at a high level:

  1. Update the frontends (sh-admin and selfhost-web) to have environment variables definable/updatable after build.
  2. Introduce more efficient build process for the Self-hostable containers.
  3. Introduce the all-in-one (AIO) container that expose the selfhost-web, sh-admin and backend apps in different ports.

The high-level end goal of this PR is to have solid container registry friendly containers of Hoppscotch.

Things changed

  • Added root .dockerignore to ignore all node_modules folders recursively as well.
  • Updated frontend environment variables to use APP_ prefix instead of VITE_.
  • Introduce @import-meta-env/cli, @import-meta-env/unplugin as dev dependencies to sh-admin and selfhost-web.
  • Use @import-meta-env/unplugin vite plugin to do environment variable processing.
  • Added placeholder script in entry point index.html files in sh-admin and selfhost-web for @import-meta-env/cli to replace environment variables after build.
  • Introducing prod.Dockerfile that builds production (container registry friendly) docker containers for the app.
  • prod-Dockerfile defines 4 final target images, app, backend, sh_admin and aio.
  • Introduce prod_run.mjs for sh-admin and selfhost-web that will be executed on runtime to set environment variables during the run of app and sh_admin containers.
  • Introduce aio_run.mjs for aio container to execute during its runtime.

Why is this still a draft ?

There are a couple of things here that I do feel we can still improve upon after I get initial feedback and this PR is fully open:

  • Improvements in the dev builds which we can derive from the prod build process.
  • Reducing the container size particularly for the backend and aio containers.
    • There should be a PR eventually to bump Prisma version which will allow us to move into node:18-alpine instead of node:18-bookworm. [Done]
    • We need to look into using pnpm deploy to extract the backend project out so the backend container doesn't need to have the entire monorepo (along with the deps) in its image.
  • There needs to be more documentation on the Dockerfile and the new scripts to make it clearer how this works.
  • The AIO container doesn't deal with termination really well along with situations when either the caddy server or the backend crashes. [This has been fixed]
  • There is a weird behaviour with prod_run.mjs (both of them) and aio_run.mjs where the parsing of the placeholder messes up due to quotes in the .env file. If you run into this issue, just try removing the quotes in your .env entries, but I think we need to solve this a bit more gracefully.

Things that may break/change

  • Environment variable defined with the VITE_ will definitely be broken. We can look into impact assumptions, mitigations or to reverse this decision before opening this PR from draft status. [This has been reverted]

How to test this ?

  • Build the target from the prod.Dockerfile dockerfile
# assuming CWD is the root of the repo
# target can be "app", "sh_admin", "backend"

docker build -t <target> --target <target> -f prod.Dockerfile .
  • Start the container with docker run (Example, here is the command for aio)
# Look into prod.Dockerfile for what ports are required
docker run -p 3000:3000 -p 3100:3100 -p 3170:3170 --env-file .env aio

Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/3193 **Author:** [@AndrewBastin](https://github.com/AndrewBastin) **Created:** 7/17/2023 **Status:** ✅ Merged **Merged:** 8/23/2023 **Merged by:** [@AndrewBastin](https://github.com/AndrewBastin) **Base:** `release/2023.8.0` ← **Head:** `chore/docker-fixes` --- ### 📝 Commits (10+) - [`dd61f40`](https://github.com/hoppscotch/hoppscotch/commit/dd61f40ed82954c37554b20d0f1afbd053ed295e) chore: simplify prod docker build process - [`a720d98`](https://github.com/hoppscotch/hoppscotch/commit/a720d98ab7fdb1ce7f1ad80dc5e7ea512d7a28ca) feat: updated frontend docker containers to allow for runtime environment variable definitions - [`b86d08d`](https://github.com/hoppscotch/hoppscotch/commit/b86d08dc6f517f3895466e0b8b9bf6f65c0f4e1d) feat: initial aio container implementation - [`ae3e1ee`](https://github.com/hoppscotch/hoppscotch/commit/ae3e1ee390eaa78c36ebc98748f85a4e2b369b80) chore: small corrections - [`581b7d4`](https://github.com/hoppscotch/hoppscotch/commit/581b7d471b52f8f15f7baa1871e7c69fcffcca61) chore: correct VITE env prefix to APP - [`7104801`](https://github.com/hoppscotch/hoppscotch/commit/7104801c47864dcf45a0933c203de6a0b7e54c41) chore: rename frontend prod docker target into app - [`a727aae`](https://github.com/hoppscotch/hoppscotch/commit/a727aae78d22ed82ed6dcd4effd4b8d32903a8b1) chore: revert back environment variable prefixes to VITE_ - [`7ae2437`](https://github.com/hoppscotch/hoppscotch/commit/7ae243763bc1a11079bb004252726b55d631dd73) fix: pass production and port environment variables for the backend functioning - [`d01df5d`](https://github.com/hoppscotch/hoppscotch/commit/d01df5d796a69688ebf3d064382684cf0f42e48d) fix: add tini as the init process for a clean signal handling for the aio container - [`536c453`](https://github.com/hoppscotch/hoppscotch/commit/536c453436d9ac32235939d80506d6ad1d9c09e4) feat: exit the container if any of the child processes exit out ### 📊 Changes **23 files changed** (+680 additions, -42 deletions) <details> <summary>View changed files</summary> 📝 `.dockerignore` (+2 -1) ➕ `aio.Caddyfile` (+11 -0) ➕ `aio_run.mjs` (+72 -0) 📝 `docker-compose.yml` (+76 -7) ➕ `healthcheck.sh` (+14 -0) 📝 `packages/hoppscotch-backend/package.json` (+2 -2) 📝 `packages/hoppscotch-backend/prisma/schema.prisma` (+1 -1) ➕ `packages/hoppscotch-backend/src/app.controller.ts` (+9 -0) 📝 `packages/hoppscotch-backend/src/app.module.ts` (+2 -0) 📝 `packages/hoppscotch-backend/src/user-history/user-history.service.spec.ts` (+4 -2) ➕ `packages/hoppscotch-common/src/helpers/strategies/AxiosStrategy.ts` (+163 -0) 📝 `packages/hoppscotch-selfhost-web/index.html` (+3 -0) 📝 `packages/hoppscotch-selfhost-web/meta.ts` (+4 -4) 📝 `packages/hoppscotch-selfhost-web/package.json` (+2 -0) ➕ `packages/hoppscotch-selfhost-web/prod_run.mjs` (+17 -0) 📝 `packages/hoppscotch-selfhost-web/vite.config.ts` (+10 -3) 📝 `packages/hoppscotch-sh-admin/index.html` (+4 -1) 📝 `packages/hoppscotch-sh-admin/package.json` (+3 -0) ➕ `packages/hoppscotch-sh-admin/prod_run.mjs` (+18 -0) 📝 `packages/hoppscotch-sh-admin/src/components.d.ts` (+23 -0) _...and 3 more files_ </details> ### 📄 Description ### Introduction This PR intends to do the following things at a high level: 1. Update the frontends (`sh-admin` and `selfhost-web`) to have environment variables definable/updatable after build. 2. Introduce more efficient build process for the Self-hostable containers. 3. Introduce the all-in-one (AIO) container that expose the `selfhost-web`, `sh-admin` and `backend` apps in different ports. The high-level end goal of this PR is to have solid container registry friendly containers of Hoppscotch. ### Things changed - Added root `.dockerignore` to ignore all `node_modules` folders recursively as well. - Updated frontend environment variables to use `APP_` prefix instead of `VITE_`. - Introduce `@import-meta-env/cli`, `@import-meta-env/unplugin` as dev dependencies to `sh-admin` and `selfhost-web`. - Use `@import-meta-env/unplugin` vite plugin to do environment variable processing. - Added placeholder script in entry point `index.html` files in `sh-admin` and `selfhost-web` for `@import-meta-env/cli` to replace environment variables after build. - Introducing `prod.Dockerfile` that builds production (container registry friendly) docker containers for the app. - `prod-Dockerfile` defines 4 final target images, `app`, `backend`, `sh_admin` and `aio`. - Introduce `prod_run.mjs` for `sh-admin` and `selfhost-web` that will be executed on runtime to set environment variables during the run of `app` and `sh_admin` containers. - Introduce `aio_run.mjs` for `aio` container to execute during its runtime. ### Why is this still a draft ? There are a couple of things here that I do feel we can still improve upon after I get initial feedback and this PR is fully open: - Improvements in the dev builds which we can derive from the prod build process. - Reducing the container size particularly for the `backend` and `aio` containers. - ~There should be a PR eventually to bump Prisma version which will allow us to move into `node:18-alpine` instead of `node:18-bookworm`.~ [Done] - We need to look into using `pnpm deploy` to extract the backend project out so the `backend` container doesn't need to have the entire monorepo (along with the deps) in its image. - There needs to be more documentation on the Dockerfile and the new scripts to make it clearer how this works. - ~The AIO container doesn't deal with termination really well along with situations when either the caddy server or the backend crashes.~ [This has been fixed] - There is a weird behaviour with `prod_run.mjs` (both of them) and `aio_run.mjs` where the parsing of the placeholder messes up due to quotes in the .env file. If you run into this issue, just try removing the quotes in your .env entries, but I think we need to solve this a bit more gracefully. ### Things that may break/change - ~Environment variable defined with the `VITE_` will definitely be broken. We can look into impact assumptions, mitigations or to reverse this decision before opening this PR from draft status.~ [This has been reverted] ### How to test this ? - Build the target from the `prod.Dockerfile` dockerfile ```bash # assuming CWD is the root of the repo # target can be "app", "sh_admin", "backend" docker build -t <target> --target <target> -f prod.Dockerfile . ``` - Start the container with `docker run` (Example, here is the command for `aio`) ```bash # Look into prod.Dockerfile for what ports are required docker run -p 3000:3000 -p 3100:3100 -p 3170:3170 --env-file .env aio ``` ### Checks <!-- Make sure your pull request passes the CI checks and do check the following fields as needed - --> - [x] My pull request adheres to the code style of this project - [x] My code requires changes to the documentation - [ ] I have updated the documentation as required - [x] All the tests have passed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 01:49:44 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#4278
No description provided.