diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..11f6b87 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +Dockerfile +.dockerignore +npm-debug.log +README.md +.next +.git +.github +.husky +.env \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..4b4badd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,16 @@ +name: publish +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + run: | + docker build . --tag ghcr.io/tautf/foinix:latest + docker push ghcr.io/tautf/foinix:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..35b6554 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM node:20-alpine AS base + +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +COPY prisma ./prisma/ +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +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 + +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +RUN yarn global add prisma +RUN prisma generate +RUN yarn build + +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 ./public + +RUN mkdir .next +RUN chown nextjs:nodejs .next + +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 +ENV HOSTNAME "0.0.0.0" + +CMD ["yarn", "start:migrate:prod"] \ No newline at end of file diff --git a/next.config.js b/next.config.js index ca2914e..0d6013a 100644 --- a/next.config.js +++ b/next.config.js @@ -1,5 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + output: 'standalone', experimental: { serverActions: true, }, diff --git a/package.json b/package.json index fa8fd82..b4179ca 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "next build", "start": "next start", "lint": "next lint", - "postinstall": "prisma generate" + "postinstall": "prisma generate", + "start:migrate:prod": "npx prisma migrate deploy && node server.js" }, "dependencies": { "@headlessui/react": "^1.7.17", diff --git a/prisma/migrations/20231129140656_cmdb_link/migration.sql b/prisma/migrations/20231129140656_cmdb_link/migration.sql new file mode 100644 index 0000000..c868594 --- /dev/null +++ b/prisma/migrations/20231129140656_cmdb_link/migration.sql @@ -0,0 +1,11 @@ +-- AlterTable +ALTER TABLE "Product" ADD COLUMN "cmdb_link" TEXT; + +INSERT INTO "ProductType" ("name",description,"createdAt","updatedAt",icon) VALUES + ('Other',NULL,'2023-11-29 15:17:00.000','2023-11-29 15:17:00.000','WrenchIcon'), + ('Computer','A desktop computer','2023-11-29 15:17:00.000','2023-11-29 15:17:00.000','DesktopComputerIcon'), + ('Software','Software','2023-11-29 15:17:00.000','2023-11-29 15:17:00.000','CommandLineIcon'), + ('Server','A server','2023-11-29 15:17:00.000','2023-11-29 15:17:00.000','ServerIcon'), + ('Subscription','A subscription','2023-11-29 15:17:00.000','2023-11-29 15:17:00.000','ArrowPathIcon'), + ('Mobile Device','Mobile device like Laptops','2023-11-29 15:17:00.000','2023-11-29 15:17:00.000','DevicePhoneMobileIcon'), + ('Network Device','Network devices like switches','2023-11-29 15:17:00.000','2023-11-29 15:17:00.000','CpuChipIcon'); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 037eecb..2b13471 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,6 +1,5 @@ datasource db { url = env("DATABASE_URL") - directUrl= env("DATABASE_DIRECT_URL") provider = "postgresql" } diff --git a/src/app/products/components/AddProduct.tsx b/src/app/products/components/AddProduct.tsx index 6dc8706..3942773 100644 --- a/src/app/products/components/AddProduct.tsx +++ b/src/app/products/components/AddProduct.tsx @@ -48,7 +48,7 @@ export default function AddProduct({ productTypes }: Props) { variant="shadow" startContent={} > - {window.innerWidth > 1024 ? 'Add' : ''} + {window?.innerWidth > 1024 ? 'Add' : ''} } > - {window.innerWidth > 1024 ? 'Home' : ''} + {window?.innerWidth > 1024 ? 'Home' : ''} ); diff --git a/src/app/shared/prisma.ts b/src/app/shared/prisma.ts index 4e54f7a..eb961f8 100644 --- a/src/app/shared/prisma.ts +++ b/src/app/shared/prisma.ts @@ -1,5 +1,12 @@ import { PrismaClient } from '@prisma/client'; -const prisma = new PrismaClient(); +const prisma = new PrismaClient({ + datasources: { + db: { + url: process.env.DATABASE_URL, + }, + + }, +}); export default prisma;