Skip to content

Commit

Permalink
Merge pull request #4 from tautf/docker-compatibility
Browse files Browse the repository at this point in the history
Docker compatibility
  • Loading branch information
tautf authored Nov 29, 2023
2 parents af2bf60 + 07dcfc2 commit 9e17961
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Dockerfile
.dockerignore
npm-debug.log
README.md
.next
.git
.github
.husky
.env
16 changes: 16 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
experimental: {
serverActions: true,
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions prisma/migrations/20231129140656_cmdb_link/migration.sql
Original file line number Diff line number Diff line change
@@ -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');
1 change: 0 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
datasource db {
url = env("DATABASE_URL")
directUrl= env("DATABASE_DIRECT_URL")
provider = "postgresql"
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/products/components/AddProduct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function AddProduct({ productTypes }: Props) {
variant="shadow"
startContent={<PlusCircleIcon className="h-5 w-5" />}
>
{window.innerWidth > 1024 ? 'Add' : ''}
{window?.innerWidth > 1024 ? 'Add' : ''}
</Button>
<AddModal
showModal={showModel}
Expand Down
2 changes: 1 addition & 1 deletion src/app/products/components/BackHomeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function BackHomeButton() {
variant="shadow"
startContent={<HomeIcon className="w-5 h-5" />}
>
{window.innerWidth > 1024 ? 'Home' : ''}
{window?.innerWidth > 1024 ? 'Home' : ''}
</Button>
</Link>
);
Expand Down
9 changes: 8 additions & 1 deletion src/app/shared/prisma.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 9e17961

Please sign in to comment.