Add base path support for Next.js frontend

Add support for deploying the homepage container at a specified URL path, passed as an environment variable.
This commit is contained in:
Vijay Soni 2024-10-06 23:52:11 +05:30
parent cd8c224ffa
commit 9f57df4992
3 changed files with 6 additions and 1 deletions

View File

@ -23,6 +23,7 @@ WORKDIR /app
ARG BUILDTIME
ARG VERSION
ARG REVISION
ARG NEXT_PUBLIC_BASE_PATH
COPY --link --from=deps /app/node_modules ./node_modules/
COPY . .
@ -30,7 +31,7 @@ COPY . .
SHELL ["/bin/ash", "-xeo", "pipefail", "-c"]
RUN npm run telemetry \
&& mkdir config \
&& NEXT_PUBLIC_BUILDTIME=$BUILDTIME NEXT_PUBLIC_VERSION=$VERSION NEXT_PUBLIC_REVISION=$REVISION npm run build
&& NEXT_PUBLIC_BUILDTIME=$BUILDTIME NEXT_PUBLIC_VERSION=$VERSION NEXT_PUBLIC_REVISION=$REVISION NEXT_PUBLIC_BASE_PATH=$NEXT_PUBLIC_BASE_PATH npm run build
# Production image, copy all the files and run next
FROM docker.io/node:18-alpine AS runner

3
docker-entrypoint.sh Executable file → Normal file
View File

@ -12,6 +12,9 @@ export PGID=${PGID:-0}
export HOMEPAGE_BUILDTIME=$(date +%s)
# Set the base path for the Next.js application
export NEXT_PUBLIC_BASE_PATH=${NEXT_PUBLIC_BASE_PATH:-""}
# Set privileges for /app but only if pid 1 user is root and we are dropping privileges.
# If container is run as an unprivileged user, it means owner already handled ownership setup on their own.
# Running chown in that case (as non-root) will cause error

View File

@ -9,6 +9,7 @@ const nextConfig = {
unoptimized: true,
},
i18n,
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
};
module.exports = nextConfig;