From 485d8791fd7003f1bf7b65b9c7c6515c95511ebd Mon Sep 17 00:00:00 2001 From: Alexander Melnikov Date: Wed, 14 Aug 2024 12:51:52 +0200 Subject: [PATCH] feat: dockerize app with hyperchains configurable at runtime (#189) --- .github/workflows/release.yml | 27 +++++++++++++++++++++++++++ Dockerfile | 21 +++++++++++++++++++++ composables/usePortalRuntimeConfig.ts | 1 + data/networks.ts | 2 +- types/index.d.ts | 11 +++++++---- 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f7c5dd88..cb4250f0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,6 +39,33 @@ jobs: VITE_FIREBASE_PROJECT_ID=zksync-dapp-wallet-v2 \ npx semantic-release || true + docker: + name: Build Docker + runs-on: ubuntu-latest + needs: publish + if: ${{ github.ref == 'refs/heads/main' && needs.publish.outputs.releaseVersion != '' }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + push: true + tags: | + matterlabs/dapp-portal:latest + matterlabs/dapp-portal:${{ needs.publish.outputs.releaseVersion }} + file: Dockerfile + no-cache: true staging: name: Deploy to Staging diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a8131384 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:18.17.1-alpine AS base-stage + +WORKDIR /usr/src/app +COPY package*.json ./ + +FROM base-stage AS build-stage +RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/* +RUN npm cache clean --force && npm install +COPY . . +RUN npm run generate + +FROM base-stage AS production-stage +COPY --from=build-stage /usr/src/app/.output/public ./dist +RUN npm i -g http-server + +ARG PORT=3000 +ENV PORT=${PORT} + +WORKDIR /usr/src/app/dist + +CMD http-server -p $PORT -c-1 --proxy="http://127.0.0.1:$PORT/index.html?" diff --git a/composables/usePortalRuntimeConfig.ts b/composables/usePortalRuntimeConfig.ts index fdbb6cd1..8bde9129 100644 --- a/composables/usePortalRuntimeConfig.ts +++ b/composables/usePortalRuntimeConfig.ts @@ -15,5 +15,6 @@ export const usePortalRuntimeConfig = () => { } : undefined, }, + hyperchainsConfig: runtimeConfig?.hyperchainsConfig, }; }; diff --git a/data/networks.ts b/data/networks.ts index cf0fdb99..6a8bfd9d 100644 --- a/data/networks.ts +++ b/data/networks.ts @@ -103,7 +103,7 @@ const publicChains: ZkSyncNetwork[] = [ ]; const getHyperchains = (): ZkSyncNetwork[] => { - const hyperchains = Hyperchains as Config; + const hyperchains = portalRuntimeConfig.hyperchainsConfig || (Hyperchains as Config); return hyperchains.map((e) => { const network: ZkSyncNetwork = { ...e.network, diff --git a/types/index.d.ts b/types/index.d.ts index 879d03ae..2a49298a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,3 +1,5 @@ +import { type Config as HyperchainsConfig } from "@/scripts/hyperchains/common"; + export type Hash = `0x${string}`; export type TokenPrice = number | undefined; @@ -132,7 +134,7 @@ declare global { track: (eventName: string, params?: unknown) => void; initialized: boolean; }; - '##runtimeConfig'?: { + "##runtimeConfig"?: { nodeType?: string; walletConnectProjectId?: string; ankrToken?: string; @@ -141,8 +143,9 @@ declare global { rudder?: { key: string; dataplaneUrl: string; - } - } - } + }; + }; + hyperchainsConfig?: HyperchainsConfig; + }; } }