Skip to content

Commit 8d3c2c3

Browse files
committed
fix: resolve issue building docker image
1 parent 56ce13b commit 8d3c2c3

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

Dockerfile

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
FROM node:18-alpine AS builder
2-
ENV PNPM_VERSION=9.0.2
1+
FROM node:22-alpine AS builder
2+
ENV PNPM_VERSION=10.24.0
33

44
RUN corepack enable && \
55
corepack prepare pnpm@${PNPM_VERSION} --activate && \
66
pnpm config set store-dir /pnpm-store
77

8+
RUN mkdir -p /app && chown node:node /app
9+
10+
USER node
11+
812
WORKDIR /app
913

1014
# Files required by pnpm install
11-
COPY package.json pnpm-lock.yaml tsdown.config.js tsconfig.json /app/
15+
COPY --chown=node package.json pnpm-lock.yaml tsdown.config.js tsconfig.json /app/
1216

1317
RUN pnpm install --frozen-lockfile
1418

15-
# Bundle app source
16-
COPY src src
17-
COPY vendor vendor
18-
19-
RUN pnpm build:server
20-
21-
22-
FROM node:18-alpine
23-
WORKDIR /app
19+
COPY --chown=node src /app/src
20+
COPY --chown=node vendor /app/vendor
2421

25-
RUN adduser -D -u 8000 commercetools
2622

27-
COPY --from=builder /app/dist /app
23+
# Build server bundle
24+
RUN pnpm build:server
2825

2926
EXPOSE 8989
30-
ENV HTTP_SERVER_PORT 8989
27+
ENV HTTP_SERVER_PORT=8989
3128

32-
CMD ["node", "./server.js"]
29+
CMD ["node", "./dist/server.mjs"]

docker-compose.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3.9"
2+
3+
services:
4+
server:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "8989:8989"
10+
environment:
11+
NODE_ENV: production
12+
PORT: 8989
13+
restart: unless-stopped

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"scripts": {
2222
"build": "tsdown",
23-
"build:server": "esbuild src/server.ts --bundle --outfile=dist/server.js --platform=node",
23+
"build:server": "tsdown src/server.ts --platform=node",
2424
"check": "biome check && tsc",
2525
"format": "biome check --fix",
2626
"lint": "biome check",
@@ -65,10 +65,10 @@
6565
"typescript": "5.9.3",
6666
"vitest": "4.0.13"
6767
},
68-
"packageManager": "pnpm@10.8.0",
68+
"packageManager": "pnpm@10.24.0",
6969
"engines": {
7070
"node": ">=18",
71-
"pnpm": ">=9.0.2"
71+
"pnpm": ">=10.8.0"
7272
},
7373
"publishConfig": {
7474
"access": "public",

src/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ let port = 3000;
1111
if (process.env.HTTP_SERVER_PORT)
1212
port = Number.parseInt(process.env.HTTP_SERVER_PORT, 10);
1313

14+
// biome-ignore lint: lint/correctness/noConsoleLog
15+
console.info("Starting commercetools-mock on http://localhost:" + port);
1416
instance.runServer(port);

0 commit comments

Comments
 (0)