CI/CD
This commit is contained in:
+43
-56
@@ -1,80 +1,67 @@
|
||||
# Stage 1: Dependencies
|
||||
FROM node:20-alpine AS deps
|
||||
RUN npm config set registry https://package-mirror.liara.ir/repository/npm/
|
||||
# Install OpenSSL for Prisma
|
||||
RUN apk add --no-cache openssl libc6-compat
|
||||
FROM docker.iranserver.com/node:20-bookworm-slim AS base
|
||||
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
# Debian mirrors (Iranian)
|
||||
RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/* && \
|
||||
printf '%s\n' \
|
||||
'deb https://mirror-linux.runflare.com/debian/ bookworm main contrib non-free non-free-firmware' \
|
||||
'deb https://mirror-linux.runflare.com/debian/ bookworm-updates main contrib non-free non-free-firmware' \
|
||||
'deb https://mirror-linux.runflare.com/debian-security/ bookworm-security main contrib non-free non-free-firmware' \
|
||||
'' \
|
||||
'deb [trusted=yes] https://mirror2.chabokan.net/debian bookworm main contrib non-free non-free-firmware' \
|
||||
'deb [trusted=yes] https://mirror2.chabokan.net/debian-security bookworm-security main contrib non-free non-free-firmware' \
|
||||
'' \
|
||||
'deb http://mirror.iranserver.com/debian/ bookworm main contrib non-free non-free-firmware' \
|
||||
'deb-src http://mirror.iranserver.com/debian/ bookworm main contrib non-free non-free-firmware' \
|
||||
> /etc/apt/sources.list
|
||||
|
||||
# npm mirrors (Iranian)
|
||||
RUN npm config set registry https://package-mirror.liara.ir/repository/npm/ && \
|
||||
npm config set @runflare:registry https://mirror-npm.runflare.com/ && \
|
||||
npm config set @chabokan:registry https://mirror2.chabokan.net/npm/ && \
|
||||
npm config set strict-ssl false && \
|
||||
npm config set fetch-retries 5 && \
|
||||
npm config set fetch-retry-mintimeout 20000
|
||||
|
||||
# ---- deps stage ----
|
||||
FROM base AS deps
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package.json ./
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Install dependencies (skip scripts to avoid postinstall which needs source code)
|
||||
RUN npm install --ignore-scripts
|
||||
# ---- build stage ----
|
||||
FROM base AS builder
|
||||
|
||||
# Stage 2: Builder
|
||||
FROM node:20-alpine AS builder
|
||||
RUN npm config set registry https://package-mirror.liara.ir/repository/npm/
|
||||
# Install OpenSSL for Prisma
|
||||
RUN apk add --no-cache openssl libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# Copy dependencies from deps stage
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=deps /app/package.json ./package.json
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Set environment variables for build
|
||||
ARG NODE_ENV=production
|
||||
ARG NEXT_PUBLIC_APP_URL
|
||||
ARG NEXT_PUBLIC_DOCS_URL
|
||||
ARG API_URL
|
||||
ARG BASEPATH
|
||||
ARG MAPBOX_ACCESS_TOKEN
|
||||
ARG DATABASE_URL
|
||||
ENV NODE_ENV=production
|
||||
|
||||
ENV NODE_ENV=$NODE_ENV
|
||||
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
|
||||
ENV NEXT_PUBLIC_DOCS_URL=$NEXT_PUBLIC_DOCS_URL
|
||||
ENV API_URL=$API_URL
|
||||
ENV BASEPATH=$BASEPATH
|
||||
ENV MAPBOX_ACCESS_TOKEN=$MAPBOX_ACCESS_TOKEN
|
||||
ENV DATABASE_URL=$DATABASE_URL
|
||||
|
||||
# Generate Prisma Client and build icons (postinstall script)
|
||||
# These commands need the source code to be present
|
||||
RUN npm run build:icons
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# Stage 3: Runner
|
||||
FROM node:20-alpine AS runner
|
||||
RUN npm config set registry https://package-mirror.liara.ir/repository/npm/
|
||||
# ---- production stage ----
|
||||
FROM base AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=9031
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
|
||||
# Install OpenSSL for Prisma runtime
|
||||
RUN apk add --no-cache openssl libc6-compat
|
||||
RUN addgroup --system --gid 1001 nodejs && \
|
||||
adduser --system --uid 1001 nextjs
|
||||
|
||||
# Create a non-root user
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
# Copy necessary files from standalone build
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 9031
|
||||
|
||||
ENV PORT=9031
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
Reference in New Issue
Block a user