From f8a240668a25cdc8e7bec19cce5df957b0f463ea Mon Sep 17 00:00:00 2001 From: KDwevedi Date: Wed, 18 Dec 2024 14:28:18 +0530 Subject: [PATCH] added dockerfile and docker compose --- .env.sample | 26 ++++++++++++++++++ Dockerfile | 39 ++++++++++++++++++++------- docker-compose.yml | 63 +++++++++++++++++++++++++++++++++++++++----- prisma/schema.prisma | 4 +-- 4 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..f2b4a36 --- /dev/null +++ b/.env.sample @@ -0,0 +1,26 @@ +# Schema Service +SCHEMA_BASE_URL=https://example.com/schema-service + +# Credential Service +CREDENTIAL_BASE_URL=https://example.com/credential-service +C4GT_DID=did:example:123456789abcdefghi +DEFAULT_CERTIFICATE_LIFETIME=31536000 + +# Identity Service +IDENTITY_BASE_URL=url + +# Certificates Verification +VERIFICATION_BASE_URL=https://example.com/verification-service + +# MinIO Configuration +MINIO_USERNAME=your-minio-username +MINIO_PASSWORD=your-minio-password +MINIO_BUCKETNAME=your-bucket-name +MINIO_PORT=9000 +MINIO_ENDPOINT=minioadminpassword +MINIO_SECRET_KEY=your-minio-secret-key +MINIO_ACCESS_KEY=minioadmin +MINIO_USE_SSL=true + +# DB Config +C4GT_BFF_POSTGRES_BASE_URL=postgresql://postgres:password@localhost:5432/c4gtbff?schema=public \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0bbcd3b..1d35b38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,39 @@ -FROM node:16 -# FROM --platform=linux/amd64 node:18-slim +# Stage 1: Build +FROM --platform=linux/amd64 node:18 AS builder +WORKDIR /app + +# Install dependencies and build the application +COPY package.json ./ +COPY yarn.lock ./ +COPY prisma ./prisma/ + +RUN yarn +COPY . . +RUN yarn run build + +# Stage 2: Runtime +FROM --platform=linux/amd64 node:18 AS runtime + +WORKDIR /app + +# Install required runtime dependencies RUN apt-get update \ && apt-get install -y wget gnupg \ && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ && apt-get update \ - && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \ + && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 ghostscript \ --no-install-recommends \ - && rm -rf /var/lib/apt/lists/* \ - && apt-get install ghostscript=10.02.0 + && rm -rf /var/lib/apt/lists/* + +# Copy necessary files from the builder stage +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./ +COPY --from=builder /app/yarn.lock ./ +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/prisma ./prisma +COPY --from=builder /app/tsconfig.json ./ -WORKDIR /app -COPY . ./ -RUN yarn EXPOSE 3001 -CMD ["yarn", "start"] \ No newline at end of file +CMD ["yarn", "start:prod"] diff --git a/docker-compose.yml b/docker-compose.yml index ef28d61..9915221 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,60 @@ -version: '3' +version: '3.8' + services: c4gt-bff: - image: c4gt-bff - build: https://github.com/techsavvyash/c4gt-bff.git - env_file: .env - restart: always + build: + context: . + dockerfile: Dockerfile + container_name: c4gt-bff ports: - - '${SERVICE_PUBLIC_PORT}:3001' \ No newline at end of file + - "3001:3001" + environment: + SCHEMA_BASE_URL: https://example.com/schema-service + CREDENTIAL_BASE_URL: https://example.com/credential-service + C4GT_DID: did:example:123456789abcdefghi + DEFAULT_CERTIFICATE_LIFETIME: 31536000 + IDENTITY_BASE_URL: url + VERIFICATION_BASE_URL: https://example.com/verification-service + MINIO_USERNAME: your-minio-username + MINIO_PASSWORD: your-minio-password + MINIO_BUCKETNAME: your-bucket-name + MINIO_PORT: 9000 + MINIO_ENDPOINT: minioadminpassword + MINIO_SECRET_KEY: your-minio-secret-key + MINIO_ACCESS_KEY: minioadmin + MINIO_USE_SSL: "true" + C4GT_BFF_POSTGRES_BASE_URL: postgres://postgres:postgres@postgres:5432/c4gt-bff + depends_on: + - postgres + - minio + + postgres: + image: postgres:14 + container_name: postgres + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: c4gt-bff + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + + minio: + image: minio/minio:latest + container_name: minio + environment: + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadminpassword + ports: + - "9000:9000" # MinIO web access + - "9001:9001" # MinIO console access + command: server /data --console-address ":9001" + volumes: + - minio_data:/data + +volumes: + postgres_data: + driver: local + minio_data: + driver: local diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b32e804..c4f5523 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -10,7 +10,7 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") + url = env("C4GT_BFF_POSTGRES_BASE_URL") } model Schema { @@ -27,7 +27,7 @@ model Template { type String verificationTemplate Template? @relation("TemplateToVerification", fields: [verificationTemplateId], references: [id]) verificationTemplateId String? // Foreign key for the self-relation - referencedBy Template[]? @relation("TemplateToVerification") + referencedBy Template[] @relation("TemplateToVerification") }