add dockerfile
This commit is contained in:
5
.dockerignore
Normal file
5
.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
node_modules
|
||||||
|
*.db
|
||||||
|
.git
|
||||||
|
python-ref
|
||||||
|
*.md
|
||||||
32
Dockerfile
Normal file
32
Dockerfile
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Dockerfile for a Bun + Hono + SQLite application
|
||||||
|
|
||||||
|
# --- Base Image ---
|
||||||
|
FROM oven/bun:1-alpine
|
||||||
|
|
||||||
|
# --- Environment Variables ---
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
# --- Working Directory ---
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# --- Copy package.json and bun.lockb to leverage Docker cache ---
|
||||||
|
COPY package.json bun.lockb ./
|
||||||
|
|
||||||
|
# --- Install Dependencies ---
|
||||||
|
# Do not install devDependencies to keep the image small
|
||||||
|
RUN bun install --frozen-lockfile --production
|
||||||
|
|
||||||
|
# --- Copy application source code ---
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# --- Create dedicated directory for SQLite database ---
|
||||||
|
# Declare a VOLUME for the database directory so data persists after container restarts.
|
||||||
|
RUN mkdir -p /app/data
|
||||||
|
VOLUME /app/data
|
||||||
|
|
||||||
|
# --- Expose Port ---
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# --- Command to run the application ---
|
||||||
|
# Ensure the Hono app listens on 0.0.0.0
|
||||||
|
CMD ["bun", "run", "src/index.ts"]
|
||||||
9
compose.yaml
Normal file
9
compose.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
services:
|
||||||
|
safemarks-server:
|
||||||
|
build: .
|
||||||
|
container_name: safemarks-server
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- 17333:3000
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
||||||
39
spec/DOCKER_INSTRUCTIONS.md
Normal file
39
spec/DOCKER_INSTRUCTIONS.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# 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`
|
||||||
Reference in New Issue
Block a user