From dc08cd05f971fdcdd71729f5a1b9be91d7999205 Mon Sep 17 00:00:00 2001 From: Aidan Date: Thu, 8 May 2025 23:35:20 -0400 Subject: [PATCH] docker: dockerize, make standalone, will move todos to issues --- Dockerfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 5 ----- docker-compose.yml | 7 +++++++ next.config.ts | 1 + 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7424433 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM node:latest AS base + +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ +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 + +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +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 + +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./build/public + +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./build/ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./build/.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 + +ENV HOSTNAME="0.0.0.0" +CMD ["node", "build/server.js"] \ No newline at end of file diff --git a/README.md b/README.md index dbecb08..1b305fb 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,3 @@ Please use common sense when contributing :) This project does not use a custom user agent when interacting with the MusicBrainz API. This is because the LastPlayed component is rendered client-side and user agent support is not universal. If bugs were to occur with my code, I believe it would be easier for MusicBrainz to block this way. - -## To-Do - -- [ ] Dockerize for easier deployment -- [ ] Use MusicBrainz recording collections for displaying data about music diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9354d61 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + aidxncc: + build: . + ports: + - 3000:3000 + environment: + - NODE_ENV=production \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index 13b5dee..ec75bba 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { + output: 'standalone', images: { remotePatterns: [ {