51 lines
1.6 KiB
Docker
51 lines
1.6 KiB
Docker
|
FROM node:20-alpine AS base
|
||
|
|
||
|
# Install dependencies only when needed
|
||
|
FROM base AS deps
|
||
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||
|
RUN apk add --no-cache python3
|
||
|
WORKDIR /app
|
||
|
|
||
|
# Install dependencies based on the preferred package manager
|
||
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||
|
RUN \
|
||
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||
|
elif [ -f package-lock.json ]; then npm ci; \
|
||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||
|
else echo "Lockfile not found." && exit 1; \
|
||
|
fi
|
||
|
|
||
|
FROM base as builder
|
||
|
|
||
|
WORKDIR /app
|
||
|
COPY --from=deps /app/node_modules ./node_modules
|
||
|
COPY . .
|
||
|
|
||
|
RUN \
|
||
|
if [ -f yarn.lock ]; then yarn run build; \
|
||
|
elif [ -f package-lock.json ]; then npm run build; \
|
||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||
|
else echo "Lockfile not found." && exit 1; \
|
||
|
fi
|
||
|
|
||
|
|
||
|
# Production image, copy all the files and run next
|
||
|
FROM base AS runner
|
||
|
WORKDIR /app
|
||
|
|
||
|
COPY --from=builder /app/package.json /app/yarn.lock* /app/package-lock.json* /app/pnpm-lock.yaml* ./
|
||
|
|
||
|
RUN apk add --no-cache python3 && \
|
||
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile --production; \
|
||
|
elif [ -f package-lock.json ]; then npm ci --production; \
|
||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile --prod; \
|
||
|
else echo "Lockfile not found." && exit 1; \
|
||
|
fi
|
||
|
|
||
|
COPY --from=builder /app/dist ./
|
||
|
COPY --from=builder /app/medusa-config.js ./
|
||
|
COPY --from=builder /app/develop.sh ./
|
||
|
|
||
|
EXPOSE 9000
|
||
|
|
||
|
ENTRYPOINT ["./develop.sh", "start"]
|