Hi
I’m currently trying to deploy realtime with docker and running into the error Unknown directive "@live"
this is my docker-compose.dev.yml
version: "3.8"
services:
redwood:
build:
context: .
dockerfile: ./Dockerfile
target: base
command: >
sh -c "yarn redwood prisma generate &&
yarn redwood prisma migrate deploy &&
yarn redwood prisma db seed &&
yarn redwood dev"
volumes:
- .:/home/node/app
- node_modules:/home/node/app/node_modules
ports:
- "8910:8910"
depends_on:
- db
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
- TEST_DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood_test
- NODE_ENV=development
db:
image: postgres:16-bookworm
environment:
POSTGRES_USER: redwood
POSTGRES_PASSWORD: redwood
POSTGRES_DB: redwood
ports:
- "5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
test-db:
image: postgres:16-bookworm
environment:
POSTGRES_USER: redwood
POSTGRES_PASSWORD: redwood
POSTGRES_DB: redwood
ports:
- '5433:5432'
volumes:
- postgres-test:/var/lib/postgresql/data
console:
user: root
build:
context: .
dockerfile: ./Dockerfile
target: console
tmpfs:
- /tmp
command: "true"
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
- TEST_DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood_test
depends_on:
- db
volumes:
node_modules:
postgres:
postgres-test:
which works flawlessly with realtime liveQueries.
and this is my deploy docker-compose.prod.yml
version: "3.8"
services:
web:
build:
context: .
dockerfile: ./Dockerfile
target: web_serve
ports:
- "8910:8910"
depends_on:
- api
api:
build:
context: .
dockerfile: ./Dockerfile
target: api_serve
ports:
- "8911:8911"
depends_on:
- init
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
init:
build:
context: .
dockerfile: ./Dockerfile
target: console
command: >
sh -c "yarn redwood prisma migrate deploy"
depends_on:
- db
environment:
- DATABASE_URL=postgresql://redwood:redwood@db:5432/redwood
db:
image: postgres:16-bookworm
environment:
POSTGRES_USER: redwood
POSTGRES_PASSWORD: redwood
POSTGRES_DB: redwood
ports:
- "5432:5432"
and lastly… this is my Dockerfile
# base
# ------------------------------------------------
FROM node:20-bookworm-slim as base
# 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/*
USER node
WORKDIR /home/node/app
COPY --chown=node:node .yarn/plugins .yarn/plugins
COPY --chown=node:node .yarn/releases .yarn/releases
COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node package.json .
COPY --chown=node:node api/package.json api/package.json
COPY --chown=node:node web/package.json web/package.json
COPY --chown=node:node 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 install
COPY --chown=node:node redwood.toml .
COPY --chown=node:node graphql.config.js .
COPY --chown=node:node .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 --chown=node:node api api
RUN yarn redwood build api
# web prerender build
# ------------------------------------------------
FROM api_build as web_build_with_prerender
COPY --chown=node:node web web
RUN yarn redwood build web
# web build
# ------------------------------------------------
FROM base as web_build
COPY --chown=node:node web web
RUN yarn redwood build web --no-prerender
# serve api
# ------------------------------------------------
FROM node:20-bookworm-slim as api_serve
RUN apt-get update && apt-get install -y \
openssl \
# python3 make gcc \
&& rm -rf /var/lib/apt/lists/*
USER node
WORKDIR /home/node/app
COPY --chown=node:node .yarn/plugins .yarn/plugins
COPY --chown=node:node .yarn/releases .yarn/releases
COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node package.json .
COPY --chown=node:node api/package.json api/package.json
COPY --chown=node:node 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 api --production
COPY --chown=node:node redwood.toml .
COPY --chown=node:node graphql.config.js .
COPY --chown=node:node .env.defaults .env.defaults
COPY --chown=node:node --from=api_build /home/node/app/api/dist /home/node/app/api/dist
COPY --chown=node:node --from=api_build /home/node/app/api/db /home/node/app/api/db
COPY --chown=node:node --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", "--rootPath=/api" ]
# serve web
# ------------------------------------------------
FROM node:20-bookworm-slim as web_serve
USER node
WORKDIR /home/node/app
COPY --chown=node:node .yarn/plugins .yarn/plugins
COPY --chown=node:node .yarn/releases .yarn/releases
COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node package.json .
COPY --chown=node:node web/package.json web/
COPY --chown=node:node 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 --chown=node:node redwood.toml .
COPY --chown=node:node graphql.config.js .
COPY --chown=node:node .env.defaults .env.defaults
COPY --chown=node:node --from=web_build /home/node/app/web/dist /home/node/app/web/dist
ENV NODE_ENV=production
ENV API_PROXY_TARGET=http://api:8911
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
#
# USER node
# ```
COPY --chown=node:node api api
COPY --chown=node:node web web
COPY --chown=node:node scripts scripts
RUN yarn redwood prisma generate
these files are all pretty standard. except the last line in the dockerfile to reuse the console target as an init container for db migrations.
I’v been using these files since the experimental days so I’m wondering if I’m missing anything here to make realtime work in docker containers.
Every help appreciated!