diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..54eda89 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +*.db +.git +python-ref +*.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c012431 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..0f0ca3b --- /dev/null +++ b/compose.yaml @@ -0,0 +1,9 @@ +services: + safemarks-server: + build: . + container_name: safemarks-server + restart: unless-stopped + ports: + - 17333:3000 + volumes: + - ./data:/app/data diff --git a/spec/DOCKER_INSTRUCTIONS.md b/spec/DOCKER_INSTRUCTIONS.md new file mode 100644 index 0000000..774b197 --- /dev/null +++ b/spec/DOCKER_INSTRUCTIONS.md @@ -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` \ No newline at end of file