I have the fly.toml here just trying to use sqllite to get this live:
app = 'may-rsc-app'
primary_region = 'lax'
[build]
build-target = "api_fe_serve"
[deploy]
release_command = '.fly/release.sh'
[env]
DATABASE_URL = 'file://data/sqlite.db'
MIGRATE_ON_BOOT = 'true'
PORT = '8910'
REDWOOD_DISABLE_TELEMETRY = '1'
[[mounts]]
source = 'data'
destination = '/data'
[http_service]
internal_port = 8910
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
the Dockerfile here I am definitely not too sure on:
ARG BASE_IMAGE=node:20-bookworm-slim
FROM ${BASE_IMAGE} as base
RUN mkdir /app
WORKDIR /app
# Required for building the api and web distributions
ENV NODE_ENV production
RUN corepack enable
RUN corepack prepare yarn@4.1.1 --activate
FROM base as dependencies
COPY .yarn .yarn
COPY .yarnrc.yml .yarnrc.yml
COPY package.json package.json
COPY web/package.json web/package.json
COPY api/package.json api/package.json
COPY yarn.lock yarn.lock
RUN --mount=type=cache,target=/root/.yarn/berry/cache \
--mount=type=cache,target=/root/.cache yarn install --immutable
COPY redwood.toml .
COPY graphql.config.js .
# api build
# ------------------------------------------------
FROM dependencies as api_build
COPY api api
RUN yarn rw build api
# web build
# ------------------------------------------------
FROM dependencies as web_build
COPY web web
RUN yarn rw build web
# DB and data migrations
# ------------------------------------------------
# ideal place for `prisma migrate` and `@redwood/data-migrate`
# serve api and fe
# ------------------------------------------------
FROM node:20-bookworm-slim as api_fe_serve
WORKDIR /home/node/app
COPY .yarn/plugins .yarn/plugins
COPY .yarn/releases .yarn/releases
COPY .yarnrc.yml .
COPY api/package.json api/package.json
COPY web/package.json web/package.json
COPY package.json .
COPY yarn.lock .
RUN yarn plugin import workspace-tools
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 web --production
COPY redwood.toml .
COPY graphql.config.js .
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
COPY --from=web_build /home/node/app/web/dist /home/node/app/web/dist
ENV NODE_ENV=production
ENV PRISMA_HIDE_UPDATE_MESSAGE=true
ENV RWJS_EXP_SSR_GRAPHQL_ENDPOINT=http://127.0.0.1:8910/.redwood/functions/graphql
COPY .fly .fly
ENTRYPOINT ["sh"]
CMD [".fly/start.sh"]
Some notes of things I had to edit to get the app to this stage where it is deploying but deploying wrongly:
In the start.sh in the .fly I had to change port to webPort thanks to Jace on this once:
set -ex
if [ -n $MIGRATE_ON_BOOT ]; then
$(dirname $0)/migrate.sh
fi
npx rw-server --webPort ${PORT} $@
in my redwood.toml I had to add a host to make sure host set correctly:
[web]
title = "Redwood App"
host = '0.0.0.0'
port = 8910
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = 8911
host = '0.0.0.0'
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
[experimental.streamingSsr]
enabled = true
[experimental.rsc]
enabled = true
It gave me some error on the FatalErrorPage because it was called DevFatalErrorPage. I had to change it to:
const FatalErrorPage =
DevFatalErrorPage ||
(() => (
<main>
...
</main>
in App.tsx it also was being weird with only building if I used dot notation vs. naming the folder directly:
THIS WORKED~~~~~~
import FatalErrorPage from './pages/FatalErrorPage'
import Routes from './Routes'
THIS GAVE ERRORS~~~~
import FatalErrorPage from 'src/pages/FatalErrorPage'
import Routes from 'src/Routes'
So now I am getting logs on Fly.io that look like it is deploying, but I do not see html coming back just 404 errors:
2024-06-06T05:36:20.015 app[machine] lax [info] 2024/06/06 05:36:20 INFO SSH listening listen_address=[fdaa:5:80e4:a7b:bf88:8fe6:4c17:2]:22 dns_server=[fdaa::3]:53
2024-06-06T05:36:20.020 app[machine] lax [info] + '[' -n true ]
2024-06-06T05:36:20.020 app[machine] lax [info] + dirname .fly/start.sh
2024-06-06T05:36:20.021 app[machine] lax [info] + .fly/migrate.sh
2024-06-06T05:36:20.022 app[machine] lax [info] + npx rw-server --webPort 8910
2024-06-06T05:36:20.029 runner[machine] lax [info] Machine started in 512ms
2024-06-06T05:36:20.031 proxy[machine] lax [info] machine started in 519.994195ms
2024-06-06T05:36:21.699 app[machine] lax [info] Starting API and Web Servers...
2024-06-06T05:36:21.753 app[machine] lax [info] {"level":30,"time":1717652181752,"pid":340,"hostname":"4d89645c6eed08","msg":"Web server listening at http://0.0.0.0:8910"}
2024-06-06T05:36:21.761 app[machine] lax [info] Importing Server Functions...
2024-06-06T05:36:22.412 proxy[machine] lax [info] machine became reachable in 2.380962287s
2024-06-06T05:36:22.577 app[machine] lax [info] /graphql 816 ms
2024-06-06T05:36:22.577 app[machine] lax [info] ...Done importing in 817 ms
2024-06-06T05:36:22.578 app[machine] lax [info] {"level":30,"time":1717652182578,"pid":340,"hostname":"4d89645c6eed08","msg":"API server listening at http://0.0.0.0:8911"}
2024-06-06T05:36:22.579 app[machine] lax [info] Took 880 ms
2024-06-06T05:36:22.579 app[machine] lax [info] Web server listening at http://0.0.0.0:8910
2024-06-06T05:36:22.579 app[machine] lax [info] API server listening at http://0.0.0.0:8911/
2024-06-06T05:36:22.579 app[machine] lax [info] GraphQL endpoint at http://0.0.0.0:8911/graphql
2024-06-06T05:36:22.583 app[machine] lax [info] {"level":30,"time":1717652182583,"pid":340,"hostname":"4d89645c6eed08","reqId":"req-1","req":{"method":"GET","url":"/","hostname":"may-rsc-app.fly.dev","remoteAddress":"xxx","remotePort":35274},"msg":"incoming request"}
2024-06-06T05:36:22.593 app[machine] lax [info] {"level":40,"time":1717652182591,"pid":340,"hostname":"4d89645c6eed08","reqId":"req-1","msg":"Trying to send a NotFound error inside a 404 handler. Sending basic 404 response."}
2024-06-06T05:36:22.595 app[machine] lax [info] {"level":30,"time":1717652182593,"pid":340,"hostname":"4d89645c6eed08","reqId":"req-1","res":{"statusCode":404},"responseTime":10.150360000000092,"msg":"request completed"}
I feeeeeeeeel like this is mostly me not being used to Docker and that I need to do a build step before serving with RSC + SSR and I do not think that is happening correctly or else I should at least get html back over the wire.
If you have any suggestions give me a holler. Otherwise I think I am deep diving Docker this weekend haha.