39 lines
1.9 KiB
Markdown
39 lines
1.9 KiB
Markdown
# Dockerization Task: Lightweight Bun + Hono Container
|
|
|
|
## 1. Objective
|
|
Create a production-ready `Dockerfile` and a `.dockerignore` file for the current Bun + Hono + SQLite application.
|
|
|
|
## 2. Performance & Resource Goals
|
|
- **Concurrency:** The container must comfortably handle simultaneous requests (4-5 concurrent connections is the baseline, but it should handle more efficiently). Rely on Bun's native asynchronous event loop.
|
|
- **Memory Footprint:** The image size and runtime memory usage must be **minimized**.
|
|
- **Security:** Do not run as root if possible, or ensure the environment is restricted.
|
|
|
|
## 3. Technical Requirements
|
|
|
|
### A. Base Image
|
|
- Use `oven/bun:1-alpine` as the base image.
|
|
- **Reason:** The Alpine variant is significantly smaller than the Debian-based default, satisfying the low-memory/storage requirement.
|
|
|
|
### B. Build Instructions
|
|
1. **Environment:** Set `NODE_ENV=production`.
|
|
2. **Dependencies:** Run `bun install --frozen-lockfile --production`. Do not install `devDependencies` (like types or test runners) to keep the image small.
|
|
3. **Database Directory:** Create a dedicated directory for the SQLite database (e.g., `/app/data`).
|
|
4. **Volume:** Declare a `VOLUME` for the database directory so data persists after container restarts.
|
|
|
|
### C. Runtime Configuration
|
|
1. **Port:** Expose the port (usually 3000).
|
|
2. **Command:** Use `bun run src/index.ts` (or the entry point file).
|
|
3. **Binding:** Ensure the Hono app listens on `0.0.0.0` (not `127.0.0.1` or `localhost`), otherwise it will not be accessible outside the container.
|
|
|
|
### D. The `.dockerignore` file
|
|
Create a strict `.dockerignore` to prevent unnecessary files from increasing the build context size. Exclude:
|
|
- `node_modules`
|
|
- `*.db` (Local database files should not be copied into the image)
|
|
- `.git`
|
|
- `python-ref`
|
|
- `*.md`
|
|
|
|
## 4. Deliverables
|
|
Please generate the code for:
|
|
1. `Dockerfile`
|
|
2. `.dockerignore` |