-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix production build broken by missing env DATABASE_URL at build time #41
Fix production build broken by missing env DATABASE_URL at build time #41
Conversation
node_modules | ||
npm-debug.log | ||
.pnpm-store | ||
out | ||
dist | ||
*.md | ||
.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were inserting a lot of shit in the image.
@@ -17,38 +18,37 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install \ | |||
--frozen-lockfile \ | |||
--filter "@latitude-data/web..." | |||
|
|||
# PRODUCTION stage | |||
# ------------------------------------------------------ | |||
FROM installer AS builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builder and installer can be merged I think.
f0552b4
to
ecfce74
Compare
dockerfile: apps/web/docker/Dockerfile | ||
# This enables to have this service for testing production build | ||
# It will not run when doing docker compose up | ||
profiles: [building] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docker compose allow to have profiles. So no profile runs when docker compose up
which is perfect for this case. I only want for the combinience of developing Dockerfile production and run docker compose build web
@@ -24,6 +24,7 @@ | |||
}, | |||
"dependencies": { | |||
"@latitude-data/env": "workspace:^", | |||
"@t3-oss/env-core": "^0.10.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the perfect excuse for this sorry. Explained in the next comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz... if (process.env.BUILDING_CONTAINER == 'true') return
let's not fight more over this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you don't want a tool built for this propose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like it for NextJS for the client-side safety measures that you mention ☝🏼 . I hate that we use it in api because it brings 0 value there, and adding a dependency is just overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this package is type save. When you do env.SOMETHING
you're sure that's a number, string, enum,... Doing the old way you still use untyped process.env
|
||
import '@latitude-data/env' | ||
|
||
const envvars = z.object({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this breaks production build because it tries to find DATABASE_URL
at build time. With t3-env this is easy fixable by using skipValidation
with BUILDING_CONTAINER
flag as we did in web.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? I don't get it why is this code evaluated at build time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's imported by nextjs bundler. And because is imported zod parse
function is run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next bundler runs the code of its dependencies at compile time? :drunk:
c8999f0
to
d04f5c4
Compare
apps/api/tsconfig.json
Outdated
@@ -1,6 +1,7 @@ | |||
{ | |||
"extends": "@latitude-data/typescript-config/base.json", | |||
"compilerOptions": { | |||
"moduleResolution": "Bundler", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'bundler' for use with bundlers. Like node16 and nodenext, this mode supports package.json "imports" and "exports", but unlike the Node.js resolution modes, bundler never requires file extensions on relative paths in imports.
I think Bundler
is ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did u need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For t3-env/core
. It use a module system that requires the more modern version. But the thing is we're already using Bundler
in NextJS app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An I think bundler
makes a lot of sense for us because we're using one only final bundler in nextjs or api and not having by package bundlers
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ | ||
BUILDING_CONTAINER=true \ | ||
pnpm turbo build --filter='@latitude-data/web...' | ||
|
||
FROM base AS runner | ||
FROM base as prod-deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is worth it to have a stage only to install production deps. That then are copied in production
stage
We moved DB initialization to core: #34 This breaks production build because at build time DATABASE_URL is not and should never be defined
d04f5c4
to
5dce8ba
Compare
What?
We moved DB initialization to core: #34 This breaks production build because at build time DATABASE_URL is not and should never be defined
TODO