From 402362e8e33b5fab6c9bef25b8b68dad3b2dfe3d Mon Sep 17 00:00:00 2001 From: Dudi Zimberknopf Date: Sun, 4 Feb 2024 18:22:23 +0200 Subject: [PATCH 1/3] add dockerfile --- Dockerfile | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ next.config.js | 1 + 2 files changed, 70 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12a0971 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +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 + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* 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 . . + +# 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 + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production +# Uncomment the following line in case you want to disable telemetry during runtime. +# ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Set the correct permission for prerender cache +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 + +EXPOSE 3000 + +ENV PORT 3000 +# set hostname to localhost +ENV HOSTNAME "0.0.0.0" + +# server.js is created by next build from the standalone output +# https://nextjs.org/docs/pages/api-reference/next-config-js/output +CMD ["node", "server.js"] \ No newline at end of file diff --git a/next.config.js b/next.config.js index 518ea81..e216f17 100644 --- a/next.config.js +++ b/next.config.js @@ -1,5 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + output: 'standalone', reactStrictMode: true, images: { unoptimized: true From 2d16f931962355dec7b99212094c91c05e081b75 Mon Sep 17 00:00:00 2001 From: Dudi Zimberknopf Date: Mon, 5 Feb 2024 09:52:57 +0200 Subject: [PATCH 2/3] add env vars fix typos --- .github/workflows/nextjs.yml | 2 +- Dockerfile | 8 +++++++- README.md | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index 87cea12..e86401d 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -2,7 +2,7 @@ name: Build on: push: - branches: ["main", "stagging"] + branches: ["main", "staging"] pull_request: diff --git a/Dockerfile b/Dockerfile index 12a0971..f0cd422 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,9 +61,15 @@ USER nextjs EXPOSE 3000 ENV PORT 3000 -# set hostname to localhost + ENV HOSTNAME "0.0.0.0" +ENV NEXTAUTH_URL "http://localhost:3000" + +ENV NEXTAUTH_SECRET "secret" + +ENV NEXT_PUBLIC_GOOGLE_ANALYTICS "UA-XXXXXXXXX-X" + # server.js is created by next build from the standalone output # https://nextjs.org/docs/pages/api-reference/next-config-js/output CMD ["node", "server.js"] \ No newline at end of file diff --git a/README.md b/README.md index d83127e..5308cf6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -FalkorDB-Browser is a vizualization UI for FalkorDB. +FalkorDB-Browser is a visualization UI for FalkorDB. To see a running demo check: https://browser.falkordb.com/ From f4035dfb91f77c589dce91da053fa3f6f902de11 Mon Sep 17 00:00:00 2001 From: Dudi Zimberknopf Date: Mon, 5 Feb 2024 10:53:34 +0200 Subject: [PATCH 3/3] - fix env var template char - add .loca.env.template to docker image --- .env.local.template | 4 ++-- Dockerfile | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.env.local.template b/.env.local.template index b418efe..f362ab7 100644 --- a/.env.local.template +++ b/.env.local.template @@ -1,4 +1,4 @@ # Next secrets NEXTAUTH_URL=http://localhost:3000/ -NEXTAUTH_SECRET=[SECRET] -NEXT_PUBLIC_GOOGLE_ANALYTICS=[ANALYTICS] +NEXTAUTH_SECRET=SECRET +NEXT_PUBLIC_GOOGLE_ANALYTICS=ANALYTICS diff --git a/Dockerfile b/Dockerfile index f0cd422..db11d29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,6 +55,8 @@ RUN chown nextjs:nodejs .next # 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 +COPY --from=builder --chown=nextjs:nodejs /app/.env.local.template ./.env.local + USER nextjs @@ -64,12 +66,6 @@ ENV PORT 3000 ENV HOSTNAME "0.0.0.0" -ENV NEXTAUTH_URL "http://localhost:3000" - -ENV NEXTAUTH_SECRET "secret" - -ENV NEXT_PUBLIC_GOOGLE_ANALYTICS "UA-XXXXXXXXX-X" - # server.js is created by next build from the standalone output # https://nextjs.org/docs/pages/api-reference/next-config-js/output CMD ["node", "server.js"] \ No newline at end of file