9 Commits

Author SHA1 Message Date
300df27aae Merge pull request 'fix: webpack build, low memory limits, and sitemap try/catch for Docker deploy' (#10) from fix/all-deploy-fixes into main
Reviewed-on: #10
2026-11-23 01:00:52 +00:00
Nermin Karic
899ed44562 fix: webpack build, low memory limits, and sitemap try/catch for Docker deploy
- Switch both storefronts from Turbopack to Webpack (next build --webpack)
- Limit build workers to 1 CPU (experimental.cpus: 1)
- Reduce NODE_OPTIONS max-old-space-size from 2048 to 1024 MB
- Wrap sitemap.ts API calls in try/catch to prevent build crash when backend is unavailable during Docker build
- During build, sitemap returns static paths only; at runtime it fetches full dynamic data
2026-11-23 01:59:50 +01:00
f97a309c21 Merge pull request 'fix: add fallback publishable keys and memory limits for storefront builds' (#8) from fix/storefront-build-env into main
Reviewed-on: #8
2026-11-23 00:37:06 +00:00
Nermin Karic
aab60fc8d4 fix: add fallback publishable keys and memory limits for storefront builds 2026-11-23 01:36:47 +01:00
ec3a4e6efc Merge pull request 'fix: set runner WORKDIR to .medusa/server for custom module resolution' (#7) from fix/dokploy-build-memory into main
Reviewed-on: #7
2026-11-23 00:14:26 +00:00
Nermin Karic
3ed45c4362 fix: set runner WORKDIR to .medusa/server for custom module resolution 2026-11-23 01:11:52 +01:00
e2279993ae Merge pull request 'design upgrade' (#6) from feat/design-upgrade into main
Reviewed-on: #6
2026-11-23 00:00:05 +00:00
d3012c6f31 Merge pull request 'fix: copy compiled medusa-config.js for production runtime' (#5) from fix/dokploy-build-memory into main
Reviewed-on: #5
2026-11-22 22:14:23 +00:00
Nermin Karic
df9f8b3a7c fix: copy compiled medusa-config.js for production runtime 2026-11-22 23:13:23 +01:00
15 changed files with 158 additions and 102 deletions

View File

@@ -26,19 +26,16 @@ COPY apps/backend ./apps/backend
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=2048"
# Build Medusa backend and admin dashboard
# Build Medusa backend and admin dashboard (compiled to .medusa/server)
RUN npm run build --workspace=@dtc/backend
# Copy compiled medusa-config.js and instrumentation.js to project root for production Node.js runtime
RUN cp apps/backend/.medusa/server/medusa-config.js apps/backend/medusa-config.js && \
if [ -f apps/backend/.medusa/server/instrumentation.js ]; then cp apps/backend/.medusa/server/instrumentation.js apps/backend/instrumentation.js; fi
# Prune devDependencies to keep image light and avoid OOM during copy
RUN npm prune --production --workspace=@dtc/backend
# 3. Production runner stage
# In Medusa v2, production runtime runs from the compiled .medusa/server directory
FROM node:22-alpine AS runner
WORKDIR /app/apps/backend
WORKDIR /app/apps/backend/.medusa/server
RUN apk add --no-cache libc6-compat curl
@@ -49,17 +46,18 @@ ENV PORT=9000
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 medusa
# Copy pruned dependencies from builder (sequential dependency prevents BuildKit parallel I/O spike)
# Copy dependencies and compiled server artifacts
COPY --from=builder --chown=medusa:nodejs /app/node_modules /app/node_modules
COPY --from=builder --chown=medusa:nodejs /app/package.json /app/package-lock.json /app/
COPY --from=builder --chown=medusa:nodejs /app/apps/backend /app/apps/backend
# Uploads directory
RUN mkdir -p /app/apps/backend/uploads && chown -R medusa:nodejs /app/apps/backend/uploads
RUN mkdir -p /app/apps/backend/.medusa/server/uploads /app/apps/backend/uploads && \
chown -R medusa:nodejs /app/apps/backend
USER medusa
EXPOSE 9000
# Run migrations and start Medusa production server
# Medusa v2 production entrypoint: run migrations then start server from compiled .medusa/server
CMD ["sh", "-c", "npx medusa db:migrate && npm run start"]

View File

@@ -25,19 +25,16 @@ COPY apps/backend ./apps/backend
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=2048"
# Build Medusa backend and admin dashboard
# Build Medusa backend and admin dashboard (compiled to .medusa/server)
RUN npm run build --workspace=@dtc/backend
# Copy compiled medusa-config.js and instrumentation.js to project root for production Node.js runtime
RUN cp apps/backend/.medusa/server/medusa-config.js apps/backend/medusa-config.js && \
if [ -f apps/backend/.medusa/server/instrumentation.js ]; then cp apps/backend/.medusa/server/instrumentation.js apps/backend/instrumentation.js; fi
# Prune devDependencies to keep image light and avoid OOM during copy
RUN npm prune --production --workspace=@dtc/backend
# 3. Production runner stage
# In Medusa v2, production runtime runs from the compiled .medusa/server directory
FROM node:22-alpine AS runner
WORKDIR /app/apps/backend
WORKDIR /app/apps/backend/.medusa/server
RUN apk add --no-cache libc6-compat curl
@@ -48,17 +45,18 @@ ENV PORT=9000
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 medusa
# Copy pruned dependencies from builder (sequential dependency prevents BuildKit parallel I/O spike)
# Copy dependencies and compiled server artifacts
COPY --from=builder --chown=medusa:nodejs /app/node_modules /app/node_modules
COPY --from=builder --chown=medusa:nodejs /app/package.json /app/package-lock.json /app/
COPY --from=builder --chown=medusa:nodejs /app/apps/backend /app/apps/backend
# Uploads directory
RUN mkdir -p /app/apps/backend/uploads && chown -R medusa:nodejs /app/apps/backend/uploads
RUN mkdir -p /app/apps/backend/.medusa/server/uploads /app/apps/backend/uploads && \
chown -R medusa:nodejs /app/apps/backend
USER medusa
EXPOSE 9000
# Run migrations and start Medusa production server
# Medusa v2 production entrypoint: run migrations then start server from compiled .medusa/server
CMD ["sh", "-c", "npx medusa db:migrate && npm run start"]

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@medusajs/framework/utils");
(0, utils_1.loadEnv)(process.env.NODE_ENV || 'development', process.cwd());
module.exports = (0, utils_1.defineConfig)({
projectConfig: {
databaseUrl: process.env.DATABASE_URL,
http: {
storeCors: process.env.STORE_CORS,
adminCors: process.env.ADMIN_CORS,
authCors: process.env.AUTH_CORS,
jwtSecret: process.env.JWT_SECRET,
cookieSecret: process.env.COOKIE_SECRET,
}
},
modules: [
{
resolve: "./src/modules/inquiry",
},
],
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVkdXNhLWNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL21lZHVzYS1jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxxREFBaUU7QUFFakUsSUFBQSxlQUFPLEVBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLElBQUksYUFBYSxFQUFFLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQyxDQUFBO0FBRTdELE1BQU0sQ0FBQyxPQUFPLEdBQUcsSUFBQSxvQkFBWSxFQUFDO0lBQzVCLGFBQWEsRUFBRTtRQUNiLFdBQVcsRUFBRSxPQUFPLENBQUMsR0FBRyxDQUFDLFlBQVk7UUFDckMsSUFBSSxFQUFFO1lBQ0osU0FBUyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVztZQUNsQyxTQUFTLEVBQUUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxVQUFXO1lBQ2xDLFFBQVEsRUFBRSxPQUFPLENBQUMsR0FBRyxDQUFDLFNBQVU7WUFDaEMsU0FBUyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVTtZQUNqQyxZQUFZLEVBQUUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxhQUFhO1NBQ3hDO0tBQ0Y7SUFDRCxPQUFPLEVBQUU7UUFDUDtZQUNFLE9BQU8sRUFBRSx1QkFBdUI7U0FDakM7S0FDRjtDQUNGLENBQUMsQ0FBQSJ9

View File

@@ -20,9 +20,9 @@ WORKDIR /app
COPY apps/suman-bosna ./apps/suman-bosna
ARG NEXT_PUBLIC_MEDUSA_BACKEND_URL
ARG NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY
ARG NEXT_PUBLIC_BASE_URL
ARG NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://backend:9000
ARG NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_b722e44870bc8cc7828d0713980537e95b2e74ff229a529a4b3fa8155035f1f0
ARG NEXT_PUBLIC_BASE_URL=http://localhost:8000
ARG NEXT_PUBLIC_DEFAULT_REGION=ba
ENV NEXT_PUBLIC_MEDUSA_BACKEND_URL=$NEXT_PUBLIC_MEDUSA_BACKEND_URL
@@ -30,6 +30,7 @@ ENV NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=$NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
ENV NEXT_PUBLIC_DEFAULT_REGION=$NEXT_PUBLIC_DEFAULT_REGION
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=1024"
RUN npm run build --workspace=@dtc/suman-bosna

View File

@@ -10,6 +10,10 @@ const requiredEnvs = [
];
function checkEnvVariables() {
if (!process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY) {
process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY = "pk_b722e44870bc8cc7828d0713980537e95b2e74ff229a529a4b3fa8155035f1f0";
}
const missingEnvs = requiredEnvs.filter(function (env) {
c;
return !process.env[env.key];

View File

@@ -13,6 +13,9 @@ const S3_PATHNAME = process.env.MEDUSA_CLOUD_S3_PATHNAME
*/
const nextConfig = {
reactStrictMode: true,
experimental: {
cpus: 1,
},
async headers() {
return [
{

View File

@@ -9,7 +9,7 @@
],
"scripts": {
"dev": "next dev -p 8000",
"build": "next build",
"build": "next build --webpack",
"start": "next start -p 8000",
"lint": "eslint .",
"analyze": "ANALYZE=true next build"

View File

@@ -30,43 +30,54 @@ async function listAll<T>(fetchPage: (offset: number) => Promise<Page<T>>) {
type Entry = { handle?: string | null; updated_at?: string | Date | null }
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
const origin = await getSiteOrigin()
const [origin, regions, products, categories, collections] = await Promise.all([
getSiteOrigin(),
listRegions(),
listAll<Entry>((offset) =>
sdk.store.product
.list({ ...query, offset })
.then((res) => ({ items: res.products, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({ items: res.product_categories, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
try {
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
const toEntries = (base: string, prefix: string, items: Entry[]) =>
items
.filter((item) => item.handle)
.map((item) => ({
url: `${base}/${prefix}/${item.handle}`,
lastModified: item.updated_at ? new Date(item.updated_at) : undefined,
}))
const [regions, products, categories, collections] = await Promise.all([
listRegions(),
listAll<Entry>((offset) =>
sdk.store.product
.list({ ...query, offset })
.then((res) => ({ items: res.products, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({
items: res.product_categories,
count: res.count,
}))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
return listCountryCodes(regions).flatMap((countryCode) => {
const base = `${origin}/${countryCode}`
return [
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
...toEntries(base, "products", products),
...toEntries(base, "categories", categories),
...toEntries(base, "collections", collections),
]
})
const toEntries = (base: string, prefix: string, items: Entry[]) =>
items
.filter((item) => item.handle)
.map((item) => ({
url: `${base}/${prefix}/${item.handle}`,
lastModified: item.updated_at
? new Date(item.updated_at)
: undefined,
}))
return listCountryCodes(regions).flatMap((countryCode) => {
const base = `${origin}/${countryCode}`
return [
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
...toEntries(base, "products", products),
...toEntries(base, "categories", categories),
...toEntries(base, "collections", collections),
]
})
} catch {
// During Docker build the backend is not running — return static paths only
return STATIC_PATHS.map((path) => ({ url: `${origin}${path}` }))
}
}

View File

@@ -20,9 +20,9 @@ WORKDIR /app
COPY apps/suman-hrvatska ./apps/suman-hrvatska
ARG NEXT_PUBLIC_MEDUSA_BACKEND_URL
ARG NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY
ARG NEXT_PUBLIC_BASE_URL
ARG NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://backend:9000
ARG NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_suman_hrvatska_publishable_key
ARG NEXT_PUBLIC_BASE_URL=http://localhost:8002
ARG NEXT_PUBLIC_DEFAULT_REGION=hr
ENV NEXT_PUBLIC_MEDUSA_BACKEND_URL=$NEXT_PUBLIC_MEDUSA_BACKEND_URL
@@ -30,6 +30,7 @@ ENV NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=$NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
ENV NEXT_PUBLIC_DEFAULT_REGION=$NEXT_PUBLIC_DEFAULT_REGION
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=1024"
RUN npm run build --workspace=@dtc/suman-hrvatska

View File

@@ -10,6 +10,10 @@ const requiredEnvs = [
];
function checkEnvVariables() {
if (!process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY) {
process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY = "pk_suman_hrvatska_publishable_key";
}
const missingEnvs = requiredEnvs.filter(function (env) {
c;
return !process.env[env.key];

View File

@@ -13,6 +13,9 @@ const S3_PATHNAME = process.env.MEDUSA_CLOUD_S3_PATHNAME
*/
const nextConfig = {
reactStrictMode: true,
experimental: {
cpus: 1,
},
async headers() {
return [
{

View File

@@ -9,7 +9,7 @@
],
"scripts": {
"dev": "next dev -p 8002",
"build": "next build",
"build": "next build --webpack",
"start": "next start -p 8002",
"lint": "eslint .",
"analyze": "ANALYZE=true next build"

View File

@@ -30,43 +30,54 @@ async function listAll<T>(fetchPage: (offset: number) => Promise<Page<T>>) {
type Entry = { handle?: string | null; updated_at?: string | Date | null }
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
const origin = await getSiteOrigin()
const [origin, regions, products, categories, collections] = await Promise.all([
getSiteOrigin(),
listRegions(),
listAll<Entry>((offset) =>
sdk.store.product
.list({ ...query, offset })
.then((res) => ({ items: res.products, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({ items: res.product_categories, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
try {
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
const toEntries = (base: string, prefix: string, items: Entry[]) =>
items
.filter((item) => item.handle)
.map((item) => ({
url: `${base}/${prefix}/${item.handle}`,
lastModified: item.updated_at ? new Date(item.updated_at) : undefined,
}))
const [regions, products, categories, collections] = await Promise.all([
listRegions(),
listAll<Entry>((offset) =>
sdk.store.product
.list({ ...query, offset })
.then((res) => ({ items: res.products, count: res.count }))
),
listAll<Entry>((offset) =>
sdk.store.category
.list({ ...query, offset })
.then((res) => ({
items: res.product_categories,
count: res.count,
}))
),
listAll<Entry>((offset) =>
sdk.store.collection
.list({ ...query, offset })
.then((res) => ({ items: res.collections, count: res.count }))
),
])
return listCountryCodes(regions).flatMap((countryCode) => {
const base = `${origin}/${countryCode}`
return [
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
...toEntries(base, "products", products),
...toEntries(base, "categories", categories),
...toEntries(base, "collections", collections),
]
})
const toEntries = (base: string, prefix: string, items: Entry[]) =>
items
.filter((item) => item.handle)
.map((item) => ({
url: `${base}/${prefix}/${item.handle}`,
lastModified: item.updated_at
? new Date(item.updated_at)
: undefined,
}))
return listCountryCodes(regions).flatMap((countryCode) => {
const base = `${origin}/${countryCode}`
return [
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
...toEntries(base, "products", products),
...toEntries(base, "categories", categories),
...toEntries(base, "collections", collections),
]
})
} catch {
// During Docker build the backend is not running — return static paths only
return STATIC_PATHS.map((path) => ({ url: `${origin}${path}` }))
}
}

View File

@@ -103,7 +103,7 @@ services:
dockerfile: apps/suman-bosna/Dockerfile
args:
NEXT_PUBLIC_MEDUSA_BACKEND_URL: ${MEDUSA_BACKEND_URL:-http://backend:9000}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_BA:-}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_BA:-pk_b722e44870bc8cc7828d0713980537e95b2e74ff229a529a4b3fa8155035f1f0}
NEXT_PUBLIC_BASE_URL: ${STOREFRONT_BA_BASE_URL:-http://localhost:8000}
NEXT_PUBLIC_DEFAULT_REGION: ba
container_name: suman_prod_storefront_bosna
@@ -138,7 +138,7 @@ services:
dockerfile: apps/suman-hrvatska/Dockerfile
args:
NEXT_PUBLIC_MEDUSA_BACKEND_URL: ${MEDUSA_BACKEND_URL:-http://backend:9000}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_HR:-}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_HR:-pk_suman_hrvatska_publishable_key}
NEXT_PUBLIC_BASE_URL: ${STOREFRONT_HR_BASE_URL:-http://localhost:8002}
NEXT_PUBLIC_DEFAULT_REGION: hr
container_name: suman_prod_storefront_hrvatska

View File

@@ -103,7 +103,7 @@ services:
dockerfile: apps/suman-bosna/Dockerfile
args:
NEXT_PUBLIC_MEDUSA_BACKEND_URL: ${MEDUSA_BACKEND_URL:-http://backend:9000}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_BA:-}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_BA:-pk_b722e44870bc8cc7828d0713980537e95b2e74ff229a529a4b3fa8155035f1f0}
NEXT_PUBLIC_BASE_URL: ${STOREFRONT_BA_BASE_URL:-http://localhost:8000}
NEXT_PUBLIC_DEFAULT_REGION: ba
container_name: suman_prod_storefront_bosna
@@ -138,7 +138,7 @@ services:
dockerfile: apps/suman-hrvatska/Dockerfile
args:
NEXT_PUBLIC_MEDUSA_BACKEND_URL: ${MEDUSA_BACKEND_URL:-http://backend:9000}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_HR:-}
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY: ${MEDUSA_PUBLISHABLE_KEY_HR:-pk_suman_hrvatska_publishable_key}
NEXT_PUBLIC_BASE_URL: ${STOREFRONT_HR_BASE_URL:-http://localhost:8002}
NEXT_PUBLIC_DEFAULT_REGION: hr
container_name: suman_prod_storefront_hrvatska