CoreControl/Dockerfile

53 lines
1.6 KiB
Docker
Raw Normal View History

2025-04-13 21:10:17 +02:00
# Builder Stage
2025-04-29 21:17:21 +02:00
FROM --platform=$BUILDPLATFORM node:20-alpine AS builder
2025-04-30 18:35:22 +02:00
ARG TARGETARCH # Automatically set by Buildx
2025-04-13 21:10:17 +02:00
WORKDIR /app
2025-04-30 18:35:22 +02:00
COPY package.json package-lock.json* ./
COPY ./prisma ./prisma
# Set PRISMA_CLI_BINARY_TARGETS based on TARGETARCH and install dependencies
2025-04-29 21:17:21 +02:00
RUN case ${TARGETARCH} in \
2025-04-30 18:47:09 +02:00
"amd64") export PRISMA_CLI_BINARY_TARGETS="linux-musl-openssl-3.0.x" ;; \
2025-04-29 21:17:21 +02:00
"arm64") export PRISMA_CLI_BINARY_TARGETS="linux-musl-arm64-openssl-3.0.x" ;; \
"arm") export PRISMA_CLI_BINARY_TARGETS="linux-musl-arm-openssl-3.0.x" ;; \
*) echo "Unsupported ARCH: ${TARGETARCH}" && exit 1 ;; \
2025-04-30 18:35:22 +02:00
esac && \
npm install && \
npx prisma generate
2025-04-13 21:10:17 +02:00
COPY . .
RUN npm run build
2025-04-14 17:19:13 +02:00
# Production Stage
2025-04-29 21:17:21 +02:00
FROM --platform=$TARGETPLATFORM node:20-alpine AS production
2025-04-13 21:10:17 +02:00
WORKDIR /app
2025-04-30 14:57:19 +02:00
ENV NODE_ENV production
2025-04-13 21:10:17 +02:00
2025-04-30 18:35:22 +02:00
# Copy built assets and dependencies from builder
2025-04-30 14:57:19 +02:00
COPY --from=builder /app/node_modules ./node_modules
2025-04-14 17:19:13 +02:00
COPY --from=builder /app/prisma ./prisma
2025-04-13 21:10:17 +02:00
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
2025-04-30 14:57:19 +02:00
COPY --from=builder /app/package.json ./package.json
2025-04-13 21:10:17 +02:00
COPY --from=builder /app/next.config.js* ./
2025-04-30 18:35:22 +02:00
# Prune dev dependencies
2025-04-30 14:57:19 +02:00
RUN npm prune --production
2025-04-29 21:17:21 +02:00
EXPOSE 3000
2025-04-30 18:35:22 +02:00
# Dynamically set PRISMA_CLI_BINARY_TARGETS based on runtime architecture and start
CMD ["sh", "-c", \
"export PRISMA_CLI_BINARY_TARGETS=$(case $(uname -m) in \
2025-04-30 18:47:09 +02:00
x86_64) echo 'linux-musl-openssl-3.0.x' ;; \
2025-04-30 18:35:22 +02:00
aarch64) echo 'linux-musl-arm64-openssl-3.0.x' ;; \
armv7l) echo 'linux-musl-arm-openssl-3.0.x' ;; \
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;; \
esac) && \
npx prisma migrate deploy && \
npm start"]