Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
node_modules
**/node_modules
**/lib
**/dist
**/*.tsbuildinfo
4 changes: 3 additions & 1 deletion .github/workflows/build-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.4.0
bun-version: 1.4.4
- uses: actions/setup-node@v6
with:
node-version: 24
Expand Down Expand Up @@ -116,6 +116,8 @@ jobs:
- name: Set up Docker Buildx
id: builder
uses: docker/setup-buildx-action@v1
- name: Smoke test production image
run: bash scripts/container-smoke.sh
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push image
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ jobs:
test:
name: Run all tests
runs-on: ubuntu-latest
container: oven/bun:1.4.0
container: oven/bun:1.4.4
steps:
- uses: actions/checkout@v4
- run: bun install --frozen-lockfile
- run: bun run build
- run: bun run typecheck
- run: bun run test
container-smoke:
name: Test production container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: bash scripts/container-smoke.sh
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM oven/bun:1.4.0-slim AS base
FROM oven/bun:1.4.4-slim AS base
WORKDIR /app

FROM base AS build
Expand All @@ -11,7 +11,8 @@ RUN bun install --frozen-lockfile && \
FROM base AS install
ENV NODE_ENV=production
COPY ./package.json bun.lock /app/
RUN bun install --no-save sharp
COPY ./packages /app/packages
RUN bun install --frozen-lockfile --production

FROM base AS prod
ENV NODE_ENV=production \
Expand Down
72 changes: 37 additions & 35 deletions bun.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"build:docker": "bun --filter @m4k/server build:docker",
"typecheck": "bun --filter '*' typecheck"
},
"dependencies": {
"sharp": "^0.35.5"
},
"devDependencies": {
"husky": "^9.1.7",
"sharp": "^0.35.3",
"typescript": "^7.0.2"
},
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@m4k/server": "workspace:^",
"bun-types": "^1.4.0",
"bun-types": "^1.4.4",
"typescript": "^7.0.2"
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"typescript": "^7.0.2"
},
"peerDependencies": {
"sharp": "^0.35.3"
"sharp": "^0.35.5"
}
}
4 changes: 2 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dev": "bun --watch src/index.ts",
"prepublishOnly": "bun run build",
"build": "tsc -b",
"build:docker": "bun build ./src/index.ts --outfile dist/server/app.js --target bun",
"build:docker": "bun build ./src/index.ts --outfile dist/server/app.js --target bun --external sharp",
"typecheck": "tsc --noEmit",
"test": "bun test"
},
Expand All @@ -40,7 +40,7 @@
},
"devDependencies": {
"@sinclair/typebox": "^0.34.52",
"bun-types": "^1.4.0",
"bun-types": "^1.4.4",
"typescript": "^7.0.2"
}
}
2 changes: 1 addition & 1 deletion packages/typebox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@sinclair/typebox": "^0.34.52"
},
"devDependencies": {
"bun-types": "^1.4.0",
"bun-types": "^1.4.4",
"typescript": "^7.0.2"
},
"repository": {
Expand Down
8 changes: 8 additions & 0 deletions scripts/container-smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
image="${1:-m4k:smoke}"
docker build --tag "$image" .
container=$(docker run --detach --mount "type=bind,source=$PWD/fixtures,target=/fixtures,readonly" "$image")
trap 'docker logs "$container"; docker rm --force "$container" >/dev/null' EXIT
docker exec --interactive "$container" bun run - < scripts/container-smoke.ts
31 changes: 31 additions & 0 deletions scripts/container-smoke.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Runs inside the production container, against its actual HTTP server.
import { strict as assert } from "node:assert";

const url = "http://127.0.0.1:3000";
let ready = false;
for (let attempt = 0; attempt < 50; attempt++) {
try {
const response = await fetch(`${url}/info`);
assert.equal(response.status, 200);
assert.equal((await response.json()).service, "m4k");
ready = true;
break;
} catch {
await Bun.sleep(100);
}
}
assert.ok(ready, "Server did not become ready");
const response = await fetch(`${url}/images/process`, {
method: "POST",
headers: { "X-Options": JSON.stringify({ format: "webp", resize: { width: 100 } }) },
body: Bun.file("/fixtures/image.jpeg"),
signal: AbortSignal.timeout(15000),
});
assert.equal(response.status, 200);
const body = Buffer.from(await response.arrayBuffer());
assert.ok(body.includes(Buffer.from("image/webp")), "Missing converted image part");
const start = body.indexOf(Buffer.from("RIFF"));
assert.ok(start >= 0, "Missing WebP data");
assert.equal(body.subarray(start + 8, start + 12).toString(), "WEBP");
assert.ok(body.includes(Buffer.from('"progress":100')), "Conversion did not complete");
console.log("Container smoke test passed: /info and JPEG → WebP");
Loading