From 681a16f5c103149a85d3e3174afd8b39da6dde2d Mon Sep 17 00:00:00 2001 From: zengzengzenghuy Date: Fri, 20 Sep 2024 11:30:54 +0800 Subject: [PATCH] refactor(reporter,relayer,executor): dockerfile and docker-compose.yml for better monorepo support --- Dockerfile.executor | 30 ------------------------------ Dockerfile.relayer | 30 ------------------------------ docker-compose.yml | 31 ++++++++++++++++--------------- packages/executor/Dockerfile | 23 +++++++++++++++++++++++ packages/relayer/Dockerfile | 23 +++++++++++++++++++++++ packages/reporter/Dockerfile | 2 +- 6 files changed, 63 insertions(+), 76 deletions(-) delete mode 100644 Dockerfile.executor delete mode 100644 Dockerfile.relayer create mode 100644 packages/executor/Dockerfile create mode 100644 packages/relayer/Dockerfile diff --git a/Dockerfile.executor b/Dockerfile.executor deleted file mode 100644 index c3404b9f..00000000 --- a/Dockerfile.executor +++ /dev/null @@ -1,30 +0,0 @@ -FROM node:18-alpine - -WORKDIR /usr/src/app -COPY package.json yarn.lock ./ - -COPY packages/common/package.json ./packages/common/ -COPY packages/executor/package.json ./packages/executor/ - -RUN yarn install --ignore-scripts - -WORKDIR /usr/src/app/packages/common -RUN yarn install --ignore-scripts - -WORKDIR /usr/src/app/packages/executor -RUN yarn install --ignore-scripts - -WORKDIR /usr/src/app - -COPY packages/common/ ./packages/common/ -COPY packages/executor/ ./packages/executor/ - -WORKDIR /usr/src/app/packages/common -RUN yarn compile - - - -WORKDIR /usr/src/app/packages/executor -RUN yarn compile - -CMD ["yarn", "start"] \ No newline at end of file diff --git a/Dockerfile.relayer b/Dockerfile.relayer deleted file mode 100644 index f2d4479a..00000000 --- a/Dockerfile.relayer +++ /dev/null @@ -1,30 +0,0 @@ -FROM node:18-alpine - -WORKDIR /usr/src/app -COPY package.json yarn.lock ./ - -COPY packages/common/package.json ./packages/common/ -COPY packages/relayer/package.json ./packages/relayer/ - -RUN yarn install --ignore-scripts - -WORKDIR /usr/src/app/packages/common -RUN yarn install --ignore-scripts - -WORKDIR /usr/src/app/packages/relayer -RUN yarn install --ignore-scripts - -WORKDIR /usr/src/app - -COPY packages/common/ ./packages/common/ -COPY packages/relayer/ ./packages/relayer/ - -WORKDIR /usr/src/app/packages/common -RUN yarn compile - - - -WORKDIR /usr/src/app/packages/relayer -RUN yarn compile - -CMD ["yarn", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 80025ddb..f19e6bdb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,38 +2,39 @@ version: "3.8" services: mongodb: - image: mongo:latest - container_name: mongodb - ports: - - "27017:27017" - networks: - - mongo-network - volumes: - - mongo-data:/data/db + image: mongo:latest + container_name: mongodb + ports: + - "27017:27017" + networks: + - mongo-network + volumes: + - mongo-data:/data/db - executor: + relayer: build: context: . - dockerfile: Dockerfile.executor - container_name: executor + dockerfile: packages/relayer/Dockerfile + container_name: relayer networks: - mongo-network depends_on: - mongodb - relayer: + executor: build: context: . - dockerfile: Dockerfile.relayer - container_name: hashi-relayer + dockerfile: packages/executor/Dockerfile + container_name: executor networks: - mongo-network depends_on: - mongodb + networks: mongo-network: driver: bridge volumes: mongo-data: - driver: local + driver: local \ No newline at end of file diff --git a/packages/executor/Dockerfile b/packages/executor/Dockerfile new file mode 100644 index 00000000..9c01c83b --- /dev/null +++ b/packages/executor/Dockerfile @@ -0,0 +1,23 @@ +FROM node:18-alpine + +WORKDIR /usr/src/app + +# Copy root package.json and yarn.lock for dependency resolution +COPY ../../package.json ../../yarn.lock ./ + +# Copy both executor and common package folders +COPY ./packages/common ./packages/common +COPY ./packages/executor ./packages/executor + + +# Install dependencies at root level +RUN yarn install + +# Compile both common and executor packages +WORKDIR /usr/src/app/packages/common +RUN yarn compile + +WORKDIR /usr/src/app/packages/executor +RUN yarn compile + +CMD ["yarn", "start"] \ No newline at end of file diff --git a/packages/relayer/Dockerfile b/packages/relayer/Dockerfile new file mode 100644 index 00000000..aec8ea25 --- /dev/null +++ b/packages/relayer/Dockerfile @@ -0,0 +1,23 @@ +FROM node:18-alpine + +WORKDIR /usr/src/app + +# Copy root package.json and yarn.lock for dependency resolution +COPY ../../package.json ../../yarn.lock ./ + +# Copy both executor and common package folders +COPY ./packages/common ./packages/common +COPY ./packages/relayer ./packages/relayer + + +# Install dependencies at root level +RUN yarn install + +# Compile both common and executor packages +WORKDIR /usr/src/app/packages/common +RUN yarn compile + +WORKDIR /usr/src/app/packages/relayer +RUN yarn compile + +CMD ["yarn", "start"] \ No newline at end of file diff --git a/packages/reporter/Dockerfile b/packages/reporter/Dockerfile index b251100d..035d9c21 100644 --- a/packages/reporter/Dockerfile +++ b/packages/reporter/Dockerfile @@ -2,7 +2,7 @@ FROM node:18-alpine WORKDIR /usr/src/app -COPY package.json yarn.lock .env ./ +COPY package.json .env ./ RUN corepack enable && \ corepack prepare --activate yarn@3.2.2 && \