From 9403aebbb95fc69f9c2e224f3b47d02bb26151b6 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 28 Sep 2024 14:21:53 +0200 Subject: [PATCH] update dockercompose --- .dockerignore | 11 ++++++ consumer/Dockerfile | 38 ++++++++++++++++++ consumer/package.json | 4 +- dashboard/Dockerfile | 1 + dashboard/package.json | 2 +- docker-compose.yml | 88 ++++++++++++++++++------------------------ producer/Dockerfile | 38 ++++++++++++++++++ scripts/pnpm-lock.yaml | 18 +-------- 8 files changed, 130 insertions(+), 70 deletions(-) create mode 100644 consumer/Dockerfile create mode 100644 producer/Dockerfile diff --git a/.dockerignore b/.dockerignore index ac56bfd..b96f0d5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,20 @@ shared/node_modules shared/.output +scripts/node_modules + lyx-ui/node_modules lyx-ui/.nuxt lyx-ui/.output +producer/node_modules +producer/scripts/start_dev.js +producer/ecosystem.config.cjs + +consumer/node_modules +consumer/scripts/start_dev.js +consumer/ecosystem.config.cjs + dashboard/node_modules dashboard/.nuxt dashboard/.output @@ -12,4 +22,5 @@ dashboard/explains dashboard/tests dashboard/.env dashboard/winston-*.ndjson +dashboard/ecosystem.config.cjs diff --git a/consumer/Dockerfile b/consumer/Dockerfile new file mode 100644 index 0000000..3ef504d --- /dev/null +++ b/consumer/Dockerfile @@ -0,0 +1,38 @@ +# Start with a minimal Node.js base image +FROM node:21-alpine as base + +# Install pnpm globally with caching to avoid reinstalling if nothing has changed +RUN npm i -g pnpm + +# Set the working directory +WORKDIR /home/app + +# Copy only package-related files to leverage caching +COPY --link ./scripts/package.json ./scripts/pnpm-lock.yaml ./scripts/ +COPY --link ./shared/package.json ./shared/pnpm-lock.yaml ./shared/ +COPY --link ./consumer/package.json ./consumer/pnpm-lock.yaml ./consumer/ + +# Install dependencies for each package +WORKDIR /home/app/scripts +RUN pnpm install --frozen-lockfile + +WORKDIR /home/app/shared +RUN pnpm install --frozen-lockfile + +WORKDIR /home/app/consumer +RUN pnpm install --frozen-lockfile + +# Now copy the rest of the source files +WORKDIR /home/app + +COPY --link ../scripts ./scripts +COPY --link ../shared ./shared +COPY --link ../consumer ./consumer + +# Build the consumer +WORKDIR /home/app/consumer + +RUN pnpm run build_all + +# Start the application +CMD ["node", "/home/app/consumer/dist/consumer/src/index.js"] \ No newline at end of file diff --git a/consumer/package.json b/consumer/package.json index fbab12c..5ef3b6a 100644 --- a/consumer/package.json +++ b/consumer/package.json @@ -19,7 +19,9 @@ "compile": "tsc", "build": "node ../scripts/build.js", "create_db": "cd scripts && ts-node create_database.ts", - "build_all": "npm run compile && npm run build && npm run create_db" + "build_all": "npm run compile && npm run build && npm run create_db", + "docker-build": "docker build -t litlyx-consumer -f Dockerfile ../", + "docker-inspect": "docker run -it litlyx-consumer sh" }, "keywords": [], "author": "Emily", diff --git a/dashboard/Dockerfile b/dashboard/Dockerfile index 009bd20..6dfe4c8 100644 --- a/dashboard/Dockerfile +++ b/dashboard/Dockerfile @@ -34,6 +34,7 @@ COPY --link ./shared ./shared # Build the dashboard WORKDIR /home/app/dashboard + RUN pnpm run build # Use a smaller base image for the final production build diff --git a/dashboard/package.json b/dashboard/package.json index 42285aa..f66132a 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -11,7 +11,7 @@ "test": "vitest", "docker-build": "docker build -t litlyx-dashboard -f Dockerfile ../", "docker-inspect": "docker run -it litlyx-dashboard sh", - "docker-run": "docker run -p 3000:3000 --name litlyx-dashboard litlyx-dashboard" + "docker-run": "docker run -p 3000:3000 litlyx-dashboard" }, "dependencies": { "@getbrevo/brevo": "^2.2.0", diff --git a/docker-compose.yml b/docker-compose.yml index c49b83d..7c83833 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,62 +2,57 @@ services: mongo: image: mongo environment: + # Change with your database username MONGO_INITDB_ROOT_USERNAME: litlyx + # Change with your database password MONGO_INITDB_ROOT_PASSWORD: litlyx - # Uncomment to expose database - # ports: # - 27017:27017 - volumes: - mongo-data:/data/db cache: image: redis:alpine restart: always - # Uncomment to expose redis - # ports: # - "6379:6379" - + # Change with "--requirepass YOUR_REDIS_PASSWORD" command: redis-server --save 20 1 --loglevel warning --requirepass litlyx - # producer: - # image: litlyx-producer - # restart: always - # ports: - # - "3099:3099" - # environment: - # PORT: "3099" - # REDIS_URL: "redis://cache" - # REDIS_USERNAME: "default" - # REDIS_PASSWORD: "litlyx" - # STREAM_NAME: "lib-events" - # build: - # dockerfile: ./producer/Dockerfile + producer: + image: litlyx-producer + restart: always + ports: + - "3099:3099" + environment: + PORT: "3099" + REDIS_URL: "redis://cache" + REDIS_USERNAME: "default" + # Change with your redis password + REDIS_PASSWORD: "litlyx" + STREAM_NAME: "LITLYX" + build: + dockerfile: ./producer/Dockerfile - # broker: - # image: litlyx-consumer - # restart: always - # ports: - # - "3999:3999" - # environment: - - # # Optional - Used to send welcome and quota emails - - # # NUXT_EMAIL_SERVICE: "Brevo" - # # NUXT_BREVO_API_KEY: "" - - # PORT: "3999" - # MONGO_CONNECTION_STRING: "mongodb://litlyx:litlyx@mongo:27017/SimpleMetrics?readPreference=primaryPreferred&authSource=admin" - # REDIS_URL: "redis://cache" - # REDIS_USERNAME: "default" - # REDIS_PASSWORD: "litlyx" - # STREAM_NAME: "lib-events" - # build: - # dockerfile: ./broker/Dockerfile + consumer: + image: litlyx-consumer + restart: always + environment: + # Optional - Used to send welcome and quota emails + # EMAIL_SERVICE: "Brevo" + # BREVO_API_KEY: "" + # Change "litlyx:litlyx" with "mongodb://YOUR_MONGO_USERNAME:YOUR_MONGO_PASSWORD" + MONGO_CONNECTION_STRING: "mongodb://litlyx:litlyx@mongo:27017/SimpleMetrics?readPreference=primaryPreferred&authSource=admin" + REDIS_URL: "redis://cache" + REDIS_USERNAME: "default" + # Change with your redis password + REDIS_PASSWORD: "litlyx" + STREAM_NAME: "LITLYX" + GROUP_NAME: "DATABASE" + build: + dockerfile: ./broker/Dockerfile dashboard: image: litlyx-dashboard @@ -66,57 +61,48 @@ services: - "3000:3000" environment: NUXT_PORT: "3000" + # Change "litlyx:litlyx" with "mongodb://YOUR_MONGO_USERNAME:YOUR_MONGO_PASSWORD" NUXT_MONGO_CONNECTION_STRING: 'mongodb://litlyx:litlyx@mongo:27017/SimpleMetrics?readPreference=primaryPreferred&authSource=admin' - NUXT_REDIS_URL: "redis://cache" NUXT_REDIS_USERNAME: "default" + # Change with your redis password NUXT_REDIS_PASSWORD: "litlyx" # Optional - Used for Lit, the AI analyst - # NUXT_AI_ORG: 'OPEN_AI_ORGANIZATION' # NUXT_AI_PROJECT: 'OPEN_AI_PROJECT' # NUXT_AI_KEY: 'OPEN_AI_KEY' - # Optional - Used to send welcome and quota emails - # NUXT_EMAIL_SERVICE: "Brevo" # NUXT_BREVO_API_KEY: "" + # Change with your jwt secret NUXT_AUTH_JWT_SECRET: "litlyx_jwt_secret" # Optional - Used to register / login via google - # NUXT_GOOGLE_AUTH_CLIENT_ID: "" # NUXT_GOOGLE_AUTH_CLIENT_SECRET: "" # NO_AUTH or GOOGLE - NUXT_PUBLIC_AUTH_MODE: 'NO_AUTH' # Default user created in NO_AUTH mode - NUXT_NOAUTH_USER_EMAIL: 'default@user.com' NUXT_NOAUTH_USER_NAME: "defaultuser" - # Optional - Used for tests - # NUXT_STRIPE_SECRET_TEST: "" # NUXT_STRIPE_WH_SECRET_TEST: "" # Optional - Stripe secret - Used to change plans of the projects - # NUXT_STRIPE_SECRET: "" # NUXT_STRIPE_WH_SECRET: "" build: dockerfile: ./dashboard/Dockerfile #args: - # Optional - Used to register / login via google - # GOOGLE_AUTH_CLIENT_ID: "" volumes: diff --git a/producer/Dockerfile b/producer/Dockerfile new file mode 100644 index 0000000..ae69736 --- /dev/null +++ b/producer/Dockerfile @@ -0,0 +1,38 @@ +# Start with a minimal Node.js base image +FROM node:21-alpine as base + +# Install pnpm globally with caching to avoid reinstalling if nothing has changed +RUN npm i -g pnpm + +# Set the working directory +WORKDIR /home/app + +# Copy only package-related files to leverage caching +COPY --link ./scripts/package.json ./scripts/pnpm-lock.yaml ./scripts/ +COPY --link ./shared/package.json ./shared/pnpm-lock.yaml ./shared/ +COPY --link ./producer/package.json ./producer/pnpm-lock.yaml ./producer/ + +# Install dependencies for each package +WORKDIR /home/app/scripts +RUN pnpm install --frozen-lockfile + +WORKDIR /home/app/shared +RUN pnpm install --frozen-lockfile + +WORKDIR /home/app/producer +RUN pnpm install --frozen-lockfile + +# Now copy the rest of the source files +WORKDIR /home/app + +COPY --link ../scripts ./scripts +COPY --link ../shared ./shared +COPY --link ../producer ./producer + +# Build the producer +WORKDIR /home/app/producer + +RUN pnpm run build_all + +# Start the application +CMD ["node", "/home/app/producer/dist/producer/src/index.js"] \ No newline at end of file diff --git a/scripts/pnpm-lock.yaml b/scripts/pnpm-lock.yaml index 899c764..5ed705b 100644 --- a/scripts/pnpm-lock.yaml +++ b/scripts/pnpm-lock.yaml @@ -7,14 +7,10 @@ settings: importers: .: - dependencies: + devDependencies: glob: specifier: ^11.0.0 version: 11.0.0 - devDependencies: - '@types/node': - specifier: ^22.5.5 - version: 22.5.5 packages: @@ -26,9 +22,6 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} - '@types/node@22.5.5': - resolution: {integrity: sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==} - ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} @@ -142,9 +135,6 @@ packages: resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} engines: {node: '>=12'} - undici-types@6.19.8: - resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} - which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} @@ -172,10 +162,6 @@ snapshots: '@pkgjs/parseargs@0.11.0': optional: true - '@types/node@22.5.5': - dependencies: - undici-types: 6.19.8 - ansi-regex@5.0.1: {} ansi-regex@6.1.0: {} @@ -279,8 +265,6 @@ snapshots: dependencies: ansi-regex: 6.1.0 - undici-types@6.19.8: {} - which@2.0.2: dependencies: isexe: 2.0.0