Skip to content

Commit b44d4e2

Browse files
fix: simplify Dockerfiles for api-main and reader-main (#490)
* refactor: simplify Dockerfiles for api-main and reader-main * Removed multi-stage build setup and unnecessary workspace copying. * Updated working directory to /app for consistency. * fix: re-add NODE_TLS_REJECT_UNAUTHORIZED * refactor: reduce docker images by copying only required code into stage 2 * chore: remove PostgreSQL replication setup SQL file Replication subscriber is now initialized when first run by the feed sync app. Also removing the SQL file fixes an issue that made PostgreSQl docker initialization fail. * fix: change Docker files to use `--frozen-lockfile` Done to have reproducible builds, otherwise we could have unexpected issues with dependencies. --------- Co-authored-by: jeronimoalbi <894299+jeronimoalbi@users.noreply.github.com>
1 parent 0b22108 commit b44d4e2

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ services:
1414
- '5432:5432'
1515
volumes:
1616
- ./packages/postgresql/postgresql.conf:/etc/postgresql/postgresql.conf:ro
17-
- ./packages/postgresql/setup-replication.sql:/docker-entrypoint-initdb.d/setup-replication.sql
1817
- ./data/postgres_data:/var/lib/postgresql/18/data
1918
healthcheck:
2019
test: [CMD, pg_isready, -U, default]

packages/api-main/Dockerfile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
FROM oven/bun:1.3.2-slim AS base
1+
# Stage 1: Dependencies installation
2+
FROM oven/bun:1.3.2-slim AS deps
3+
WORKDIR /app
24

3-
FROM base AS build
4-
WORKDIR /workspace
5+
# Copy all monorepo files, excluding the ones ignored by dockerignore.
6+
# This is required because Bun needs all monorepo apps to be able to install deps using `--frozen-lockfile`.
57
COPY . .
68

7-
# Install all workspace dependencies first
8-
# Cache bun's global install cache for faster builds
9+
# Install dependencies with cache
910
RUN --mount=type=cache,id=bun-cache,target=/root/.bun/install/cache \
1011
bun install --frozen-lockfile
1112

12-
FROM base AS runtime
13+
# Stage 2: Runtime
14+
FROM oven/bun:1.3.2-slim AS runtime
1315
WORKDIR /app
1416

15-
# Copy workspace structure (needed for drizzle-kit workspace resolution)
16-
COPY --from=build /workspace/packages/api-main ./packages/api-main
17+
# Copy installed dependencies from deps stage (only root node_modules, bun hoists workspace deps)
18+
COPY --from=deps /app/node_modules ./node_modules
19+
20+
# Copy workspace files and packages from deps stage
21+
COPY --from=deps /app/package.json /app/bun.lock /app/bunfig.toml ./
22+
COPY --from=deps /app/packages/lib-api-types ./packages/lib-api-types
23+
COPY --from=deps /app/packages/api-main ./packages/api-main
1724

25+
# Set working directory to api-main package
1826
WORKDIR /app/packages/api-main
1927

2028
CMD ["bun", "run", "push-and-start"]

packages/postgresql/setup-replication.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/reader-main/Dockerfile

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
FROM oven/bun:1.3.2-slim AS base
1+
# Stage 1: Dependencies installation
2+
FROM oven/bun:1.3.2-slim AS deps
3+
WORKDIR /app
24

3-
FROM base AS build
4-
WORKDIR /workspace
5+
# Copy all monorepo files, excluding the ones ignored by dockerignore.
6+
# This is required because Bun needs all monorepo apps to be able to install deps using `--frozen-lockfile`.
57
COPY . .
68

7-
# Install all workspace dependencies first
8-
# Cache bun's global install cache for faster builds
9+
# Install dependencies with cache
910
RUN --mount=type=cache,id=bun-cache,target=/root/.bun/install/cache \
1011
bun install --frozen-lockfile
1112

12-
FROM base AS runtime
13-
ENV NODE_TLS_REJECT_UNAUTHORIZED=0
13+
# Stage 2: Runtime
14+
FROM oven/bun:1.3.2-slim AS runtime
1415
WORKDIR /app
16+
ENV NODE_TLS_REJECT_UNAUTHORIZED=0
17+
18+
# Copy installed dependencies from deps stage (only root node_modules, bun hoists workspace deps)
19+
COPY --from=deps /app/node_modules ./node_modules
20+
21+
# Copy workspace files and packages from deps stage
22+
COPY --from=deps /app/package.json /app/bun.lock /app/bunfig.toml ./
23+
COPY --from=deps /app/packages/lib-api-types ./packages/lib-api-types
24+
COPY --from=deps /app/packages/reader-main ./packages/reader-main
1525

16-
COPY --from=build /workspace/packages/reader-main ./
26+
# Set working directory to reader-main package
27+
WORKDIR /app/packages/reader-main
1728

1829
CMD ["bun", "run", "start"]

0 commit comments

Comments
 (0)