dethcrypto / eth-sdk

Type-safe, lightweight SDKs for Ethereum smart contracts
MIT License
432 stars 40 forks source link

Documentation about dockerization process #101

Closed Pzixel closed 2 years ago

Pzixel commented 2 years ago

Hi! I want to dockerize an app that uses eth-sdk but due to this magical process of placing generated types into node_modules I'm failing to do so.

What I'm doing is building a multistage image to prevent devDependencies getting into resulting image. Here is my Dockerfile:

FROM node:16.15.0-alpine3.15 AS base

FROM node:16.15.0-alpine3.15 AS build
WORKDIR /build
COPY ["package.json", "./"]
COPY ["yarn.lock", "./"]
RUN yarn install
COPY ["tsconfig.json", "./"]
COPY ./eth-sdk ./eth-sdk
COPY ./src ./src
RUN yarn eth-sdk
RUN yarn run build

FROM base AS final
WORKDIR /app
COPY ["package.json", "./"]
COPY ["yarn.lock", "./"]
COPY --from=build /build/node_modules/@dethcrypto ./node_modules/@dethcrypto
RUN yarn install --production
COPY --from=build /build/bin ./bin
ENTRYPOINT ["node", "bin"]

The problem here is it's failing with cryptic errors:

Error: Cannot find module '.dethcrypto/eth-sdk-client'
Require stack:
- /app/node_modules/@dethcrypto/eth-sdk-client/index.js
- /app/bin/utils.js
- /app/bin/index.js

I think some explanation about using eth-sdk in non-dev environment would be nice. I think I'm back to fat image with all development dependencies but I hope there is some solution for this

P.S. My package.json looks like this:

{
  "devDependencies": {
    "@dethcrypto/eth-sdk": "^0.3.1",
    "@types/node": "17.0.7",
    "@types/node-fetch": "2.6.1",
    "@typescript-eslint/eslint-plugin": "5.18.0",
    "@typescript-eslint/parser": "5.18.0",
    "eslint": "8.12.0",
    "eslint-plugin-typescript": "0.14.0",
    "ts-node": "^10.7.0",
    "typescript": "4.5.4"
  },
  "dependencies": {
    "@dethcrypto/eth-sdk-client": "^0.1.6",
    "ethers": "5.6.4",
  }
}
krzkaczor commented 2 years ago

@Pzixel the easiest way would be to to just generate SDK to a src dir instead and don't use @dethcrypto/eth-sdk-client. I am thinking about providing: https://github.com/dethcrypto/eth-sdk#outputpath

Another solution would be to copy all packages from the fat image: