Dockerfile update
This commit is contained in:
parent
1a8e23215f
commit
afaebaa821
56
Dockerfile
56
Dockerfile
@ -1,14 +1,52 @@
|
|||||||
# Use an official Node.js image as the base
|
# Stage 1: Build Stage – Create a new Medusa application and build it
|
||||||
FROM node:16-alpine AS base
|
FROM node:20-alpine AS builder
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install dependencies
|
# Set the working directory for generation and installation
|
||||||
COPY package*.json ./
|
WORKDIR /workspace
|
||||||
|
|
||||||
|
# Run the Medusa app generator non-interactively using default options.
|
||||||
|
# This will create a new Medusa project named "my-medusa-store" in the /workspace directory.
|
||||||
|
RUN npx create-medusa-app@latest my-medusa-store --yes
|
||||||
|
|
||||||
|
# Change directory into the generated Medusa project.
|
||||||
|
WORKDIR /workspace/my-medusa-store
|
||||||
|
|
||||||
|
# Install project dependencies (Medusa and its related packages are installed by the generator).
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
# Copy code and build for production
|
# Build the Medusa project for production.
|
||||||
FROM base AS production
|
|
||||||
COPY . .
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# Optionally, you could run a seed script here if you want seeding done during the build:
|
||||||
|
# RUN if [ "$SEED_DATA" = "true" ]; then npx medusa seed; fi
|
||||||
|
|
||||||
|
|
||||||
|
# Stage 2: Runner Stage – Create the final production image
|
||||||
|
FROM node:20-alpine AS runner
|
||||||
|
|
||||||
|
# Set production environment and default configuration variables.
|
||||||
|
# These environment variables can be overridden via Coolify.
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV DATABASE_URL=postgres://medusa:medusa@db:5432/medusa
|
||||||
|
ENV MEDUSA_STORE_NAME="My Medusa Store"
|
||||||
|
ENV MEDUSA_ADMIN_EMAIL="admin@medusajs.com"
|
||||||
|
ENV MEDUSA_ADMIN_PASSWORD="supersecret"
|
||||||
|
ENV SEED_DATA="false" # Set to "true" in Coolify to run seed scripts on startup
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the built Medusa application from the builder stage into the final image.
|
||||||
|
COPY --from=builder /workspace/my-medusa-store .
|
||||||
|
|
||||||
|
# Expose the default port that the Medusa server listens on.
|
||||||
EXPOSE 9000
|
EXPOSE 9000
|
||||||
CMD ["npm", "start"]
|
|
||||||
|
# (Optional) Create an admin user if needed.
|
||||||
|
# If you want the container itself to create an admin user at startup,
|
||||||
|
# you could include a command like the following.
|
||||||
|
# It depends on having your CLI support non-interactive admin creation.
|
||||||
|
# RUN if [ "$CREATE_ADMIN" = "true" ]; then npx medusa user -e "$MEDUSA_ADMIN_EMAIL" -p "$MEDUSA_ADMIN_PASSWORD"; fi
|
||||||
|
|
||||||
|
# Start up the Medusa application.
|
||||||
|
# This command conditionally runs the seed command if SEED_DATA is set to "true" and then starts the server.
|
||||||
|
CMD ["sh", "-c", "if [ \"$SEED_DATA\" = \"true\" ]; then npx medusa seed; fi && npm start"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user