diff --git a/.dockerignore b/.dockerignore index 0501d09..883b43c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,12 @@ -fly.toml +.git +.github +.next +node_modules +npm-debug.log* +bun-debug.log* +.env +.env.* +!.env.example +Dockerfile +README.md +tsconfig.tsbuildinfo diff --git a/Dockerfile b/Dockerfile index 46a5e4c..ba80422 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,58 @@ -FROM pierrezemb/gostatic -COPY . /srv/http/ -CMD ["-port","8080","-https-promote", "-enable-logging"] +# syntax = docker/dockerfile:1 + +# Adjust BUN_VERSION as desired +ARG BUN_VERSION=1.3.14 +FROM oven/bun:${BUN_VERSION}-slim AS base + +LABEL fly_launch_runtime="Next.js" + +# Next.js app lives here +WORKDIR /app + +ENV NEXT_TELEMETRY_DISABLED="1" + + +# Throw-away build stage to reduce size of final image +FROM base AS build + +# Install packages needed to build node modules +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential ca-certificates node-gyp pkg-config python-is-python3 && \ + rm -rf /var/lib/apt/lists/* + +# Install node modules +COPY package.json bun.lock prisma.config.ts ./ +COPY prisma ./prisma +RUN bun install --frozen-lockfile + +# Copy application code +COPY . . + +# Public admin configuration must be present at build time because Next.js +# inlines NEXT_PUBLIC_* values into the client bundle during next build. +ARG NEXT_PUBLIC_ADMIN_ADDRESS +ARG NEXT_PUBLIC_ADMIN_ADDRESSES +ENV NEXT_PUBLIC_ADMIN_ADDRESS="${NEXT_PUBLIC_ADMIN_ADDRESS}" +ENV NEXT_PUBLIC_ADMIN_ADDRESSES="${NEXT_PUBLIC_ADMIN_ADDRESSES}" + +# Build application (runs prisma generate + prisma:sync + next build via package.json) +RUN bun run build + +# Remove development dependencies +RUN bun install --frozen-lockfile --production + + +# Final stage for app image +FROM base + +ENV NODE_ENV="production" + +# Copy built application +COPY --from=build /app /app + +ENV HOSTNAME="0.0.0.0" +ENV PORT="3000" + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3000 +CMD ["bun", "run", "start"] diff --git a/fly.toml b/fly.toml index d4d671e..f89c87e 100644 --- a/fly.toml +++ b/fly.toml @@ -9,7 +9,7 @@ primary_region = 'syd' [build] [http_service] - internal_port = 8080 + internal_port = 3000 force_https = true auto_stop_machines = 'stop' auto_start_machines = true diff --git a/next-env.d.ts b/next-env.d.ts index c4b7818..9edff1c 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,6 +1,6 @@ /// /// -import "./.next/dev/types/routes.d.ts"; +import "./.next/types/routes.d.ts"; // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/package.json b/package.json index 55cb6c4..2e015bf 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "next dev", - "build": "prisma generate && npm run prisma:sync && next build", + "build": "prisma generate && node scripts/prisma-sync.mjs && next build", "prisma:sync": "node scripts/prisma-sync.mjs", "postinstall": "prisma generate", "lint": "eslint .",