From 2314604d18976093bcce8f9e8b09cc6bb57cf13b Mon Sep 17 00:00:00 2001 From: besscroft Date: Fri, 3 May 2024 11:11:43 +0800 Subject: [PATCH] feat: container support --- .dockerignore | 10 ++ .github/workflows/build-dev.yaml | 36 ++++ .github/workflows/build-release.yaml | 45 +++++ Dockerfile | 53 ++++++ app/api/get-link/route.ts | 4 +- app/api/v1/alist-info/route.ts | 4 +- app/api/v1/get-images-json/route.ts | 4 +- app/api/v1/get-tags/route.ts | 4 +- app/api/v1/r2-info/route.ts | 4 +- app/api/v1/s3-info/route.ts | 4 +- instrumentation.ts | 2 +- next.config.mjs | 1 + package.json | 1 + pnpm-lock.yaml | 237 ++++++++++++++++++++++++++- script.sh | 5 + server/lib/db.ts | 14 +- 16 files changed, 416 insertions(+), 12 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build-dev.yaml create mode 100644 .github/workflows/build-release.yaml create mode 100644 Dockerfile create mode 100644 script.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..539a333 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git +.idea +.github +.gitignore \ No newline at end of file diff --git a/.github/workflows/build-dev.yaml b/.github/workflows/build-dev.yaml new file mode 100644 index 0000000..acdc6a9 --- /dev/null +++ b/.github/workflows/build-dev.yaml @@ -0,0 +1,36 @@ +name: Dev Docker Multi-arch Image CI & CD + +on: + push: + branches: + - dev + +jobs: + build: + name: Running Compile Next Multi-arch Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout PicImpact + uses: actions/checkout@v4 + - name: Get Version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + id: set_up_buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push dev + id: docker_build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/picimpact:dev diff --git a/.github/workflows/build-release.yaml b/.github/workflows/build-release.yaml new file mode 100644 index 0000000..dc1cca5 --- /dev/null +++ b/.github/workflows/build-release.yaml @@ -0,0 +1,45 @@ +name: Dev Docker Multi-arch Image CI & CD + +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Running Compile Next Multi-arch Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout PicImpact + uses: actions/checkout@v4 + - name: Get Version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + id: set_up_buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push latest + id: docker_build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/picimpact:latest + - name: Build and push version + id: docker_build + uses: docker/build-push-action@v5 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/picimpact:${{ steps.get_version.outputs.VERSION }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9c5ade --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +FROM node:18-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat + +WORKDIR /app + +COPY package.json pnpm-lock.yaml* .npmrc ./ + +RUN corepack enable pnpm && pnpm i --frozen-lockfile + +FROM base AS builder + +WORKDIR /app + +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +RUN AUTH_SECRET=pic-impact export NODE_OPTIONS=--openssl-legacy-provider && corepack enable pnpm && pnpm run prisma:generate && pnpm run build + +FROM base AS runner + +WORKDIR /app + +ENV NODE_ENV production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public +COPY ./prisma ./prisma +COPY ./script.sh ./script.sh + +RUN chmod +x script.sh +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +ENV AUTH_TRUST_HOST true + +EXPOSE 3000 + +ENV PORT 3000 + +CMD ./script.sh diff --git a/app/api/get-link/route.ts b/app/api/get-link/route.ts index 627df6f..8c1496f 100644 --- a/app/api/get-link/route.ts +++ b/app/api/get-link/route.ts @@ -4,4 +4,6 @@ import { fetchTagsShow } from '~/server/lib/query' export async function GET() { const data = await fetchTagsShow(); return Response.json(data) -} \ No newline at end of file +} + +export const dynamic = 'force-dynamic' \ No newline at end of file diff --git a/app/api/v1/alist-info/route.ts b/app/api/v1/alist-info/route.ts index d7d3e96..4c8fad8 100644 --- a/app/api/v1/alist-info/route.ts +++ b/app/api/v1/alist-info/route.ts @@ -4,4 +4,6 @@ import { fetchAListInfo } from '~/server/lib/query' export async function GET() { const data = await fetchAListInfo(); return Response.json(data) -} \ No newline at end of file +} + +export const dynamic = 'force-dynamic' \ No newline at end of file diff --git a/app/api/v1/get-images-json/route.ts b/app/api/v1/get-images-json/route.ts index 03e270d..b7435e7 100644 --- a/app/api/v1/get-images-json/route.ts +++ b/app/api/v1/get-images-json/route.ts @@ -4,4 +4,6 @@ import { fetchAllImages } from '~/server/lib/query' export async function GET() { const data = await fetchAllImages(); return Response.json(data) -} \ No newline at end of file +} + +export const dynamic = 'force-dynamic' \ No newline at end of file diff --git a/app/api/v1/get-tags/route.ts b/app/api/v1/get-tags/route.ts index e24886a..218471a 100644 --- a/app/api/v1/get-tags/route.ts +++ b/app/api/v1/get-tags/route.ts @@ -4,4 +4,6 @@ import { fetchTagsList } from '~/server/lib/query' export async function GET() { const data = await fetchTagsList(); return Response.json(data) -} \ No newline at end of file +} + +export const dynamic = 'force-dynamic' \ No newline at end of file diff --git a/app/api/v1/r2-info/route.ts b/app/api/v1/r2-info/route.ts index e6699ff..3ce7c92 100644 --- a/app/api/v1/r2-info/route.ts +++ b/app/api/v1/r2-info/route.ts @@ -4,4 +4,6 @@ import { fetchR2Info } from '~/server/lib/query' export async function GET() { const data = await fetchR2Info(); return Response.json(data) -} \ No newline at end of file +} + +export const dynamic = 'force-dynamic' \ No newline at end of file diff --git a/app/api/v1/s3-info/route.ts b/app/api/v1/s3-info/route.ts index a57c353..5ecf107 100644 --- a/app/api/v1/s3-info/route.ts +++ b/app/api/v1/s3-info/route.ts @@ -4,4 +4,6 @@ import { fetchS3Info } from '~/server/lib/query' export async function GET() { const data = await fetchS3Info(); return Response.json(data) -} \ No newline at end of file +} + +export const dynamic = 'force-dynamic' \ No newline at end of file diff --git a/instrumentation.ts b/instrumentation.ts index e73f451..5382a54 100644 --- a/instrumentation.ts +++ b/instrumentation.ts @@ -29,7 +29,7 @@ export async function register() { skipDuplicates: true, }) }) - console.log('数据库初始化完毕!') + console.log('初始化完毕!') await prisma.$disconnect() } else { console.error('数据库初始化失败,请检查您的连接信息!') diff --git a/next.config.mjs b/next.config.mjs index 84a503c..7557269 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,5 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + output: "standalone", experimental: { serverComponentsExternalPackages: ['pg'], instrumentationHook: true, diff --git a/package.json b/package.json index 8d9f1b3..8ef5f9e 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "react-dom": "^18.2.0", "react-photo-album": "^2.3.1", "server-only": "^0.0.1", + "sharp": "^0.33.3", "sonner": "^1.4.41", "swr": "^2.2.5", "tailwind-merge": "^2.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f2c7e65..d4d6941 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -86,6 +86,9 @@ dependencies: server-only: specifier: ^0.0.1 version: 0.0.1 + sharp: + specifier: ^0.33.3 + version: 0.33.3 sonner: specifier: ^1.4.41 version: 1.4.41(react-dom@18.2.0)(react@18.2.0) @@ -940,6 +943,14 @@ packages: engines: {node: '>=10'} dev: false + /@emnapi/runtime@1.1.1: + resolution: {integrity: sha512-3bfqkzuR1KLx57nZfjr2NLnFOobvyS0aTszaEGCGqmYMVDRaGvgIZbjGSV/MHSSmLgQ/b9JFHQ5xm5WRZYd+XQ==} + requiresBuild: true + dependencies: + tslib: 2.6.2 + dev: false + optional: true + /@emotion/hash@0.8.0: resolution: {integrity: sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==} dev: false @@ -1067,6 +1078,194 @@ packages: resolution: {integrity: sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw==} dev: true + /@img/sharp-darwin-arm64@0.33.3: + resolution: {integrity: sha512-FaNiGX1MrOuJ3hxuNzWgsT/mg5OHG/Izh59WW2mk1UwYHUwtfbhk5QNKYZgxf0pLOhx9ctGiGa2OykD71vOnSw==} + engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-darwin-arm64': 1.0.2 + dev: false + optional: true + + /@img/sharp-darwin-x64@0.33.3: + resolution: {integrity: sha512-2QeSl7QDK9ru//YBT4sQkoq7L0EAJZA3rtV+v9p8xTKl4U1bUqTIaCnoC7Ctx2kCjQgwFXDasOtPTCT8eCTXvw==} + engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [x64] + os: [darwin] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-darwin-x64': 1.0.2 + dev: false + optional: true + + /@img/sharp-libvips-darwin-arm64@1.0.2: + resolution: {integrity: sha512-tcK/41Rq8IKlSaKRCCAuuY3lDJjQnYIW1UXU1kxcEKrfL8WR7N6+rzNoOxoQRJWTAECuKwgAHnPvqXGN8XfkHA==} + engines: {macos: '>=11', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-libvips-darwin-x64@1.0.2: + resolution: {integrity: sha512-Ofw+7oaWa0HiiMiKWqqaZbaYV3/UGL2wAPeLuJTx+9cXpCRdvQhCLG0IH8YGwM0yGWGLpsF4Su9vM1o6aer+Fw==} + engines: {macos: '>=10.13', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-libvips-linux-arm64@1.0.2: + resolution: {integrity: sha512-x7kCt3N00ofFmmkkdshwj3vGPCnmiDh7Gwnd4nUwZln2YjqPxV1NlTyZOvoDWdKQVDL911487HOueBvrpflagw==} + engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-libvips-linux-arm@1.0.2: + resolution: {integrity: sha512-iLWCvrKgeFoglQxdEwzu1eQV04o8YeYGFXtfWU26Zr2wWT3q3MTzC+QTCO3ZQfWd3doKHT4Pm2kRmLbupT+sZw==} + engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-libvips-linux-s390x@1.0.2: + resolution: {integrity: sha512-cmhQ1J4qVhfmS6szYW7RT+gLJq9dH2i4maq+qyXayUSn9/3iY2ZeWpbAgSpSVbV2E1JUL2Gg7pwnYQ1h8rQIog==} + engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-libvips-linux-x64@1.0.2: + resolution: {integrity: sha512-E441q4Qdb+7yuyiADVi5J+44x8ctlrqn8XgkDTwr4qPJzWkaHwD489iZ4nGDgcuya4iMN3ULV6NwbhRZJ9Z7SQ==} + engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-libvips-linuxmusl-arm64@1.0.2: + resolution: {integrity: sha512-3CAkndNpYUrlDqkCM5qhksfE+qSIREVpyoeHIU6jd48SJZViAmznoQQLAv4hVXF7xyUB9zf+G++e2v1ABjCbEQ==} + engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-libvips-linuxmusl-x64@1.0.2: + resolution: {integrity: sha512-VI94Q6khIHqHWNOh6LLdm9s2Ry4zdjWJwH56WoiJU7NTeDwyApdZZ8c+SADC8OH98KWNQXnE01UdJ9CSfZvwZw==} + engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-linux-arm64@0.33.3: + resolution: {integrity: sha512-Zf+sF1jHZJKA6Gor9hoYG2ljr4wo9cY4twaxgFDvlG0Xz9V7sinsPp8pFd1XtlhTzYo0IhDbl3rK7P6MzHpnYA==} + engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm64] + os: [linux] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-linux-arm64': 1.0.2 + dev: false + optional: true + + /@img/sharp-linux-arm@0.33.3: + resolution: {integrity: sha512-Q7Ee3fFSC9P7vUSqVEF0zccJsZ8GiiCJYGWDdhEjdlOeS9/jdkyJ6sUSPj+bL8VuOYFSbofrW0t/86ceVhx32w==} + engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm] + os: [linux] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-linux-arm': 1.0.2 + dev: false + optional: true + + /@img/sharp-linux-s390x@0.33.3: + resolution: {integrity: sha512-vFk441DKRFepjhTEH20oBlFrHcLjPfI8B0pMIxGm3+yilKyYeHEVvrZhYFdqIseSclIqbQ3SnZMwEMWonY5XFA==} + engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [s390x] + os: [linux] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-linux-s390x': 1.0.2 + dev: false + optional: true + + /@img/sharp-linux-x64@0.33.3: + resolution: {integrity: sha512-Q4I++herIJxJi+qmbySd072oDPRkCg/SClLEIDh5IL9h1zjhqjv82H0Seupd+q2m0yOfD+/fJnjSoDFtKiHu2g==} + engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [x64] + os: [linux] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-linux-x64': 1.0.2 + dev: false + optional: true + + /@img/sharp-linuxmusl-arm64@0.33.3: + resolution: {integrity: sha512-qnDccehRDXadhM9PM5hLvcPRYqyFCBN31kq+ErBSZtZlsAc1U4Z85xf/RXv1qolkdu+ibw64fUDaRdktxTNP9A==} + engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [arm64] + os: [linux] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-linuxmusl-arm64': 1.0.2 + dev: false + optional: true + + /@img/sharp-linuxmusl-x64@0.33.3: + resolution: {integrity: sha512-Jhchim8kHWIU/GZ+9poHMWRcefeaxFIs9EBqf9KtcC14Ojk6qua7ghKiPs0sbeLbLj/2IGBtDcxHyjCdYWkk2w==} + engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [x64] + os: [linux] + requiresBuild: true + optionalDependencies: + '@img/sharp-libvips-linuxmusl-x64': 1.0.2 + dev: false + optional: true + + /@img/sharp-wasm32@0.33.3: + resolution: {integrity: sha512-68zivsdJ0koE96stdUfM+gmyaK/NcoSZK5dV5CAjES0FUXS9lchYt8LAB5rTbM7nlWtxaU/2GON0HVN6/ZYJAQ==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [wasm32] + requiresBuild: true + dependencies: + '@emnapi/runtime': 1.1.1 + dev: false + optional: true + + /@img/sharp-win32-ia32@0.33.3: + resolution: {integrity: sha512-CyimAduT2whQD8ER4Ux7exKrtfoaUiVr7HG0zZvO0XTFn2idUWljjxv58GxNTkFb8/J9Ub9AqITGkJD6ZginxQ==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@img/sharp-win32-x64@0.33.3: + resolution: {integrity: sha512-viT4fUIDKnli3IfOephGnolMzhz5VaTvDRkYqtZxOMIoMQ4MrAziO7pT1nVnOt2FAm7qW5aa+CCc13aEY6Le0g==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + /@internationalized/date@3.5.2: resolution: {integrity: sha512-vo1yOMUt2hzp63IutEaTUxROdvQg1qlMRsbCvbay2AK2Gai7wIgCyK5weEX3nHkiLgo4qCXHijFNC/ILhlRpOQ==} dependencies: @@ -5277,6 +5476,11 @@ packages: engines: {node: '>=6'} dev: true + /detect-libc@2.0.3: + resolution: {integrity: sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==} + engines: {node: '>=8'} + dev: false + /detect-node-es@1.1.0: resolution: {integrity: sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ==} dev: false @@ -6418,7 +6622,6 @@ packages: engines: {node: '>=10'} dependencies: yallist: 4.0.0 - dev: true /lucide-react@0.367.0(react@18.2.0): resolution: {integrity: sha512-3FWiBaJiqMrx5a1sjH3CVdPqWnw/Z/PTVeeTDmOeILSs+8Ah+VhCd4FQMeHo6Z0WxHcm9piIOtilQwvceiCCKQ==} @@ -7720,7 +7923,6 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 - dev: true /server-only@0.0.1: resolution: {integrity: sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==} @@ -7748,6 +7950,36 @@ packages: has-property-descriptors: 1.0.2 dev: true + /sharp@0.33.3: + resolution: {integrity: sha512-vHUeXJU1UvlO/BNwTpT0x/r53WkLUVxrmb5JTgW92fdFCFk0ispLMAeu/jPO2vjkXM1fYUi3K7/qcLF47pwM1A==} + engines: {libvips: '>=8.15.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0} + requiresBuild: true + dependencies: + color: 4.2.3 + detect-libc: 2.0.3 + semver: 7.6.0 + optionalDependencies: + '@img/sharp-darwin-arm64': 0.33.3 + '@img/sharp-darwin-x64': 0.33.3 + '@img/sharp-libvips-darwin-arm64': 1.0.2 + '@img/sharp-libvips-darwin-x64': 1.0.2 + '@img/sharp-libvips-linux-arm': 1.0.2 + '@img/sharp-libvips-linux-arm64': 1.0.2 + '@img/sharp-libvips-linux-s390x': 1.0.2 + '@img/sharp-libvips-linux-x64': 1.0.2 + '@img/sharp-libvips-linuxmusl-arm64': 1.0.2 + '@img/sharp-libvips-linuxmusl-x64': 1.0.2 + '@img/sharp-linux-arm': 0.33.3 + '@img/sharp-linux-arm64': 0.33.3 + '@img/sharp-linux-s390x': 0.33.3 + '@img/sharp-linux-x64': 0.33.3 + '@img/sharp-linuxmusl-arm64': 0.33.3 + '@img/sharp-linuxmusl-x64': 0.33.3 + '@img/sharp-wasm32': 0.33.3 + '@img/sharp-win32-ia32': 0.33.3 + '@img/sharp-win32-x64': 0.33.3 + dev: false + /shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} @@ -8360,7 +8592,6 @@ packages: /yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - dev: true /yaml@2.4.1: resolution: {integrity: sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg==} diff --git a/script.sh b/script.sh new file mode 100644 index 0000000..4ef7bd8 --- /dev/null +++ b/script.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +npx prisma migrate deploy + +HOSTNAME="0.0.0.0" node server.js diff --git a/server/lib/db.ts b/server/lib/db.ts index 5e4d599..f7b495a 100644 --- a/server/lib/db.ts +++ b/server/lib/db.ts @@ -1,5 +1,15 @@ import { PrismaClient } from '@prisma/client' -const prisma = new PrismaClient() +const prismaClientSingleton = () => { + return new PrismaClient() +} -export const db = prisma \ No newline at end of file +declare const globalThis: { + prisma: ReturnType; +} & typeof global; + +const prisma = globalThis.prisma ?? prismaClientSingleton() + +export const db = prisma + +globalThis.prisma = prisma \ No newline at end of file