From 81ab988519ad81e5e2007d283f4d3468fc489102 Mon Sep 17 00:00:00 2001 From: tate Date: Mon, 11 Jul 2022 10:16:44 +1000 Subject: [PATCH 1/2] add dockerfile + USE_LOCAL_WEB3 env var --- .dockerignore | 1 + Dockerfile | 16 ++++++++++++ src/service/network.ts | 57 +++++++++++++++++++++++------------------- 3 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..20daace --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:16-alpine +WORKDIR /usr/src/app + +RUN apk add pkgconfig cairo-dev pango-dev libjpeg giflib-dev librsvg-dev pixman-dev g++ make py3-pip + +COPY package.json yarn.lock tsconfig.json ./ +COPY ./src ./src + +RUN yarn install --verbose +RUN yarn build + +RUN yarn install --production +RUN apk del g++ make py3-pip + +EXPOSE 8080 +CMD ["yarn", "start"] diff --git a/src/service/network.ts b/src/service/network.ts index 8cde6c6..a20e68c 100644 --- a/src/service/network.ts +++ b/src/service/network.ts @@ -14,32 +14,37 @@ export default function getNetwork(network: string): any { // we will have namewrapper support and more attributes when latest subgraph goes to production let SUBGRAPH_URL: string; let CLOUDFLARE_WEB3_URL: string = 'https://web3metadata.ens.domains/v1'; - switch (network) { - case NETWORK.LOCAL: - SUBGRAPH_URL = 'http://127.0.0.1:8000/subgraphs/name/graphprotocol/ens'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; - break; - case NETWORK.RINKEBY: - SUBGRAPH_URL = - 'https://api.thegraph.com/subgraphs/name/makoto/ensrinkeby'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; - break; - case NETWORK.ROPSTEN: - SUBGRAPH_URL = - 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.ROPSTEN}`; - break; - case NETWORK.GOERLI: - SUBGRAPH_URL = - 'https://api.thegraph.com/subgraphs/name/ensdomains/ensgoerli'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.GOERLI}`; - break; - case NETWORK.MAINNET: - SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/ensdomains/ens'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.MAINNET}`; - break; - default: - throw new UnsupportedNetwork(`Unknown network '${network}'`, 400); + if (process.env.USE_LOCAL_WEB3) { + SUBGRAPH_URL = 'http://127.0.0.1:8000/subgraphs/name/graphprotocol/ens'; + CLOUDFLARE_WEB3_URL = 'http://127.0.0.1:8545'; + } else { + switch (network) { + case NETWORK.LOCAL: + SUBGRAPH_URL = 'http://127.0.0.1:8000/subgraphs/name/graphprotocol/ens'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; + break; + case NETWORK.RINKEBY: + SUBGRAPH_URL = + 'https://api.thegraph.com/subgraphs/name/makoto/ensrinkeby'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; + break; + case NETWORK.ROPSTEN: + SUBGRAPH_URL = + 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.ROPSTEN}`; + break; + case NETWORK.GOERLI: + SUBGRAPH_URL = + 'https://api.thegraph.com/subgraphs/name/ensdomains/ensgoerli'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.GOERLI}`; + break; + case NETWORK.MAINNET: + SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/ensdomains/ens'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.MAINNET}`; + break; + default: + throw new UnsupportedNetwork(`Unknown network '${network}'`, 400); + } } const provider = new ethers.providers.StaticJsonRpcProvider(CLOUDFLARE_WEB3_URL); return { CLOUDFLARE_WEB3_URL, SUBGRAPH_URL, provider }; From b78e7eb16e0bd07139c3862fcbacbad62bdd61cd Mon Sep 17 00:00:00 2001 From: tate Date: Tue, 12 Jul 2022 10:30:22 +1000 Subject: [PATCH 2/2] use individual rpc and subgraph URL env vars --- Dockerfile | 2 +- src/service/network.ts | 59 ++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20daace..cc24f2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN apk add pkgconfig cairo-dev pango-dev libjpeg giflib-dev librsvg-dev pixman- COPY package.json yarn.lock tsconfig.json ./ COPY ./src ./src -RUN yarn install --verbose +RUN yarn install RUN yarn build RUN yarn install --production diff --git a/src/service/network.ts b/src/service/network.ts index a20e68c..a9aba08 100644 --- a/src/service/network.ts +++ b/src/service/network.ts @@ -14,38 +14,35 @@ export default function getNetwork(network: string): any { // we will have namewrapper support and more attributes when latest subgraph goes to production let SUBGRAPH_URL: string; let CLOUDFLARE_WEB3_URL: string = 'https://web3metadata.ens.domains/v1'; - if (process.env.USE_LOCAL_WEB3) { - SUBGRAPH_URL = 'http://127.0.0.1:8000/subgraphs/name/graphprotocol/ens'; - CLOUDFLARE_WEB3_URL = 'http://127.0.0.1:8545'; - } else { - switch (network) { - case NETWORK.LOCAL: - SUBGRAPH_URL = 'http://127.0.0.1:8000/subgraphs/name/graphprotocol/ens'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; - break; - case NETWORK.RINKEBY: - SUBGRAPH_URL = - 'https://api.thegraph.com/subgraphs/name/makoto/ensrinkeby'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; - break; - case NETWORK.ROPSTEN: - SUBGRAPH_URL = - 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.ROPSTEN}`; - break; - case NETWORK.GOERLI: - SUBGRAPH_URL = - 'https://api.thegraph.com/subgraphs/name/ensdomains/ensgoerli'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.GOERLI}`; - break; - case NETWORK.MAINNET: - SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/ensdomains/ens'; - CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.MAINNET}`; - break; - default: - throw new UnsupportedNetwork(`Unknown network '${network}'`, 400); - } + switch (network) { + case NETWORK.LOCAL: + SUBGRAPH_URL = 'http://127.0.0.1:8000/subgraphs/name/graphprotocol/ens'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; + break; + case NETWORK.RINKEBY: + SUBGRAPH_URL = + 'https://api.thegraph.com/subgraphs/name/makoto/ensrinkeby'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.RINKEBY}`; + break; + case NETWORK.ROPSTEN: + SUBGRAPH_URL = + 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.ROPSTEN}`; + break; + case NETWORK.GOERLI: + SUBGRAPH_URL = + 'https://api.thegraph.com/subgraphs/name/ensdomains/ensgoerli'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.GOERLI}`; + break; + case NETWORK.MAINNET: + SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/ensdomains/ens'; + CLOUDFLARE_WEB3_URL = `${CLOUDFLARE_WEB3_URL}/${NETWORK.MAINNET}`; + break; + default: + throw new UnsupportedNetwork(`Unknown network '${network}'`, 400); } + process.env.RPC_PROVIDER && (CLOUDFLARE_WEB3_URL = process.env.RPC_PROVIDER); + process.env.SUBGRAPH_URL && (SUBGRAPH_URL = process.env.SUBGRAPH_URL); const provider = new ethers.providers.StaticJsonRpcProvider(CLOUDFLARE_WEB3_URL); return { CLOUDFLARE_WEB3_URL, SUBGRAPH_URL, provider }; }