From fb0cf85d7a0c9e69044a354180f559ca32c675f0 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Tue, 11 Jun 2024 11:58:14 +0200 Subject: [PATCH] chore: setup prod and dev docker with compose ref #229 --- .gitignore | 67 ++++++------------- README.md | 35 ++++++---- apps/api/package-lock.json | 0 apps/api/package.json | 1 + apps/deploy-web/package.json | 2 +- apps/indexer/package.json | 1 + apps/landing/package.json | 4 +- apps/stats-web/next.config.js | 1 + docker-compose.build.yml | 27 ++++++++ docker-compose.prod.yml | 76 ++++++++++++++++++++++ docker-compose.yml | 108 +++++++++++-------------------- docker/Dockerfile.api | 32 +++++---- docker/Dockerfile.deploy-web | 54 ++++++---------- docker/Dockerfile.indexer | 19 ++++-- docker/Dockerfile.landing | 38 ++++++----- docker/Dockerfile.provider-proxy | 11 ++-- docker/Dockerfile.stats-web | 49 +++++--------- package-lock.json | 10 +-- package.json | 4 ++ 19 files changed, 291 insertions(+), 248 deletions(-) create mode 100755 apps/api/package-lock.json create mode 100644 docker-compose.build.yml create mode 100644 docker-compose.prod.yml diff --git a/.gitignore b/.gitignore index 259a6bc36..e4fff45aa 100644 --- a/.gitignore +++ b/.gitignore @@ -16,52 +16,42 @@ pids *.seed *.pid.lock -# Directory for instrumented libs generated by jscoverage/JSCover +# Coverage directories and reports lib-cov - -# Coverage directory used by tools like istanbul coverage *.lcov - -# nyc test coverage .nyc_output -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - # Dependency directories node_modules/ jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) web_modules/ +bower_components -# TypeScript cache -*.tsbuildinfo +# Build directories and tools +build/Release +.grunt +.lock-wscript +.next +out +dist +build.ps1 -# Optional npm cache directory +# Caches .npm - -# Optional eslint cache .eslintcache - -# Optional stylelint cache .stylelintcache - -# Microbundle cache .rpt2_cache/ .rts2_cache_cjs/ .rts2_cache_es/ .rts2_cache_umd/ +.turbo +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* +*.tsbuildinfo # Optional REPL history .node_repl_history @@ -79,27 +69,10 @@ web_modules/ .env.production.local .env.local -# Next.js build output -.next -out -dist - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - # IDE files .idea .vscode - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -# Scripts -build.ps1 +.vscode-test # Data Folder -data +data \ No newline at end of file diff --git a/README.md b/README.md index 56c5dbed3..5461d6f5d 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,28 @@ See [Example_Queries.md](./doc/Example_Queries.md) This document provides instructions on how to set up and run the application, including steps for manual database restoration and using Docker Compose for ease of setup. +### Using Docker and Docker Compose +This project's service are deployed using Docker and Docker Compose. The following sections provide instructions for setting up and running the application using Docker Compose. +All the Dockerfiles are using multi-stage builds to optimize the image build processes. Same files are used to build both development and production images. There are 3 docker-compose files: +- **docker-compose.build.yml:** Base file solely building production images for the services. It can be used to verify the same build process as in CICD. +- **docker-compose.prod.yml:** This file is used to run the services in production mode. It also includes the database service which would fetch a remote backup and import it on init. +- **docker-compose.yml:** The default file to run all the services in development mode with features like hot-reload. + +Some commands are added to package.json for convenience. + +```shell +npm run dc:build # Build the production images +npm run dc:up:prod # Run the services in production mode +npm run dc:up:dev # Run the services in development mode +npm run dc:down # Stop the services referencing any possible service +``` + +Note: you may pass any `docker compose` related arguments to the above commands. E.g. to only start `deploy-web` service in development mode: +```shell +npm run dc:up:dev -- deploy-web +``` +This would also properly spin up all the dependencies like the `api`. + ## Manual Database Restoration Due to the extensive time required to index Akash from block #1, it's recommended to initialize your database using an existing backup for efficiency. This approach is particularly beneficial for development purposes. @@ -108,19 +130,6 @@ gunzip -c /path/to/cloudmos-akash-sandbox.sql.gz | psql --host "localhost" --por ``` After restoring the database, you can proceed with the specific project's README instructions for further setup and running the application. -### Using Docker Compose -For convenience, a Docker Compose configuration is provided to automate the database setup, download, and data import process. - -#### Configuration -1. Ensure environment variables are set in .postgres.local.env. This file configures PostgreSQL and import settings. -2. The `POSTGRES_DBS_FOR_IMPORT` variable should be updated with the databases you wish to import. This is a comma-separated list with potential values including `cloudmos-akash-sandbox` (default) and `cloudmos-akash-2` (mainnet). Leave this variable empty if no import is desired. - -#### Running Docker Compose -```sh -docker-compose up db -``` -This command spins up the database service and automatically handles the downloading and importing of the specified data. - # Database Structure The database schemas is defined using [sequelize-typescript](https://github.com/sequelize/sequelize-typescript) in [/shared/dbSchemas/](./shared/dbSchemas/). Models are separated into the following folders: diff --git a/apps/api/package-lock.json b/apps/api/package-lock.json new file mode 100755 index 000000000..e69de29bb diff --git a/apps/api/package.json b/apps/api/package.json index dd4abc410..1c1676d2b 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -14,6 +14,7 @@ "format": "prettier --write ./*.{js,json} **/*.{ts,js,json}", "lint": "eslint .", "start": "webpack --config webpack.dev.js --watch", + "dev": "npm run start", "test": "jest --selectProjects unit functional", "test:cov": "jest --selectProjects unit functional --coverage", "test:functional": "jest --selectProjects functional", diff --git a/apps/deploy-web/package.json b/apps/deploy-web/package.json index 08699d090..0ea8146ae 100644 --- a/apps/deploy-web/package.json +++ b/apps/deploy-web/package.json @@ -8,7 +8,7 @@ "scripts": { "build": "next build", "build-analyze": "set ANALYZE=true&& next build", - "dev": "next -p 3000", + "dev": "next", "format": "prettier --write ./*.{ts,js,json} **/*.{ts,tsx,js,json}", "lint": "eslint .", "start": "next start", diff --git a/apps/indexer/package.json b/apps/indexer/package.json index e4862c858..d9a1f2425 100644 --- a/apps/indexer/package.json +++ b/apps/indexer/package.json @@ -18,6 +18,7 @@ "format": "prettier --write ./*.{js,json} **/*.{ts,js,json}", "lint": "eslint .", "start": "webpack --mode development --config webpack.dev.js --watch", + "dev": "npm run start", "test": "jest" }, "dependencies": { diff --git a/apps/landing/package.json b/apps/landing/package.json index ce382caa2..4efb2996a 100644 --- a/apps/landing/package.json +++ b/apps/landing/package.json @@ -1,5 +1,5 @@ { - "name": "cloudmos-block-explorer", + "name": "console-landing", "version": "2.5.2", "private": true, "description": "Landing page for Cloudmos", @@ -7,7 +7,7 @@ "author": "Cloudmos", "scripts": { "build": "next build", - "dev": "next -p 3001", + "dev": "next", "format": "prettier --write ./*.{ts,js,json} **/*.{ts,tsx,js,json}", "lint": "eslint .", "start": "next start", diff --git a/apps/stats-web/next.config.js b/apps/stats-web/next.config.js index 30fcdc7f1..0e55bf6a3 100644 --- a/apps/stats-web/next.config.js +++ b/apps/stats-web/next.config.js @@ -1,4 +1,5 @@ const { version } = require("./package.json"); +const path = require("path"); /** @type {import('next').NextConfig} */ const nextConfig = { diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 000000000..971e90493 --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,27 @@ +services: + api: + build: + dockerfile: docker/Dockerfile.api + target: production + + indexer: + build: + dockerfile: docker/Dockerfile.indexer + target: production + + provider-proxy: + build: + dockerfile: docker/Dockerfile.provider-proxy + + deploy-web: + build: + dockerfile: docker/Dockerfile.deploy-web + target: production + + stats-web: + build: + dockerfile: docker/Dockerfile.stats-web + + landing: + build: + dockerfile: docker/Dockerfile.landing diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 000000000..ab29281fe --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,76 @@ +services: + api: + restart: always + environment: + AkashSandboxDatabaseCS: postgres://postgres:password@db:5432/cloudmos-akash-sandbox + UserDatabaseCS: postgres://postgres:password@db:5432/cloudmos-users + env_file: + - apps/api/.env.local + ports: + - '3080:3080' + depends_on: + - db + + indexer: + restart: always + environment: + AkashSandboxDatabaseCS: postgres://postgres:password@db:5432/cloudmos-akash-sandbox + UserDatabaseCS: postgres://postgres:password@db:5432/cloudmos-users + env_file: + - apps/indexer/.env.local + depends_on: + - db + + provider-proxy: + restart: always + ports: + - '3040:3040' + + deploy-web: + restart: always + environment: + API_BASE_URL: http://api:3080 + PROVIDER_PROXY_URL: http://provider-proxy:3040 + env_file: + - apps/deploy-web/.env.local + ports: + - '3000:3000' + depends_on: + - api + - provider-proxy + + stats-web: + restart: always + environment: + API_MAINNET_BASE_URL: http://api:3080 + API_TESTNET_BASE_URL: http://api:3080 + API_SANDBOX_BASE_URL: http://api:3080 + API_BASE_URL: http://api:3080 + ports: + - '3001:3000' + depends_on: + - api + + landing: + restart: always + ports: + - '3002:3000' + + db: + build: + context: docker + dockerfile: Dockerfile.db + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DBS_FOR_IMPORT: cloudmos-akash-sandbox + POSTGRES_USERS_DB: cloudmos-users + restart: always + ports: + - '5432:5432' + volumes: + - postgres_data:/var/lib/postgresql/data + +volumes: + postgres_data: + driver: local diff --git a/docker-compose.yml b/docker-compose.yml index 86bee4533..6977d738d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,88 +1,54 @@ services: api: build: - dockerfile: docker/Dockerfile.api - restart: always - environment: - AkashSandboxDatabaseCS: postgres://postgres:password@db:5432/cloudmos-akash-sandbox - UserDatabaseCS: postgres://postgres:password@db:5432/cloudmos-users - env_file: - - apps/api/.env.local - ports: - - '3080:3080' - depends_on: - - db + target: development + volumes: + - ./apps/api:/app/apps/api + - ./package.json:/app/package.json + - ./package-lock.json:/app/package-lock.json + - /app/node_modules + - /app/apps/api/node_modules indexer: build: - dockerfile: docker/Dockerfile.indexer - restart: always - environment: - AkashSandboxDatabaseCS: postgres://postgres:password@db:5432/cloudmos-akash-sandbox - UserDatabaseCS: postgres://postgres:password@db:5432/cloudmos-users - env_file: - - apps/indexer/.env.local - depends_on: - - db - - provider-proxy: - build: - dockerfile: docker/Dockerfile.provider-proxy - restart: always - ports: - - '3040:3040' + target: development + volumes: + - ./apps/indexer:/app/apps/indexer + - ./package.json:/app/package.json + - ./package-lock.json:/app/package-lock.json + - /app/node_modules + - /app/apps/indexer/node_modules deploy-web: build: - dockerfile: docker/Dockerfile.deploy-web - restart: always - environment: - API_BASE_URL: http://api:3080 - PROVIDER_PROXY_URL: http://provider-proxy:3040 - env_file: - - apps/deploy-web/.env.local - ports: - - '3000:3001' - depends_on: - - api - - provider-proxy + target: development + volumes: + - ./apps/deploy-web:/app/apps/deploy-web + - ./package.json:/app/package.json + - ./package-lock.json:/app/package-lock.json + - /app/node_modules + - /app/apps/deploy-web/node_modules + - /app/apps/deploy-web/.next stats-web: build: - dockerfile: docker/Dockerfile.stats-web - restart: always - environment: - API_MAINNET_BASE_URL: http://api:3080 - API_TESTNET_BASE_URL: http://api:3080 - API_SANDBOX_BASE_URL: http://api:3080 - API_BASE_URL: http://api:3080 - ports: - - '3001:3001' - depends_on: - - api + target: development + volumes: + - ./apps/stats-web:/app/apps/stats-web + - ./package.json:/app/package.json + - ./package-lock.json:/app/package-lock.json + - /app/node_modules + - /app/apps/stats-web/node_modules + - /app/apps/stats-web/.next landing: build: - dockerfile: docker/Dockerfile.landing - restart: always - ports: - - '3002:3001' - - db: - build: - context: docker - dockerfile: Dockerfile.db - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: password - POSTGRES_DBS_FOR_IMPORT: cloudmos-akash-sandbox - POSTGRES_USERS_DB: cloudmos-users - restart: always - ports: - - '5432:5432' + target: development volumes: - - postgres_data:/var/lib/postgresql/data + - ./apps/landing:/app/apps/landing + - ./package.json:/app/package.json + - ./package-lock.json:/app/package-lock.json + - /app/node_modules + - /app/apps/landing/node_modules + - /app/apps/landing/.next -volumes: - postgres_data: - driver: local diff --git a/docker/Dockerfile.api b/docker/Dockerfile.api index 745881cb1..d72d024a4 100644 --- a/docker/Dockerfile.api +++ b/docker/Dockerfile.api @@ -1,4 +1,10 @@ -FROM node:20-alpine AS builder +FROM node:20-alpine AS base + +WORKDIR /app + +RUN apk add --no-cache python3 make g++ libc6-compat postgresql-dev + +FROM base AS development WORKDIR /app @@ -7,28 +13,20 @@ COPY /packages /app/packages COPY package.json /app COPY package-lock.json /app -RUN apk add --no-cache python3 make g++ libc6-compat postgresql-dev +RUN npm install -RUN npm ci -RUN npm run build --workspace apps/api +CMD ["npm", "run", "dev", "--workspace", "apps/api"] -FROM node:20-alpine +FROM development AS builder WORKDIR /app -COPY --from=builder /app/packages/shared /app/packages/shared -COPY --from=builder /app/package.json /app/package.json -COPY --from=builder /app/package-lock.json /app/package-lock.json - -COPY --from=builder /app/apps/api/dist /app/apps/api/dist -COPY --from=builder /app/apps/api/package.json /app/apps/api/package.json - -RUN apk add --no-cache python3 make g++ libc6-compat postgresql-dev +RUN npm run build --workspace apps/api -RUN npm ci --workspace apps/api --omit=dev +FROM base AS production -EXPOSE 80 +WORKDIR /app -WORKDIR /app/apps/api +COPY --from=builder /app/apps/api/dist /app -CMD ["node", "dist/server.js"] \ No newline at end of file +CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker/Dockerfile.deploy-web b/docker/Dockerfile.deploy-web index a227cf152..580da7ad7 100644 --- a/docker/Dockerfile.deploy-web +++ b/docker/Dockerfile.deploy-web @@ -1,64 +1,50 @@ -FROM node:20 AS base +FROM node:20-alpine AS base -FROM base AS deps +ENV NEXT_TELEMETRY_DISABLED 1 + +FROM base AS development + +ENV NODE_ENV development WORKDIR /app +RUN apk add --no-cache libc6-compat + +COPY apps/deploy-web ./apps/deploy-web +COPY apps/deploy-web/patches ./apps/deploy-web/patches +COPY /packages /app/packages COPY package.json /app COPY package-lock.json /app -COPY apps/deploy-web/patches ./apps/deploy-web/patches -COPY apps/deploy-web/package.json ./apps/deploy-web/ -RUN apt-get update && apt-get install -y libc6-dev && \ - ARCH=$(uname -m) && \ - if [ "$ARCH" = "x86_64" ]; then \ - npm install @next/swc-linux-x64-gnu; \ - elif [ "$ARCH" = "aarch64" ]; then \ - npm install @next/swc-linux-arm64-gnu; \ - else \ - echo "Unsupported architecture"; exit 1; \ - fi +RUN npm install -RUN npm ci +CMD ["npm", "run", "dev", "--workspace", "apps/deploy-web"] -FROM base AS builder +FROM development AS builder WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY --from=deps /app/apps/deploy-web/node_modules ./apps/deploy-web/node_modules -COPY . . - -ENV NEXT_TELEMETRY_DISABLED 1 +ENV NODE_ENV production RUN npm run build -w apps/deploy-web -FROM node:20 AS runner +FROM base AS production + WORKDIR /app ENV NODE_ENV production -ENV NEXT_TELEMETRY_DISABLED 1 - -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs COPY --from=builder /app/apps/deploy-web/public ./apps/deploy-web/public COPY --from=builder --chown=nextjs:nodejs /app/apps/deploy-web/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/apps/deploy-web/.next/static ./apps/deploy-web/.next/static -RUN apt-get update -RUN apt-get install libcap2-bin -y +RUN apk add --no-cache libcap nginx openssl RUN setcap cap_net_bind_service=+ep `readlink -f \`which node\`` -RUN apt-get install nginx -y +RUN apk add --no-cache nginx RUN mkdir -p /etc/nginx/ssl RUN openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout /etc/nginx/ssl/my_ssl_key.key -out /etc/nginx/ssl/my_ssl_cert.crt -subj "/CN=cloudmos.io" -days 600 COPY apps/deploy-web/nginx.conf /etc/nginx/nginx.conf RUN nginx -t -EXPOSE 80 -EXPOSE 443 - -ENV PORT 3001 - -CMD sed -i "s/127.0.0.1/$(hostname -i)/" /etc/nginx/nginx.conf && service nginx start && node apps/deploy-web/server.js \ No newline at end of file +CMD sed -i "s/127.0.0.1/$(hostname -i)/" /etc/nginx/nginx.conf && nginx && node apps/deploy-web/server.js \ No newline at end of file diff --git a/docker/Dockerfile.indexer b/docker/Dockerfile.indexer index f07438e00..8bc0b4889 100644 --- a/docker/Dockerfile.indexer +++ b/docker/Dockerfile.indexer @@ -1,4 +1,8 @@ -FROM node:20-alpine AS builder +FROM node:20-alpine AS base + +WORKDIR /app + +FROM base AS development WORKDIR /app @@ -7,10 +11,17 @@ COPY /packages /app/packages COPY package.json /app COPY package-lock.json /app -RUN npm ci --include-workspace-root --workspace=apps/indexer +RUN npm install + +CMD ["npm", "run", "dev", "--workspace", "apps/indexer"] + +FROM development AS builder + +WORKDIR /app + RUN npm run build --workspace apps/indexer -FROM node:20-alpine +FROM base AS production WORKDIR /app @@ -22,8 +33,6 @@ COPY --from=builder /app/apps/indexer/package.json /app/apps/indexer/package.jso RUN npm ci --workspace apps/indexer --omit=dev -EXPOSE 80 - WORKDIR /app/apps/indexer CMD ["node", "dist/server.js"] \ No newline at end of file diff --git a/docker/Dockerfile.landing b/docker/Dockerfile.landing index f540e341f..8ab1a8219 100644 --- a/docker/Dockerfile.landing +++ b/docker/Dockerfile.landing @@ -1,31 +1,38 @@ -FROM node:20-alpine AS deps +FROM node:20-alpine AS base + +ENV NEXT_TELEMETRY_DISABLED 1 + +FROM base AS development + +ENV NODE_ENV development + +WORKDIR /app + # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat -WORKDIR /app +COPY apps/landing ./apps/landing +COPY /packages /app/packages COPY package.json /app COPY package-lock.json /app -COPY apps/landing/package.json ./apps/landing/ -RUN npm ci +RUN npm install -FROM node:20-alpine AS builder -WORKDIR /app +CMD ["npm", "run", "dev", "--workspace", "apps/landing"] -COPY --from=deps /app/node_modules ./node_modules -COPY --from=deps /app/apps/landing/node_modules ./apps/landing/node_modules -COPY . . +FROM development AS builder -ENV NEXT_TELEMETRY_DISABLED 1 +WORKDIR /app + +ENV NODE_ENV production RUN npm run build -w apps/landing -ENV NEXT_TELEMETRY_DISABLED 1 -FROM node:20-alpine AS runner +FROM base AS production + WORKDIR /app ENV NODE_ENV production -ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs @@ -36,8 +43,7 @@ COPY --from=builder --chown=nextjs:nodejs /app/apps/landing/.next/static ./apps/ USER nextjs -EXPOSE 3001 - -ENV PORT 3001 +#EXPOSE 3001 +#ENV PORT 3001 CMD ["node", "apps/landing/server.js"] \ No newline at end of file diff --git a/docker/Dockerfile.provider-proxy b/docker/Dockerfile.provider-proxy index 0dd70f192..b98c69f2e 100644 --- a/docker/Dockerfile.provider-proxy +++ b/docker/Dockerfile.provider-proxy @@ -1,4 +1,6 @@ -FROM node:20-alpine AS builder +FROM node:20-alpine AS base + +FROM base AS builder WORKDIR /app @@ -10,18 +12,17 @@ COPY package-lock.json /app RUN npm ci RUN npm run build --workspace apps/provider-proxy -FROM node:20-alpine +FROM base as runner WORKDIR /app +ENV NODE_ENV production + COPY --from=builder /app/package.json /app/package.json COPY --from=builder /app/package-lock.json /app/package-lock.json - COPY --from=builder /app/apps/provider-proxy/build /app/apps/provider-proxy/build COPY --from=builder /app/apps/provider-proxy/package.json /app/apps/provider-proxy/package.json RUN npm ci --workspace apps/provider-proxy --omit=dev -EXPOSE 80 - CMD ["node", "apps/provider-proxy/build/main.js"] \ No newline at end of file diff --git a/docker/Dockerfile.stats-web b/docker/Dockerfile.stats-web index ca1ae3706..daf7510ca 100644 --- a/docker/Dockerfile.stats-web +++ b/docker/Dockerfile.stats-web @@ -1,45 +1,37 @@ -FROM node:20 AS base +FROM node:20-alpine AS base -FROM base AS deps +ENV NEXT_TELEMETRY_DISABLED 1 + +FROM base AS development + +ENV NODE_ENV development WORKDIR /app +RUN apk add --no-cache libc6-compat + +COPY apps/stats-web ./apps/stats-web +COPY /packages /app/packages COPY package.json /app COPY package-lock.json /app -COPY apps/stats-web/package.json ./apps/stats-web/ -RUN apt-get update && apt-get install -y libc6-dev && \ - ARCH=$(uname -m) && \ - if [ "$ARCH" = "x86_64" ]; then \ - npm install @next/swc-linux-x64-gnu; \ - elif [ "$ARCH" = "aarch64" ]; then \ - npm install @next/swc-linux-arm64-gnu; \ - else \ - echo "Unsupported architecture"; exit 1; \ - fi +RUN npm install -RUN npm ci +CMD ["npm", "run", "dev", "--workspace", "apps/stats-web"] -FROM base AS builder +FROM development AS builder WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY --from=deps /app/apps/stats-web/node_modules ./apps/stats-web/node_modules -COPY . . - -ENV NEXT_TELEMETRY_DISABLED 1 +ENV NODE_ENV production RUN npm run build -w apps/stats-web -FROM node:20 AS runner +FROM base AS production + WORKDIR /app ENV NODE_ENV production -ENV NEXT_TELEMETRY_DISABLED 1 - -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs COPY --from=builder /app/package.json . COPY --from=builder /app/package-lock.json . @@ -47,16 +39,9 @@ COPY --from=builder /app/apps/stats-web/public ./apps/stats-web/public COPY --from=builder --chown=nextjs:nodejs /app/apps/stats-web/.next/standalone ./apps/stats-web COPY --from=builder --chown=nextjs:nodejs /app/apps/stats-web/.next/static ./apps/stats-web/.next/static -RUN apt-get update -RUN apt-get install libcap2-bin -y +RUN apk add --no-cache libcap RUN setcap cap_net_bind_service=+ep `readlink -f \`which node\`` RUN npm ci --workspace apps/stats-web --omit=dev -USER nextjs - -EXPOSE 3001 - -ENV PORT 3001 - CMD ["node", "apps/stats-web/server.js"] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 52a7e9c73..30c7a0d25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -603,7 +603,7 @@ "integrity": "sha512-ZhYeb6nRaXCfhnndflDK8qI6ZQ/YcWZCISRAWICW9XYqMUwjZM9Z0DveWX/ABN01oxSHwVxKQmxeYZSsm0jh5A==" }, "apps/landing": { - "name": "cloudmos-block-explorer", + "name": "console-landing", "version": "2.5.2", "license": "Apache-2.0", "dependencies": { @@ -19728,10 +19728,6 @@ "resolved": "apps/api", "link": true }, - "node_modules/cloudmos-block-explorer": { - "resolved": "apps/landing", - "link": true - }, "node_modules/cloudmos-indexer": { "resolved": "apps/indexer", "link": true @@ -20160,6 +20156,10 @@ "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz", "integrity": "sha512-ZMkYO/LkF17QvCPqM0gxw8yUzigAOZOSWSHg91FH6orS7vcEj5dVZTidN2fQ14yBSdg97RqhSNwLUXInd52OTA==" }, + "node_modules/console-landing": { + "resolved": "apps/landing", + "link": true + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", diff --git a/package.json b/package.json index 5b4394da7..2fea3a5ac 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,10 @@ "./apps/*" ], "scripts": { + "dc:build": "docker compose -f docker-compose.build.yml build", + "dc:down": "docker compose -p console down", + "dc:up:dev": "docker compose -p console -f docker-compose.build.yml -f docker-compose.prod.yml -f docker-compose.yml up", + "dc:up:prod": "docker compose -p console -f docker-compose.build.yml -f docker-compose.prod.yml up", "format": "prettier --write ./*.{js,json} **/*.{ts,tsx,js,json}", "lint": "eslint .", "lint:api": "eslint ./apps/api"