Skip to content

Commit 1bd93bb

Browse files
mjunaidcaclaude
andcommitted
fix(sso): Switch Dockerfiles from alpine to slim for QEMU compatibility
The alpine-based images cause "Illegal instruction" errors during cross-platform builds (ARM64) due to musl libc issues with QEMU emulation. Changes: - Dockerfile: node:22-alpine → node:22-slim - Dockerfile.migrator: node:22-alpine → node:22-slim - Remove apk commands, use apt-get for Debian - Update healthcheck to use Node.js fetch instead of wget - Update migrate.sh to use bash instead of sh 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c14db49 commit 1bd93bb

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

apps/sso/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
# Next.js 15 SSO Platform Dockerfile
44
# ============================================================================
55
# Slim production image - migrations run separately on first deploy
6+
# Using node:22-slim (Debian) instead of alpine for better glibc compatibility
7+
# and to avoid QEMU emulation issues during cross-platform builds
68
# ============================================================================
79

810
# ----- Stage 1: Dependencies -----
9-
FROM node:22-alpine AS deps
11+
FROM node:22-slim AS deps
1012

11-
RUN apk add --no-cache libc6-compat
1213
WORKDIR /app
1314

1415
RUN corepack enable && corepack prepare pnpm@latest --activate
@@ -17,7 +18,7 @@ COPY package.json pnpm-lock.yaml ./
1718
RUN pnpm install --frozen-lockfile
1819

1920
# ----- Stage 2: Builder -----
20-
FROM node:22-alpine AS builder
21+
FROM node:22-slim AS builder
2122

2223
WORKDIR /app
2324
RUN corepack enable && corepack prepare pnpm@latest --activate
@@ -43,7 +44,7 @@ ENV DOCKER_BUILD=true
4344
RUN pnpm build
4445

4546
# ----- Stage 3: Runner (slim production image) -----
46-
FROM node:22-alpine AS runner
47+
FROM node:22-slim AS runner
4748

4849
WORKDIR /app
4950

@@ -66,6 +67,6 @@ USER nextjs
6667
EXPOSE 3001
6768

6869
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
69-
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:3001/api/health || exit 1
70+
CMD node -e "fetch('http://127.0.0.1:3001/api/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"
7071

7172
CMD ["node", "server.js"]

apps/sso/Dockerfile.migrator

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# SSO Platform Migrator - Lightweight init container for DB migrations
33
# ============================================================================
44
# Runs migrations and seeding before main services start
5+
# Using node:22-slim (Debian) for better glibc compatibility
56
# ============================================================================
67

7-
FROM node:22-alpine
8+
FROM node:22-slim
89

9-
RUN apk add --no-cache libc6-compat
1010
WORKDIR /app
1111

1212
RUN corepack enable && corepack prepare pnpm@latest --activate
@@ -22,17 +22,22 @@ RUN pnpm install --frozen-lockfile --ignore-scripts
2222

2323
# Migration script
2424
COPY <<'EOF' /app/migrate.sh
25-
#!/bin/sh
25+
#!/bin/bash
2626
set -e
2727

2828
echo "=== SSO Platform Migrations ==="
2929
echo "Waiting for database..."
3030

31-
# Wait for postgres to be ready
32-
until pg_isready -h ${DB_HOST:-postgres} -p ${DB_PORT:-5432} -U ${DB_USER:-postgres} 2>/dev/null; do
33-
echo "Waiting for postgres..."
34-
sleep 2
35-
done
31+
# Wait for postgres to be ready (using pg_isready if available, otherwise skip wait)
32+
if command -v pg_isready &> /dev/null; then
33+
until pg_isready -h ${DB_HOST:-postgres} -p ${DB_PORT:-5432} -U ${DB_USER:-postgres} 2>/dev/null; do
34+
echo "Waiting for postgres..."
35+
sleep 2
36+
done
37+
else
38+
echo "pg_isready not available, waiting 5s..."
39+
sleep 5
40+
fi
3641

3742
echo "Database ready. Running migrations..."
3843
pnpm db:push
@@ -43,6 +48,8 @@ pnpm seed:setup
4348
echo "=== Migrations complete ==="
4449
EOF
4550

46-
RUN apk add --no-cache postgresql-client && chmod +x /app/migrate.sh
51+
RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client \
52+
&& rm -rf /var/lib/apt/lists/* \
53+
&& chmod +x /app/migrate.sh
4754

4855
CMD ["/app/migrate.sh"]

0 commit comments

Comments
 (0)