I use API Platform 3.2.
I'm deploying my API Platform application with Nuxt, and when I run the command:
SERVER_NAME=your-domain-name.example.com \ APP_SECRET=ChangeMe \ POSTGRES_PASSWORD=ChangeMe \ CADDY_MERCURE_JWT_SECRET=ChangeThisMercureHubJWTSecretKey \ docker compose -f compose.yaml -f compose.prod.yaml up --wait
I have the following error:
ERROR [pwa builder 4/4] RUN PNPM install --frozen-lockfile --offline --prod && pnpm run build 4.9s
> [pwa builder 4/4] RUN PNPM install --frozen-lockfile --offline --prod && pnpm run build:
> 3.272 ? The modules directory at "/srv/app/node_modules" will be removed and reinstalled from scratch. Proceed? (Y/n) ‣ true
> 4.190 > nuxt-app@ build /srv/app
> 4.190 > nuxt build
> 4.190
> 4.196 sh: 1: nuxt: not found
> `4.199 ELIFECYCLE Command failed.
------
failed to solve: process "/bin/sh -c pnpm install --frozen-lockfile --offline --prod && \tpnpm run build" did not complete successfully: exit code: 1
Here is my pwa/Dockerfile:
#syntax=docker/dockerfile:1.4
# Versions
FROM node:lts AS node_upstream
# Base stage for dev and build
FROM node_upstream AS base
WORKDIR /srv/app
RUN corepack enable && \
corepack prepare --activate pnpm@latest && \
pnpm config -g set store-dir /.pnpm-store
# Development image
FROM base as dev
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME localhost
CMD ["sh", "-c", "pnpm install; pnpm dev"]
FROM base AS builder
COPY --link pnpm-lock.yaml ./
RUN pnpm fetch --prod
COPY --link . .
RUN pnpm install --frozen-lockfile --offline --prod && \
pnpm run build
# Production image, copy all the files and run nuxt
FROM node_upstream AS prod
WORKDIR /srv/app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs; \
adduser --system --uid 1001 nuxt
COPY --from=builder --link /srv/app/public ./public
USER nuxt
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME localhost
CMD ["node", "server.js"]
And my compose.prod.yaml:
# Production environment override
services:
php:
build:
context: ./api
target: frankenphp_prod
environment:
APP_SECRET: ${APP_SECRET}
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
pwa:
build:
context: ./pwa
target: prod
database:
environment:
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
This is the first time I've deployed API platform in production and I don't know where it could be coming from... Thanks for your help
I tried to do a pnpm install directly in pwa but it didn't work.
I solved my problem by changing the line COPY --from=builder --link /srv/app/public ./public
in my pwa/Dockerfile
to COPY --from=builder /srv/app/.output ./.output
and adding COPY --link package*.json ./
before pnpm install
. I also had to separate pnpm install
from RUN pnpm run build
and place COPY --link . .
between the two.
Finally, I replaced CMD ["node", "server.js"]
with CMD ["node", ".output/server/index.mjs" ]
at the end of the file.
Here's my final file :
#syntax=docker/dockerfile:1.4
# Versions
FROM node:lts AS node_upstream
# Base stage for dev and build
FROM node_upstream AS base
WORKDIR /srv/app
RUN corepack enable && \
corepack prepare --activate pnpm@latest && \
pnpm config -g set store-dir /.pnpm-store
# Development image
FROM base as dev
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME localhost
CMD ["sh", "-c", "pnpm install; pnpm dev"]
FROM base AS builder
COPY --link pnpm-lock.yaml ./
RUN pnpm fetch --prod
COPY --link package*.json ./
RUN pnpm install --frozen-lockfile --offline --prod
COPY --link . .
RUN pnpm run build
RUN pnpm prune
# Production image, copy all the files and run nuxt
FROM node_upstream AS prod
WORKDIR /srv/app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs; \
adduser --system --uid 1001 nuxt
COPY --from=builder /srv/app/.output ./.output
USER nuxt
EXPOSE 3000
ENV PORT 3000
ENV HOST localhost
CMD [ "node", ".output/server/index.mjs" ]
Hope this helps!