mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[PR #4233] [MERGED] refactor: slim down the backend containers #4720
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#4720
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/4233
Author: @AndrewBastin
Created: 8/1/2024
Status: ✅ Merged
Merged: 8/8/2024
Merged by: @balub
Base:
patch← Head:refactor/containers📝 Commits (9)
4862e81refactor: slim down the backend containers222a5adrefactor: make containers run as non-root user in container7731611chore: correct casing for the build stage definitions8247480chore: remove docker compose version field as its obsolete564c95fchore: optimise chown and chmod into the COPY command itself1047285chore: add package overrides for packages with reported vulns3d4d5edchore: add pnpm to containers + set workdir dir to the backend project5aebd74fix: permission issues with the fe containers16a4de6chore: define env variables on AIO📊 Changes
12 files changed (+1256 additions, -442 deletions)
View changed files
📝
aio_run.mjs(+1 -1)📝
docker-compose.deploy.yml(+0 -2)📝
docker-compose.yml(+0 -1)📝
package.json(+7 -1)➖
packages/hoppscotch-backend/cross-env(+0 -0)➖
packages/hoppscotch-backend/eslint(+0 -0)📝
packages/hoppscotch-backend/package.json(+5 -1)📝
packages/hoppscotch-backend/prod_run.mjs(+2 -2)📝
packages/hoppscotch-backend/tsconfig.build.json(+5 -1)📝
packages/hoppscotch-selfhost-web/selfhost-web.Caddyfile(+1 -1)📝
pnpm-lock.yaml(+1144 -400)📝
prod.Dockerfile(+91 -32)📄 Description
This PR intends to slim down the containers (particularly the backend and hence the AIO container) and along with that move the containers to execute the servers as a non-root container user (
hoppuser).For the AIO container, this PR reduces the container size from 2.0GB to 501MB (as per dive report). Similar improvements should be present in the backend container as well (from 1.9GB to 440MB) but the FE and SH Admin containers should remain the same mostly.
The size reduction is mostly achieved by removing out the existing entire monorepo copy that was present in the containers. Along with the build steps and artifacts around it. The present build artifacts also caused a lot of erroneous vulnerability reports on the container as the container had more exploitable bits inside it. The reduction here reduces the signal-to-noise ratio for the containers greatly.
Along with that, this PR also moves the container from using non-root user accounts (named
hoppuser) to execute the main operations (mostly the container switches to defaulting tohoppuserafter all the installation steps are done inprod.Dockerfile). This improves security and is considered a best practice to reduce damages that can be caused by privilege escalation attacks caused by container breakouts into the host system.Along with that, this PR has some package overrides for packages in the repo that were having known vulnerabilities.
What's changed
backend_builderbuild stage and move the build process into that./dist/backendfolder withpnpm deployto generate a copy of the package without associations to the monorepo, see: https://pnpm.io/cli/deploy.hoppuseruser to switch to for execution after all the installs are done.node:20-alpine3.19image. This is due to thehoppuseraccount messing up some stuff between the containers.package.jsonto replace packages with vulnerabilities with a version that is fixed. We use PNPM's package overrides for this, see: https://pnpm.io/package_json#pnpmoverridesNotes to reviewers
Make sure to check all the containers work also consider the subpath access and non subpath access mode on the individual containers as well.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.