From 424359ec0fe4f6881199f99552d10f82bb404387 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Fri, 8 Mar 2024 13:06:23 -0300 Subject: [PATCH] Attempt at docker building --- .dockerignore | 1 + Dockerfile | 11 +++++++++++ apps/api/package.json | 2 +- apps/api/src/server.ts | 11 ++++++++++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0d8de4c --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d70ebeb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM node:21-alpine3.18 +RUN npm i -g pnpm turbo + +WORKDIR /app +COPY . . + +RUN pnpm install +ENV PAYLOAD_CONFIG_PATH=src/payload.config.ts +RUN pnpm build + +CMD ["pnpm", "serve"] diff --git a/apps/api/package.json b/apps/api/package.json index 4b6dba5..70b17fd 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -17,7 +17,7 @@ "dependencies": { "dotenv": "^8.2.0", "express": "^4.17.1", - "payload": "latest", + "payload": "1.12.0", "@payloadcms/plugin-seo": "latest", "@payloadcms/plugin-cloud-storage": "latest", "@aws-sdk/client-s3": "latest", diff --git a/apps/api/src/server.ts b/apps/api/src/server.ts index 5298e66..3386429 100644 --- a/apps/api/src/server.ts +++ b/apps/api/src/server.ts @@ -8,6 +8,9 @@ app.get("/", (_, res) => { res.redirect("/admin"); }); +const PORT = process.env.PAYLOAD_PORT ?? 3000, +const HOST = process.env.PAYLOAD_ADDRESS ?? 'localhost', + const start = async () => { // Initialize Payload await payload.init({ @@ -24,7 +27,13 @@ const start = async () => { // Add your own express routes here - app.listen(process.env.PAYLOAD_PORT ?? 3000); + app.listen( + PORT, + HOST, + () => { + console.log(`Server running at http://${HOST}:${PORT}/`); + } + ); }; start();