47 lines
1.7 KiB
Docker
47 lines
1.7 KiB
Docker
# Stage 1: Builder Stage – Generate and build the Medusa project silently
|
||
FROM node:20-alpine AS builder
|
||
|
||
WORKDIR /workspace
|
||
|
||
# Run the Medusa generator non-interactively.
|
||
# Options used:
|
||
# --db-url "postgres://medusa:medusa@db:5432/medusa" : Provide the database URL so it connects (and runs migrations & seeding).
|
||
# --no-browser : Do not open the browser after installation.
|
||
# --directory-path : Specify the installation directory.
|
||
# --seed : Seed the database with demo data.
|
||
RUN npx create-medusa-app@latest my-medusa-store \
|
||
--db-url "postgres://medusa:medusa@db:5432/medusa" \
|
||
--no-browser \
|
||
--directory-path /workspace/my-medusa-store \
|
||
--seed
|
||
|
||
# Change into the generated project directory.
|
||
WORKDIR /workspace/my-medusa-store
|
||
|
||
# Install dependencies and build the project.
|
||
RUN npm install && npm run build
|
||
|
||
# Stage 2: Production Stage – Build the final image to run the Medusa application
|
||
FROM node:20-alpine AS production
|
||
|
||
# Define default environment variables.
|
||
# These values can be overridden via Coolify’s UI.
|
||
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" (via Coolify) if you want to run a seed command at startup.
|
||
|
||
WORKDIR /app
|
||
|
||
# Copy the built application from the builder stage.
|
||
COPY --from=builder /workspace/my-medusa-store .
|
||
|
||
# Expose the default port for Medusa (which runs on 9000).
|
||
EXPOSE 9000
|
||
|
||
# Start the Medusa application.
|
||
# This command conditionally runs a seeding command if SEED_DATA is "true" and then starts the server.
|
||
CMD ["sh", "-c", "if [ \"$SEED_DATA\" = \"true\" ]; then npx medusa seed; fi && npm start"]
|