fix: serverless and google cloud storage
This commit is contained in:
parent
cc542b005a
commit
1def791cfb
9 changed files with 1457 additions and 2072 deletions
|
|
@ -1,2 +1,3 @@
|
||||||
DATABASE_URI=mongodb://127.0.0.1/dreikoenige
|
DATABASE_URI=mongodb://127.0.0.1/dreikoenige
|
||||||
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
||||||
|
GOOGLE_BUCKET=google_storage_bucket
|
||||||
61
Dockerfile
61
Dockerfile
|
|
@ -1,8 +1,61 @@
|
||||||
FROM node:21-alpine
|
# From https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
|
||||||
|
|
||||||
|
FROM node:18-alpine AS base
|
||||||
|
RUN corepack enable;
|
||||||
|
|
||||||
|
# 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
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install dependencies based on the preferred package manager
|
||||||
|
COPY package.json yarn.lock* .yarnrc.yml package-lock.json* pnpm-lock.yaml* ./
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||||
|
elif [ -f package-lock.json ]; then npm ci; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM base AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN yarn set version stable
|
|
||||||
RUN yarn install --frozen-lockfile
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||||
|
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn run build; \
|
||||||
|
elif [ -f package-lock.json ]; then npm run build; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||||
|
else echo "Lockfile not found." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. Production image, copy all the files and run next
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
RUN addgroup -g 1001 -S nodejs
|
||||||
|
RUN adduser -S nextjs -u 1001
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD yarn dev
|
|
||||||
|
ENV PORT=3000
|
||||||
|
|
||||||
|
CMD HOSTNAME="0.0.0.0" node server.js
|
||||||
|
|
@ -24,6 +24,14 @@ To Run the image as a Container
|
||||||
docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:latest
|
docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Postgres Database
|
||||||
|
|
||||||
|
You will need the an Postgres database including the postgis extension
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker pull postgis/postgis
|
||||||
|
```
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
||||||
Please set the environment variables in the `.env` file
|
Please set the environment variables in the `.env` file
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,21 @@ import { withPayload } from '@payloadcms/next/withPayload'
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
// Your Next.js config here
|
// Your Next.js config here
|
||||||
|
output: 'standalone',
|
||||||
eslint: {
|
eslint: {
|
||||||
// Warning: This allows production builds to successfully complete even if
|
// Warning: This allows production builds to successfully complete even if
|
||||||
// your project has ESLint errors.
|
// your project has ESLint errors.
|
||||||
ignoreDuringBuilds: true,
|
ignoreDuringBuilds: true,
|
||||||
},
|
},
|
||||||
|
images: {
|
||||||
|
remotePatterns: [
|
||||||
|
{
|
||||||
|
protocol: 'https',
|
||||||
|
hostname: 'storage.googleapis.com',
|
||||||
|
pathname: '/dreikoenige/**',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig)
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@
|
||||||
"chromatic": "npx chromatic --project-token=chpt_70d6a2e05af185a"
|
"chromatic": "npx chromatic --project-token=chpt_70d6a2e05af185a"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@payloadcms/db-mongodb": "^3.3.0",
|
"@payloadcms/db-postgres": "^3.3.0",
|
||||||
"@payloadcms/next": "^3.3.0",
|
"@payloadcms/next": "^3.3.0",
|
||||||
"@payloadcms/payload-cloud": "^3.3.0",
|
|
||||||
"@payloadcms/richtext-lexical": "^3.3.0",
|
"@payloadcms/richtext-lexical": "^3.3.0",
|
||||||
|
"@payloadcms/storage-gcs": "^3.3.0",
|
||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"graphql": "^16.8.1",
|
"graphql": "^16.8.1",
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,13 @@ export const Media: CollectionConfig = {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'search',
|
||||||
|
type: 'text',
|
||||||
|
label: {
|
||||||
|
de: "Suchbegriffe"
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
upload: {
|
upload: {
|
||||||
imageSizes: [
|
imageSizes: [
|
||||||
|
|
@ -39,7 +46,6 @@ export const Media: CollectionConfig = {
|
||||||
position: 'centre',
|
position: 'centre',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
adminThumbnail: 'thumbnail',
|
|
||||||
mimeTypes: ['image/*'],
|
mimeTypes: ['image/*'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,8 @@ export interface Employee {
|
||||||
export interface Media {
|
export interface Media {
|
||||||
id: string;
|
id: string;
|
||||||
alt: string;
|
alt: string;
|
||||||
|
search?: string | null;
|
||||||
|
prefix?: string | null;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
url?: string | null;
|
url?: string | null;
|
||||||
|
|
@ -229,6 +231,7 @@ export interface Announcement {
|
||||||
export interface Document {
|
export interface Document {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
prefix?: string | null;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
url?: string | null;
|
url?: string | null;
|
||||||
|
|
@ -966,6 +969,7 @@ export interface UsersSelect<T extends boolean = true> {
|
||||||
*/
|
*/
|
||||||
export interface DocumentsSelect<T extends boolean = true> {
|
export interface DocumentsSelect<T extends boolean = true> {
|
||||||
name?: T;
|
name?: T;
|
||||||
|
prefix?: T;
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
url?: T;
|
url?: T;
|
||||||
|
|
@ -984,6 +988,8 @@ export interface DocumentsSelect<T extends boolean = true> {
|
||||||
*/
|
*/
|
||||||
export interface MediaSelect<T extends boolean = true> {
|
export interface MediaSelect<T extends boolean = true> {
|
||||||
alt?: T;
|
alt?: T;
|
||||||
|
search?: T;
|
||||||
|
prefix?: T;
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
url?: T;
|
url?: T;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
// storage-adapter-import-placeholder
|
// storage-adapter-import-placeholder
|
||||||
import { mongooseAdapter } from '@payloadcms/db-mongodb'
|
|
||||||
import {
|
import {
|
||||||
lexicalEditor,
|
lexicalEditor,
|
||||||
BoldFeature,
|
BoldFeature,
|
||||||
|
|
@ -35,7 +34,8 @@ import { Pages } from '@/collections/Pages'
|
||||||
import { Documents } from '@/collections/Documents'
|
import { Documents } from '@/collections/Documents'
|
||||||
import { Locations } from '@/collections/Locations'
|
import { Locations } from '@/collections/Locations'
|
||||||
import { ContactPerson } from '@/collections/ContactPerson'
|
import { ContactPerson } from '@/collections/ContactPerson'
|
||||||
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'
|
import { postgresAdapter } from '@payloadcms/db-postgres'
|
||||||
|
import { gcsStorage } from '@payloadcms/storage-gcs'
|
||||||
|
|
||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(filename)
|
const dirname = path.dirname(filename)
|
||||||
|
|
@ -85,12 +85,31 @@ export default buildConfig({
|
||||||
i18n: {
|
i18n: {
|
||||||
supportedLanguages: { de },
|
supportedLanguages: { de },
|
||||||
},
|
},
|
||||||
db: mongooseAdapter({
|
db: postgresAdapter({
|
||||||
url: process.env.DATABASE_URI || '',
|
idType: "uuid",
|
||||||
|
pool: {
|
||||||
|
connectionString: process.env.DATABASE_URI,
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
sharp,
|
sharp,
|
||||||
plugins: [
|
plugins: [
|
||||||
// storage-adapter-placeholder
|
gcsStorage({
|
||||||
payloadCloudPlugin()
|
|
||||||
|
collections: {
|
||||||
|
media: {
|
||||||
|
disablePayloadAccessControl: true,
|
||||||
|
prefix: 'media/',
|
||||||
|
generateFileURL: args => `https://storage.googleapis.com/${process.env.GOOGLE_BUCKET}/media/${args.filename}`
|
||||||
|
},
|
||||||
|
documents: {
|
||||||
|
disablePayloadAccessControl: true,
|
||||||
|
prefix: 'documents/',
|
||||||
|
generateFileURL: args => `https://storage.googleapis.com/${process.env.GOOGLE_BUCKET}/documents/${args.filename}`
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bucket: process.env.GOOGLE_BUCKET || "",
|
||||||
|
options: {},
|
||||||
|
acl: undefined
|
||||||
|
})
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue