-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move prisma to runtime dependencies * Optimize Dockerfile and build script * Fix: remove mention of generated next-env.d.ts in Dockerfile * Add missing reset.d.ts file to Dockerfile * Remove compression steps from Dockerfile and entrypoint script * Add an env file with mocked env vars added for Docker production builds * Use server actions to get runtime env vars * Refactor types and names * Rollback serverActions, use parsed Zod object for runtime env * Reintroduce featureFlags object to avoid passing secret envs to the frontend * Improve string to boolean coercion Co-authored-by: Sebastien Castiel <sebastien@castiel.me> * Run prettier autoformat * Fix type issue, rename function to match behaviour better --------- Co-authored-by: Lauri Vuorela <lauri.vuorela@gmail.com> Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
- Loading branch information
1 parent
50525ad
commit 2af0660
Showing
12 changed files
with
143 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ yarn-error.log* | |
# local env files | ||
.env*.local | ||
*.env | ||
!scripts/build.env | ||
|
||
# vercel | ||
.vercel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,47 @@ | ||
FROM node:21-slim as base | ||
FROM node:21-alpine as base | ||
|
||
EXPOSE 3000/tcp | ||
WORKDIR /usr/app | ||
COPY ./ ./ | ||
COPY ./package.json \ | ||
./package-lock.json \ | ||
./next.config.js \ | ||
./tsconfig.json \ | ||
./reset.d.ts \ | ||
./tailwind.config.js \ | ||
./postcss.config.js ./ | ||
COPY ./scripts ./scripts | ||
COPY ./prisma ./prisma | ||
COPY ./src ./src | ||
|
||
RUN apt update && \ | ||
apt install openssl -y && \ | ||
apt clean && \ | ||
apt autoclean && \ | ||
apt autoremove && \ | ||
RUN apk add --no-cache openssl && \ | ||
npm ci --ignore-scripts && \ | ||
npm install -g prisma && \ | ||
prisma generate | ||
npx prisma generate | ||
|
||
# env vars needed for build not to fail | ||
ARG POSTGRES_PRISMA_URL | ||
ARG POSTGRES_URL_NON_POOLING | ||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
COPY scripts/build.env .env | ||
RUN npm run build | ||
|
||
ENTRYPOINT ["/usr/app/scripts/container-entrypoint.sh"] | ||
RUN rm -r .next/cache | ||
|
||
FROM node:21-alpine as runtime-deps | ||
|
||
WORKDIR /usr/app | ||
COPY --from=base /usr/app/package.json /usr/app/package-lock.json ./ | ||
COPY --from=base /usr/app/prisma ./prisma | ||
|
||
RUN npm ci --omit=dev --omit=optional --ignore-scripts && \ | ||
npx prisma generate | ||
|
||
FROM node:21-alpine as runner | ||
|
||
EXPOSE 3000/tcp | ||
WORKDIR /usr/app | ||
|
||
COPY --from=base /usr/app/package.json /usr/app/package-lock.json ./ | ||
COPY --from=runtime-deps /usr/app/node_modules ./node_modules | ||
COPY ./public ./public | ||
COPY ./scripts ./scripts | ||
COPY --from=base /usr/app/prisma ./prisma | ||
COPY --from=base /usr/app/.next ./.next | ||
|
||
ENTRYPOINT ["/bin/sh", "/usr/app/scripts/container-entrypoint.sh"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# build file that contains all possible env vars with mocked values | ||
# as most of them are used at build time in order to have the production build to work properly | ||
|
||
# db | ||
POSTGRES_PASSWORD=1234 | ||
|
||
# app | ||
POSTGRES_PRISMA_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db | ||
POSTGRES_URL_NON_POOLING=postgresql://postgres:${POSTGRES_PASSWORD}@db | ||
|
||
# app-minio | ||
NEXT_PUBLIC_ENABLE_EXPENSE_DOCUMENTS=false | ||
S3_UPLOAD_KEY=AAAAAAAAAAAAAAAAAAAA | ||
S3_UPLOAD_SECRET=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | ||
S3_UPLOAD_BUCKET=spliit | ||
S3_UPLOAD_REGION=eu-north-1 | ||
S3_UPLOAD_ENDPOINT=s3://minio.example.com | ||
|
||
# app-openai | ||
NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT=false | ||
OPENAI_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
NEXT_PUBLIC_ENABLE_CATEGORY_EXTRACT=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
#!/bin/bash | ||
prisma migrate deploy | ||
|
||
set -euxo pipefail | ||
|
||
npx prisma migrate deploy | ||
npm run start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use server' | ||
|
||
import { env } from './env' | ||
|
||
export async function getRuntimeFeatureFlags() { | ||
return { | ||
enableExpenseDocuments: env.NEXT_PUBLIC_ENABLE_EXPENSE_DOCUMENTS, | ||
enableReceiptExtract: env.NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT, | ||
enableCategoryExtract: env.NEXT_PUBLIC_ENABLE_CATEGORY_EXTRACT, | ||
} | ||
} | ||
|
||
export type RuntimeFeatureFlags = Awaited< | ||
ReturnType<typeof getRuntimeFeatureFlags> | ||
> |