Experimental setup-docker -> build web / api fails

Hi there, i am struggeling to get the docker-compose.prod.yml to work.
besides the env variables i did not really change anything in the docker-compose file.

No matter what i try i continue to get this error message when trying to build the container:

 => CANCELED [rw_new-web web_build 3/3] RUN yarn rw build web --no-prerender                                                                                                                                                                                            2.2s
 => ERROR [rw_new-web web_serve 10/14] RUN --mount=type=cache,target=/home/node/.yarn/berry/cache,uid=1000     --mount=type=cache,target=/home/node/.cache,uid=1000     CI=1 yarn workspaces focus web --production                                                     1.9s
------
 > [rw_new-web web_serve 10/14] RUN --mount=type=cache,target=/home/node/.yarn/berry/cache,uid=1000     --mount=type=cache,target=/home/node/.cache,uid=1000     CI=1 yarn workspaces focus web --production:
#0 1.784 Internal Error: ENOENT: no such file or directory, stat '/home/node/app/.yarn/releases/yarn-4.1.0.cjs'
#0 1.784 Error: ENOENT: no such file or directory, stat '/home/node/app/.yarn/releases/yarn-4.1.0.cjs'
------
failed to solve: executor failed running [/bin/sh -c CI=1 yarn workspaces focus web --production]: exit code: 1
  • changed the yarn version from 3 → 4. without any changes.
  • tried: yarn plugin import workspace-tools
  • added “packageManager”: “yarn@4.1.0”, to the package.json (also tried with 3.2.3)
  • copied .yarn/releases (COPY .yarn/releases .yarn/releases)

interestingly the docker-compose.dev.yml works including db access etc…

if there is anything i can provide, or any idea how i could fix this it would be great to hear :slight_smile: !

thanks a lot for any help!

1 Like

One thing to perhaps try is removing yarnPath from the .yarnrc.yml if it exists? It may also be helpful if you’re able to share your dockerfile too.

Hi, i forgot to mention - i have removed the yarnPath already from the .yarnrc.yml.
so no success here :confused: any other idea?

1 Like

Are you able to share the dockerfile? It could be helpful to see

Hi no problem:

here is the docker file, in my case called Dockerfile.testing:

# base
# ----
FROM node:20-bookworm-slim as base
RUN corepack enable

# We tried to make the Dockerfile as lean as possible. In some cases, that means we excluded a dependency your project needs.
# By far the most common is Python. If you're running into build errors because `python3` isn't available,
# uncomment the line below here and in other stages as necessary:
RUN apt-get update && apt-get install -y \
openssl \
# python3 make gcc \
&& rm -rf /var/lib/apt/lists/*
#

WORKDIR /home/node/app
COPY .yarn/releases .yarn/releases
COPY .yarn/plugins .yarn/plugins
COPY .yarn/patches .yarn/patches
COPY .yarnrc.yml .
COPY package.json .
COPY packages packages
COPY api/package.json api/
COPY web/package.json web/
COPY yarn.lock .
RUN mkdir -p /home/node/.yarn/berry/index
RUN mkdir -p /home/node/.cache
RUN --mount=type=cache,target=/home/node/.yarn/berry/cache,uid=1000 \
--mount=type=cache,target=/home/node/.cache,uid=1000 \
CI=1 yarn install
# RUN CI=1 yarn install
COPY redwood.toml .
COPY graphql.config.js .
COPY .env.defaults .env.defaults
# api build
# ---------
FROM base as api_build
# If your api side build relies on build-time environment variables,
# specify them here as ARGs. (But don't put secrets in your Dockerfile!)
#
# ARG MY_BUILD_TIME_ENV_VAR
COPY api api
COPY scripts scripts
COPY packages packages
RUN yarn rw build api
# web prerender build
# -------------------
FROM api_build as web_build_with_prerender
COPY web web
COPY packages packages
RUN yarn rw build web
# web build
# ---------
FROM base as web_build
COPY web web
COPY packages packages
RUN yarn rw build web --no-prerender
# api serve
# ---------
FROM node:20-bookworm-slim as api_serve
RUN apt install bash
RUN corepack enable
RUN apt-get update && apt-get install -y \
openssl \
# python3 make gcc \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /home/node/app
COPY .yarnrc.yml .
COPY package.json .
COPY api/package.json api/
COPY yarn.lock .
RUN mkdir -p /home/node/.yarn/berry/index
RUN mkdir -p /home/node/.cache
RUN --mount=type=cache,target=/home/node/.yarn/berry/cache,uid=1000 \
--mount=type=cache,target=/home/node/.cache,uid=1000 \
CI=1 yarn workspaces focus api --production
COPY redwood.toml .
COPY graphql.config.js .
COPY .env.defaults .env.defaults
COPY serve-api.sh .
COPY --from=api_build /home/node/app/api/dist /home/node/app/api/dist
COPY --from=api_build /home/node/app/api/db /home/node/app/api/db
COPY --from=api_build /home/node/app/node_modules/.prisma /home/node/app/node_modules/.prisma
ENV NODE_ENV=production
CMD [ "node_modules/.bin/rw-server", "api" ]
# web serve
# ---------
FROM node:20-bookworm-slim as web_serve
RUN corepack enable
WORKDIR /home/node/app
COPY .yarnrc.yml .
COPY package.json .
COPY web/package.json web/
COPY yarn.lock .
RUN mkdir -p /home/node/.yarn/berry/index
RUN --mount=type=cache,target=/home/node/.yarn/berry/cache,uid=1000 \
--mount=type=cache,target=/home/node/.cache,uid=1000 \
CI=1 yarn workspaces focus web --production
COPY redwood.toml .
COPY graphql.config.js .
COPY .env.defaults .env.defaults
COPY --from=web_build /home/node/app/web/dist /home/node/app/web/dist
ENV NODE_ENV=production \
API_PROXY_TARGET=http://api:8911
# We use the shell form here for variable expansion.
CMD "node_modules/.bin/rw-web-server" "--api-proxy-target" "$API_PROXY_TARGET"

# console
# -------
FROM base as console
# To add more packages:
#
# ```
# USER root
#
# RUN apt-get update && apt-get install -y \
# curl
#
#
# ```
COPY api api
COPY web web
COPY scripts scripts

the docker-compose.testing.yml looks like this:

version: "3.8"

services:
  api:
    build:
      context: .
      dockerfile: ./Dockerfile.testing
      target: api_serve
    ports:
      - "8911:8911"
    depends_on:
      - db


  web:
    build:
      context: .
      dockerfile: ./Dockerfile.testing
      target: web_serve
    ports:
      - "8910:8910"
    depends_on:
      - api
    environment:
      - API_HOST=http://api:8911

  db:
    image: postgis/postgis:latest
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgrespw
      POSTGRES_DB: postgres
    ports:
      - "5432:5432"
    # volumes:
      # - ./postgrestesting:/var/lib/postgresql/data


  # After starting with `docker compose -f ./docker-compose.prod.yml up`,
  # use the console to run commands in the container:
  #
  # ```
  # docker compose -f ./docker-compose.prod.yml run --rm -it console /bin/bash
  # ```
  console:
    user: root
    build:
      context: .
      dockerfile: ./Dockerfile.testing
      target: console
    tmpfs:
      - /tmp
    command: "true"
    env_file: .env

    depends_on:
      - db

i execute the compose file with:
docker compose -f ./docker-compose.testing.yml --env-file .env up

Thanks a lot for your time!

I did get a little bit further by also copying packages and .yarn to api_serve and web_serve

COPY .yarn .yarn
COPY packages packages

Cheers

Hi there, i think i almost have it running. The only thing i am wondering tho - where does rw-web-server come from in the web serving stage?

CMD "node_modules/.bin/rw-web-server" "--api-proxy-target" "$API_PROXY_TARGET"

i get it so far that all containers build, but when i run them the web container fails with this:


rw_new-web-1      | /bin/sh: 1: node_modules/.bin/rw-web-server: not found

Thanks again!!

EDIT: needed
“@redwoodjs/web-server”: “^6.6.4”,
in the web package.json…

3 Likes