From 3686c9e3147cbb22e849cc68b49ebacc7803d6e4 Mon Sep 17 00:00:00 2001 From: Laurenz Honauer Date: Fri, 16 Jun 2023 13:52:39 +0200 Subject: [PATCH] fix(workspace): create docker compose file and configurize api host and port --- .env.example | 2 ++ apps/api/Dockerfile | 2 +- apps/api/index.ts | 3 ++- apps/api/src/lib/config.ts | 4 ++++ docker-compose.yml | 18 ++++++++++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example index 8f0139a6..25e0180d 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ +API_HOST=localhost +API_PORT=3000 COOKIE_SECRET="our-secure-cookie-secret" LOG_LEVEL=debug DB_URL=file:./db.sqlite diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index 04f67d93..fbebaad2 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -9,7 +9,7 @@ RUN turbo prune --scope=@superlight-labs/api --docker # Install Dependencies and Node Modules -FROM amd64/node:16-bullseye-slim AS installer +FROM amd64/node:16 AS installer RUN apt-get update RUN apt-get --yes install python3 \ diff --git a/apps/api/index.ts b/apps/api/index.ts index 140fcd4d..c979896e 100644 --- a/apps/api/index.ts +++ b/apps/api/index.ts @@ -1,10 +1,11 @@ +import config from '@lib/config'; import { client } from '@superlight-labs/database'; import logger from '@superlight-labs/logger'; import { createServer } from 'src/server'; createServer(client) .then(server => { - server.listen({ port: 8080 }, (err, address) => { + server.listen({ host: config.host, port: config.port }, (err, address) => { if (err) { logger.error({ err, address }, 'Error while trying to listen on port 8080'); process.exit(1); diff --git a/apps/api/src/lib/config.ts b/apps/api/src/lib/config.ts index 3aacabb1..7e6209f6 100644 --- a/apps/api/src/lib/config.ts +++ b/apps/api/src/lib/config.ts @@ -3,6 +3,8 @@ import { config as loadConfig } from 'dotenv'; interface Config { cookieSecret: string; logLevel: string; + host: string; + port: number; } const initConfig = (): Config => { @@ -11,6 +13,8 @@ const initConfig = (): Config => { return { cookieSecret: process.env.COOKIE_SECRET || '', logLevel: process.env.LOG_LEVEL || 'debug', + host: process.env.API_HOST || '0.0.0.0', + port: parseInt(process.env.API_PORT || '3000', 10), }; }; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..d9d9d667 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3.8" + +services: + api: + build: + context: . + dockerfile: ./apps/api/Dockerfile + ports: + - ${API_PORT}:${API_PORT} + environment: + - API_HOST=${API_HOST} + - API_PORT=${API_PORT} + - COOKIE_SECRET=${COOKIE_SECRET} + - LOG_LEVEL=${LOG_LEVEL} + - DB_URL=${DB_URL} + - TATUM_TEST_TOKEN=${TATUM_TEST_TOKEN} + - TATUM_MAIN_TOKEN=${TATUM_MAIN_TOKEN} + domainname: "${API_DOMAIN_NAME}"