diff --git a/README.md b/README.md index 0106eaff3d..9febbccef0 100644 --- a/README.md +++ b/README.md @@ -71,10 +71,20 @@ For `production` mode run: $ npm run build $ npm run start ``` -To verify front-end `App` is running open http://localhost:3010 in your browser. `API` should be available at http://localhost:3000. `Worker` - http://localhost:3001. Each component can also be started individually. Follow individual packages `README` for details. +## 🐳 Running in Docker +There is a docker compose configuration that allows you to run Block Explorer and all its dependencies in docker. Just run the following command to spin up the whole environment: +``` +docker-compose up +``` +It will run local Ethereum node, ZkSync Era, Postgres DB and all Block Explorer services. + +## 🔍 Verify Block Explorer is up and running + +To verify front-end `App` is running open http://localhost:3010 in your browser. `API` should be available at http://localhost:3000. `Worker` - http://localhost:3001. + ## 🕵️‍♂️ Testing Run unit tests for all packages: ```bash diff --git a/packages/worker/docker-compose.yaml b/docker-compose.yaml similarity index 55% rename from packages/worker/docker-compose.yaml rename to docker-compose.yaml index e229f2bd50..ad31a1fe02 100644 --- a/packages/worker/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,10 +1,22 @@ name: block-explorer services: + app: + build: + context: . + dockerfile: ./packages/app/Dockerfile + command: npm run --prefix packages/app dev -- --host + ports: + - '3010:3010' + depends_on: + - api + restart: unless-stopped + worker: build: context: . + dockerfile: ./packages/worker/Dockerfile target: development-stage - command: npm run dev:debug + command: npm run --prefix packages/worker dev:debug environment: - PORT=3001 - LOG_LEVEL=verbose @@ -19,15 +31,45 @@ services: - '9229:9229' - '9230:9230' volumes: - - ./:/usr/src/app - - /usr/src/app/node_modules + - ./packages/worker:/usr/src/app/packages/worker + - /usr/src/app/packages/worker/node_modules + - ./node_modules:/usr/src/worker/node_modules:ro depends_on: zksync: condition: service_healthy restart: unless-stopped + api: + build: + context: . + dockerfile: ./packages/api/Dockerfile + target: development-stage + command: npm run --prefix packages/api dev:debug + environment: + - PORT=3000 + - METRICS_PORT=3005 + - LOG_LEVEL=verbose + - NODE_ENV=development + - DATABASE_URL=postgres://postgres:postgres@postgres:5432/block-explorer + ports: + - '3000:3000' + - '3005:3005' + - '9231:9229' + - '9232:9230' + volumes: + - ./packages/api:/usr/src/app/packages/api + - /usr/src/app/packages/api/node_modules + - ./node_modules:/usr/src/api/node_modules:ro + depends_on: + - worker + restart: unless-stopped + postgres: - image: "postgres" + image: "postgres:14" + logging: + driver: none + volumes: + - postgres:/var/lib/postgresql/data ports: - "5432:5432" healthcheck: @@ -48,7 +90,7 @@ services: - "8545:8545" - "8546:8546" volumes: - - ./volumes/geth:/var/lib/geth/data + - geth:/var/lib/geth/data zksync: stdin_open: true @@ -64,9 +106,9 @@ services: - "3051:3051" # JSON RPC WS port volumes: # Configs folder bind - - ./volumes/zksync/env/dev:/etc/env/dev + - zksync-config:/etc/env/ # Storage folder bind - - ./volumes/zksync/data:/var/lib/zksync/data + - zksync-data:/var/lib/zksync/data environment: - DATABASE_URL=postgres://postgres:postgres@postgres:5432/zksync_local - ETH_CLIENT_WEB3_URL=http://geth:8545 @@ -76,3 +118,9 @@ services: timeout: 5s retries: 120 restart: unless-stopped + +volumes: + geth: + postgres: + zksync-config: + zksync-data: \ No newline at end of file diff --git a/packages/api/README.md b/packages/api/README.md index 6ea67881ab..66db5232fa 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -86,7 +86,4 @@ To output performance results to a file use next command: artillery run ./performance/load-test.yaml -e testnet -o ./performance/29-06/testnet.json ``` -for more command options check [official artillery docs](https://www.artillery.io/docs). - -### Conventional Commits -We follow the Conventional Commits [specification](https://www.conventionalcommits.org/en/v1.0.0/#specification). \ No newline at end of file +for more command options check [official artillery docs](https://www.artillery.io/docs). \ No newline at end of file diff --git a/packages/api/docker-compose.yaml b/packages/api/docker-compose.yaml deleted file mode 100644 index 526ede2ade..0000000000 --- a/packages/api/docker-compose.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: block-explorer -services: - api: - build: - context: . - target: development-stage - command: npm run dev:debug - environment: - - PORT=3000 - - METRICS_PORT=3005 - - LOG_LEVEL=verbose - - NODE_ENV=development - - DATABASE_URL='postgres://postgres:postgres@localhost:5432/block-explorer' - ports: - - '3000:3000' - - '3005:3005' - - '9231:9229' - - '9232:9230' - volumes: - - ./:/usr/src/app - - /usr/src/app/node_modules - depends_on: - postgres: - condition: service_healthy - - postgres: - image: "postgres" - ports: - - "5432:5432" - healthcheck: - test: [ "CMD-SHELL", "pg_isready -U postgres" ] - interval: 5s - timeout: 5s - retries: 5 - environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres - - POSTGRES_DB=block-explorer diff --git a/packages/app/Dockerfile b/packages/app/Dockerfile new file mode 100644 index 0000000000..aca6217127 --- /dev/null +++ b/packages/app/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18.17.1-alpine +ENV NODE_ENV=development + +WORKDIR /usr/src/app +RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/* + +COPY --chown=node:node .npmrc .npmrc +COPY --chown=node:node lerna.json ./ +COPY --chown=node:node package*.json ./ +COPY --chown=node:node ./packages/app/package*.json ./packages/app/ +RUN npm ci +COPY --chown=node:node ./packages/app/. ./packages/app \ No newline at end of file diff --git a/packages/worker/README.md b/packages/worker/README.md index d64f8ce0b9..4cb914fd45 100644 --- a/packages/worker/README.md +++ b/packages/worker/README.md @@ -41,13 +41,6 @@ $ npm run dev:debug $ npm run start ``` -## Running the app in Docker -There is a docker compose configuration that allows you to run Block Explorer Worker and all its dependencies in docker. Just run the following command to spin up the whole environment: -``` -docker-compose up -``` -It will run local Ethereum node, ZkSync Era, Postgres DB and Block Explorer Worker. - ## Test ```bash @@ -90,7 +83,4 @@ Example: npm run migration:create -name=UpdateTxsFee ``` -this command will simply create an empty migration where the custom migration logic can be added. - -### Conventional Commits -We follow the Conventional Commits [specification](https://www.conventionalcommits.org/en/v1.0.0/#specification). +this command will simply create an empty migration where the custom migration logic can be added. \ No newline at end of file