From 3611ef0812cbdff789339b6f2e0734b773a14588 Mon Sep 17 00:00:00 2001 From: ziteh Date: Sun, 15 Sep 2024 13:40:54 +0800 Subject: [PATCH] feat: add docker image --- .dockerignore | 13 +++++++++++++ .gitignore | 4 ++++ Dockerfile | 43 ++++++++++++++++++++++++++++--------------- docker-compose.yml | 11 +++++++++++ next.config.mjs | 4 +++- 5 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..189a463 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.pnpm +.next +.git +**/*.db +prisma/migrations/ + +!.next/static +!.next/standalone diff --git a/.gitignore b/.gitignore index 6240fb8..2985f01 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,7 @@ next-env.d.ts /prisma/migrations/ *.db *.db-journal + +# Docker +.docker_temp_* +*.tar diff --git a/Dockerfile b/Dockerfile index 76d50b9..e30df19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,37 @@ -# Use Node.js 20 as the base image -FROM node:20 +FROM node:20-alpine AS base + +# Build stage +FROM base AS build -# Set the working directory inside the container WORKDIR /app -# Copy package.json and pnpm-lock.yaml (or package-lock.json) -COPY package*.json ./ +ENV DATABASE_URL=file:/app/db/hie_sqlite.db -# Install dependencies using pnpm -RUN npm install -g pnpm -RUN pnpm install +COPY package.json pnpm-lock.yaml* ./ +RUN corepack enable pnpm && pnpm install --frozen-lockfile -# Copy the rest of the application code COPY . . +RUN pnpm run prisma:update && pnpm run build -# Expose the port your Next.js app will run on -EXPOSE 3000 +# Remove dev dependencies +RUN pnpm prune --prod + +# Production stage +FROM base + +WORKDIR /app -# Build the Next.js app -RUN pnpm run build +ENV NODE_ENV=production +ENV DATABASE_URL=file:/app/db/hie_sqlite.db + +RUN npm install -g pnpm + +COPY --from=build /app/db/hie_sqlite.db /app/db/hie_sqlite.db +COPY --from=build /app/.next /app/.next +COPY --from=build /app/node_modules /app/node_modules +COPY --from=build /app/package.json /app/package.json +COPY --from=build /app/public /app/public + +EXPOSE 3000 -# Start the app -CMD ["pnpm", "start"] +CMD ["pnpm", "run", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..eaa6cd7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3" +services: + app: + image: hie + build: + context: . + ports: + - "5888:3000" + volumes: + - HOST_DIR:/app/data + # restart: always diff --git a/next.config.mjs b/next.config.mjs index 4678774..8c8bab6 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + output: "standalone", +}; export default nextConfig;