From b257aa95f636e82e41a4ee9bfa16d530e9419783 Mon Sep 17 00:00:00 2001 From: harsh-98 Date: Tue, 24 Dec 2024 22:47:03 +0700 Subject: [PATCH] feat: add docker --- .github/workflows/release.yml | 33 ++++++++++++++++++++++++++++ .releaserc.json | 35 ++++++++++++++++++++++++++++++ Dockerfile | 34 +++++++++++++++++++++++++++++ esbuild.config.mjs | 26 ++++++++++++++++++++++ package.json | 5 ++++- src/apy/curveAPY.ts | 41 +++++++++++++++++++---------------- 6 files changed, 154 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .releaserc.json create mode 100644 Dockerfile create mode 100644 esbuild.config.mjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..cba48d9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Release + +on: + push: + branches: + - "main" + workflow_dispatch: + +env: + HUSKY: 0 + CI: true + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v4 + with: + extra_plugins: | + @codedependant/semantic-release-docker + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..a797d65 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,35 @@ +{ + "branches": [ + { + "name": "main" + } + ], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/github", + { + "successComment": false, + "failTitle": false + } + ], + [ + "@codedependant/semantic-release-docker", + { + "dockerTags": [ + "{{#if prerelease.[0]}}{{prerelease.[0]}}{{else}}latest{{/if}}", + "{{version}}" + ], + "dockerArgs": { + "PACKAGE_VERSION": "{{version}}" + }, + "dockerImage": "apy-server", + "dockerRegistry": "ghcr.io", + "dockerProject": "gearbox-protocol", + "dockerBuildQuiet": false, + "dockerLogin": false + } + ] + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ad74a63 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM node:20.14 as dev + +ENV YARN_CACHE_FOLDER=/root/.yarn + +WORKDIR /app + +COPY . . + +RUN --mount=type=cache,id=yarn,target=/root/.yarn \ + yarn install --frozen-lockfile --ignore-engines \ + && yarn build + +# Production npm modules + +FROM node:20.14 as prod + +ENV YARN_CACHE_FOLDER=/root/.yarn + +WORKDIR /app + +COPY --from=dev /app/package.json /app +COPY --from=dev /app/build/ /app/build + +RUN --mount=type=cache,id=yarn,target=/root/.yarn \ + yarn install --production --frozen-lockfile --ignore-engines + + +# Final image + +FROM gcr.io/distroless/nodejs20-debian12 + +WORKDIR /app +COPY --from=dev /app /app +CMD ["--enable-source-maps", "/app/build/main.mjs"] diff --git a/esbuild.config.mjs b/esbuild.config.mjs new file mode 100644 index 0000000..2362df7 --- /dev/null +++ b/esbuild.config.mjs @@ -0,0 +1,26 @@ +import { build } from "esbuild"; + +build({ + entryPoints: ["main.ts"], + outdir: "build", + bundle: true, + platform: "node", + format: "esm", + outExtension: { ".js": ".mjs" }, + target: ["node20"], + sourcemap: "external", + banner: { + js: ` + import { createRequire } from 'module'; + import { fileURLToPath } from 'url'; + + const require = createRequire(import.meta.url); + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + `, + }, + external: ["node-pty"], +}).catch(e => { + console.error(e); + process.exit(1); +}); diff --git a/package.json b/package.json index 114c9a7..971ca37 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "Gearbox SDK", "main": "index.js", "license": "MIT", + "scripts": { + "build": "node esbuild.config.mjs" + }, "dependencies": { "axios": "^1.7.9", "cors": "^2.8.5", @@ -18,4 +21,4 @@ "@types/cors": "^2.8.17", "@types/express": "^5.0.0" } -} +} \ No newline at end of file diff --git a/src/apy/curveAPY.ts b/src/apy/curveAPY.ts index 07afa0f..d17de94 100644 --- a/src/apy/curveAPY.ts +++ b/src/apy/curveAPY.ts @@ -165,11 +165,13 @@ export async function getCurveAPY(network: NetworkType, store: TokenStore): Prom reward: pool.lpTokenAddress, symbol: curveSymbol, value: curveAPYToBn(baseAPY), - }, { - reward: crv.address, - symbol: crv.symbol, - value: curveAPYToBn(maxCrv), - }, ...extraRewards]; + }, + // { + // reward: crv.address, + // symbol: crv.symbol, + // value: curveAPYToBn(maxCrv), + // }, ...extraRewards, + ]; acc[pool.lpTokenAddress] = getTokenAPY(curveSymbol, curveAPYs); return acc; }, @@ -199,20 +201,21 @@ export async function getCurveAPY(network: NetworkType, store: TokenStore): Prom symbol: gearPool.symbol, value: curveAPYToBn(gearVolume?.latestDailyApyPcent || 0), }, - { - reward: crv.address, - symbol: crv.symbol, - value: curveAPYToBn(Math.max(...(gearPool?.gaugeCrvApy || []), 0)), - }, - ...(gearPool?.gaugeRewards || []).map( - ({ apy = 0, symbol, tokenAddress }): ApyDetails => { - return { - reward: tokenAddress, - symbol: symbol, - value: curveAPYToBn(apy), - } - } - )]; + // { + // reward: crv.address, + // symbol: crv.symbol, + // value: curveAPYToBn(Math.max(...(gearPool?.gaugeCrvApy || []), 0)), + // }, + // ...(gearPool?.gaugeRewards || []).map( + // ({ apy = 0, symbol, tokenAddress }): ApyDetails => { + // return { + // reward: tokenAddress, + // symbol: symbol, + // value: curveAPYToBn(apy), + // } + // } + // ), + ]; curveAPY[GEAR_POOL as Address] = getTokenAPY(gearPool.symbol, gearAPY);