diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8a18a69 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,40 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# database +/prisma/db.sqlite +/prisma/db.sqlite-journal + +# next.js +/.next/ +/out/ +next-env.d.ts + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ee6d780 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,68 @@ +FROM node:18.19-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* ./ +COPY prisma/ ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add 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 yarn build + +# If using npm comment out above and use below instead +# RUN npm run build + +# 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/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1e48cd8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,46 @@ +# docker-compose.dev.yml +version: '3' + +services: + web: + container_name: web + build: + context: . + dockerfile: ./Dockerfile + volumes: + - .:/app/web + environment: + POSTGRES_ADDR: postgres + POSTGRES_DATABASE: savage_tracking + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + DATABASE_URL: postgresql://postgres:postgres@postgres:5432/savage_tracking?schema=public + JWT_SECRET: secret + TZ: Asia/Taipei + RFID_PKEY: secret + depends_on: + postgres: + condition: service_healthy + restart: always + ports: + - 3000:3000 + postgres: + image: postgres:16-alpine + restart: always + environment: + POSTGRES_DB: savage_tracking + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + volumes: + - pgdata:/var/lib/postgresql/data + healthcheck: + test: + ["CMD", "pg_isready", "-U", "postgres", "-d", "savage_tracking"] + interval: 5s + timeout: 10s + retries: 5 + ports: + - 3001:5432 + +volumes: + pgdata: {} diff --git a/next.config.js b/next.config.js index ffbeb9f..c824120 100644 --- a/next.config.js +++ b/next.config.js @@ -17,6 +17,11 @@ const config = { locales: ["en"], defaultLocale: "en", }, + + eslint: { + ignoreDuringBuilds: true, + }, + output: 'standalone', // for docker }; export default config; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9351e95..e8d9ca0 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -3,10 +3,11 @@ generator client { provider = "prisma-client-js" + binaryTargets = ["native", "linux-musl-openssl-3.0.x"] } datasource db { - provider = "sqlite" + provider = "postgresql" url = env("DATABASE_URL") } diff --git a/src/components/admin/Periods.tsx b/src/components/admin/Periods.tsx index fc1e0a1..ca74853 100644 --- a/src/components/admin/Periods.tsx +++ b/src/components/admin/Periods.tsx @@ -43,7 +43,7 @@ export default function Periods() {
{ - Object.keys(periods.data || {}).map((date) => { + Object.keys(periods.data ?? {}).map((date) => { periodCnt = 0; return (