From bf3325437fddc7e354084e411a0e91bb3baba43f Mon Sep 17 00:00:00 2001 From: potts99 Date: Sat, 25 Nov 2023 21:47:52 +0000 Subject: [PATCH] docker --- apps/api/src/main.ts | 2 ++ apps/client/package.json | 4 +--- apps/client/pages/auth/login.tsx | 2 +- apps/client/prisma/prisma.js | 2 -- docker-compose.dev.yml | 2 +- docker-compose.local.yml | 4 ++-- docker-compose.yml | 2 +- dockerfile | 7 ++++--- ecosystem.config.js | 1 + 9 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 apps/client/prisma/prisma.js diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 0f22f38c1..bc4861bc9 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -29,6 +29,7 @@ server.register(require("@fastify/swagger"), { url: "https://swagger.io", description: "Find more info here", }, + mode: "static", host: "localhost", schemes: ["http"], consumes: ["application/json"], @@ -37,6 +38,7 @@ server.register(require("@fastify/swagger"), { { name: "user", description: "User related end-points" }, { name: "code", description: "Code related end-points" }, ], + exposeRoute: true, definitions: { User: { type: "object", diff --git a/apps/client/package.json b/apps/client/package.json index 4babf918f..11ad3bb07 100644 --- a/apps/client/package.json +++ b/apps/client/package.json @@ -5,9 +5,7 @@ "scripts": { "dev": "next dev", "build": "next build", - "start": "next start", - "docker": "yarn run migrate && yarn run generate && yarn run seed && yarn start", - "pm2-prod": "yarn run migrate && yarn run generate && yarn run seed && yarn run build && pm2 start npm --name \"next\" -- start" + "start": "next start" }, "dependencies": { "@headlessui/react": "^1.4.2", diff --git a/apps/client/pages/auth/login.tsx b/apps/client/pages/auth/login.tsx index 2fd297986..623581a91 100644 --- a/apps/client/pages/auth/login.tsx +++ b/apps/client/pages/auth/login.tsx @@ -14,7 +14,7 @@ export default function Login({}) { const { setUser } = useUser(); async function postData() { - await fetch("http://localhost:5003/api/v1/auth/login", { + await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/login`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), diff --git a/apps/client/prisma/prisma.js b/apps/client/prisma/prisma.js deleted file mode 100644 index 2b349b84b..000000000 --- a/apps/client/prisma/prisma.js +++ /dev/null @@ -1,2 +0,0 @@ -import { PrismaClient } from 'database'; -export const prisma = new PrismaClient(); diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index be2a4b060..50031815a 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -32,7 +32,7 @@ services: DB_USERNAME: "peppermint" DB_PASSWORD: "1234" DB_HOST: "peppermint_postgres" - API_PORT: 5003 + API_URL: "http://localhost:5003" volumes: pgdata: \ No newline at end of file diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 4a6a76865..3d99c4769 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -32,7 +32,7 @@ services: DB_USERNAME: "peppermint" DB_PASSWORD: "1234" DB_HOST: "peppermint_postgres" - API_PORT: 5003 - + API_URL: "http://localhost:5003" + volumes: pgdata: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0ff3b8ae6..64ff7be46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +32,7 @@ services: DB_USERNAME: "peppermint" DB_PASSWORD: "1234" DB_HOST: "peppermint_postgres" - API_PORT: 5003 + API_URL: "http://localhost:5003" volumes: pgdata: \ No newline at end of file diff --git a/dockerfile b/dockerfile index 65df1d0ae..05b069aa4 100644 --- a/dockerfile +++ b/dockerfile @@ -9,6 +9,8 @@ RUN apt-get update && \ # Copy the package.json and package-lock.json files for both apps COPY apps/api/package*.json ./apps/api/ COPY apps/client/package*.json ./apps/client/ +COPY ./ecosystem.config.js ./ecosystem.config.js + RUN npm i -g prisma RUN npm i -g typescript@latest -g --force @@ -27,8 +29,7 @@ FROM node:lts AS runner COPY --from=builder /app/apps/api/ ./apps/api/ COPY --from=builder /app/apps/client ./apps/client -COPY ./ecosystem.config.js ./ecosystem.config.js - +COPY --from=builder /app/ecosystem.config.js ./ecosystem.config.js # Expose the ports for both apps EXPOSE 3000 5003 @@ -37,5 +38,5 @@ EXPOSE 3000 5003 RUN npm install -g pm2 # Start both apps using PM2 -CMD ["pm2-runtime", "ecosystem.config .js"] +CMD ["pm2-runtime", "ecosystem.config.js"] diff --git a/ecosystem.config.js b/ecosystem.config.js index c58857f8a..6bb8fb8c2 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -11,6 +11,7 @@ module.exports = { env: { NODE_ENV: "production", PORT: 3000, // Change this to your desired port + API_URL: process.env.API_URL, }, }, {