From be7adea81de8dbc95e9a2f3925d830232a2ea210 Mon Sep 17 00:00:00 2001 From: liviuancas-elrond Date: Fri, 25 Oct 2024 10:18:08 +0300 Subject: [PATCH 1/3] added dockerfile, placeholders and docker-compose example --- .gitignore | 2 ++ Dockerfile | 23 +++++++++++++++++++++++ docker-compose.yaml | 18 ++++++++++++++++++ entrypoint.sh | 38 ++++++++++++++++++++++++++++++++++++++ package.json | 3 +++ 5 files changed, 84 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 entrypoint.sh diff --git a/.gitignore b/.gitignore index 0559480b6..c02a0643d 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ dist-ssr /src/config/* !/src/config/helpers !/src/config.devnet.ts +!/src/config.placeholder.ts !/src/config.devnet-old.ts !/src/config.testnet.ts !/src/config.mainnet.ts @@ -58,6 +59,7 @@ dist-ssr *.sh !prepare-free-icons.sh !prepare-pro-icons.sh +!entrypoint.sh # Editor directories and files .vscode/* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..76d948cfb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use the official Node.js image +FROM node:18 AS build + +# Set the working directory +WORKDIR /app + +COPY . . + +# Install dependencies +RUN yarn install +RUN yarn copy-placeholder-config & yarn build + +# Production image +FROM nginx:alpine + +# Copy the build files to the Nginx HTML directory +COPY --from=build /app/build /usr/share/nginx/html +COPY ./entrypoint.sh . +RUN chmod +x entrypoint.sh + +# Expose port 80 +EXPOSE 80 +CMD ["./entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..5caac62ac --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,18 @@ +version: "3.9" + +services: + test: + ports: + - 127.0.0.1:80:80 + container_name: explorer + build: + context: . + dockerfile: Dockerfile + environment: + START_NAME_STOP: testnet + START_CHAIN_ID_STOP: D + START_EGLD_LABEL_STOP: xEGLD + START_WALLET_ADDRESS_STOP: https://testnet-wallet.multiversx.com + START_EXPLORER_ADDRESS_STOP: https://testnet-explorer.multiversx.com + START_NFT_EXPLORER_ADDRESS_STOP: https://testnet.xspotlight.com + START_API_ADDRESS_STOP: https://testnet-api.multiversx.com diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 000000000..0533ff762 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Replaces envs if defined +if [ -n "$START_NAME_STOP" ]; then + echo "Name defined: ${START_NAME_STOP}, replacing in config" + find /usr/share/nginx/html/ -type f -exec sed -i 's|START_NAME_STOP|'${START_NAME_STOP}'|g' {} + +fi + +if [ -n "$START_CHAIN_ID_STOP" ]; then + echo "Chain ID defined: ${START_CHAIN_ID_STOP}, replacing in config" + find /usr/share/nginx/html/ -type f -exec sed -i 's|START_CHAIN_ID_STOP|'${START_CHAIN_ID_STOP}'|g' {} + +fi + +if [ -n "$START_EGLD_LABEL_STOP" ]; then + echo "egldLabel defined: ${START_EGLD_LABEL_STOP}, replacing in config" + find /usr/share/nginx/html/ -type f -exec sed -i 's|START_EGLD_LABEL_STOP|'${START_EGLD_LABEL_STOP}'|g' {} + +fi + +if [ -n "$START_WALLET_ADDRESS_STOP" ]; then + echo "WalletAdress defined: ${START_WALLET_ADDRESS_STOP}, replacing in config" + find /usr/share/nginx/html/ -type f -exec sed -i 's|START_WALLET_ADDRESS_STOP|'${START_WALLET_ADDRESS_STOP}'|g' {} + +fi + +if [ -n "$START_EXPLORER_ADDRESS_STOP" ]; then + echo "Explorer address defined: ${START_EXPLORER_ADDRESS_STOP}, replacing in config" + find /usr/share/nginx/html/ -type f -exec sed -i 's|START_EXPLORER_ADDRESS_STOP|'${START_EXPLORER_ADDRESS_STOP}'|g' {} + +fi + +if [ -n "$START_NFT_EXPLORER_ADDRESS_STOP" ]; then + echo "NFT Explorer address defined: ${START_NFT_EXPLORER_ADDRESS_STOP}, replacing in config" + find /usr/share/nginx/html/ -type f -exec sed -i 's|START_NFT_EXPLORER_ADDRESS_STOP|'${START_NFT_EXPLORER_ADDRESS_STOP}'|g' {} + +fi + +if [ -n "$START_API_ADDRESS_STOP" ]; then + echo "API address defined: ${START_API_ADDRESS_STOP}, replacing in config" + find /usr/share/nginx/html/ -type f -exec sed -i 's|START_API_ADDRESS_STOP|'${START_API_ADDRESS_STOP}'|g' {} + +fi + +exec nginx -g 'daemon off;' diff --git a/package.json b/package.json index 922722e86..5d903f021 100644 --- a/package.json +++ b/package.json @@ -62,16 +62,19 @@ "build": "cross-env VITE_APP_CACHE_BUST=$(git rev-parse --short HEAD || echo 'local') vite build && yarn version:make", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", + "copy-placeholder-config": "run-script-os", "copy-devnet-config": "run-script-os", "copy-mainnet-config": "run-script-os", "copy-testnet-config": "run-script-os", "copy-multiple-config": "run-script-os", "copy-base-interceptor": "run-script-os", + "copy-placeholder-config:nix": "cp ./src/config/config.placeholder.ts ./src/config/index.ts", "copy-devnet-config:nix": "cp ./src/config/config.devnet.ts ./src/config/index.ts", "copy-mainnet-config:nix": "cp ./src/config/config.mainnet.ts ./src/config/index.ts", "copy-testnet-config:nix": "cp ./src/config/config.testnet.ts ./src/config/index.ts", "copy-multiple-config:nix": "cp ./src/config/config.multiple.ts ./src/config/index.ts", "copy-base-interceptor:nix": "cp ./src/interceptors/Interceptor.tsx ./src/interceptors/index.tsx", + "copy-placeholder-config:windows": "copy .\\src\\config\\config.placeholder.ts .\\src\\config\\index.ts", "copy-devnet-config:windows": "copy .\\src\\config\\config.devnet.ts .\\src\\config\\index.ts", "copy-mainnet-config:windows": "copy .\\src\\config\\config.mainnet.ts .\\src\\config\\index.ts", "copy-testnet-config:windows": "copy .\\src\\config\\config.testnet.ts .\\src\\config\\index.ts", From 3af6caa7a0a882fcdd9d45b1231b9dbcf9773018 Mon Sep 17 00:00:00 2001 From: liviuancas-elrond Date: Fri, 25 Oct 2024 10:37:04 +0300 Subject: [PATCH 2/3] added dockerfile, placeholders and docker-compose example --- .github/workflows/build-docker-image.yaml | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/build-docker-image.yaml diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/build-docker-image.yaml new file mode 100644 index 000000000..882f950a4 --- /dev/null +++ b/.github/workflows/build-docker-image.yaml @@ -0,0 +1,43 @@ +name: Publish Docker image + +on: + workflow_dispatch: + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' # Specify your Node.js version + + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: multiversx/mx-explorer-dapp + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file From 0436ed5b7fa29c339809f118a8d573676d94c673 Mon Sep 17 00:00:00 2001 From: Liviu Ancas <83750585+liviuf-ancas@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:07:23 +0300 Subject: [PATCH 3/3] Create config.placeholder.ts --- src/config/config.placeholder.ts | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/config/config.placeholder.ts diff --git a/src/config/config.placeholder.ts b/src/config/config.placeholder.ts new file mode 100644 index 000000000..868a610eb --- /dev/null +++ b/src/config/config.placeholder.ts @@ -0,0 +1,51 @@ +import { NetworkType } from 'types/network.types'; + +import { getStorageCustomNetworks } from './helpers'; +import { allApps, schema } from './sharedConfig'; +export * from './sharedConfig'; + +export const hasExtraNetworks = false; +export const links: NetworkUrlType[] = []; +export const networks: NetworkType[] = [ + { + default: true, + id: 'START_NAME_STOP', + name: 'START_NAME_STOP', + chainId: 'START_CHAIN_ID_STOP', + adapter: 'api', + theme: 'testnet', + egldLabel: 'START_EGLD_LABEL_STOP', + walletAddress: 'START_WALLET_ADDRESS_STOP', + explorerAddress: 'START_EXPLORER_ADDRESS_STOP', + nftExplorerAddress: 'START_NFT_EXPLORER_ADDRESS_STOP', + apiAddress: 'START_API_ADDRESS_STOP' + }, + + // Saved Custom Network Configs + ...getStorageCustomNetworks() +]; + +export const multiversxApps = allApps([ + { + id: 'wallet', + url: 'START_WALLET_ADDRESS_STOP' + }, + { + id: 'explorer', + url: 'START_EXPLORER_ADDRESS_STOP' + }, + { + id: 'xexchange', + url: 'https://devnet.xexchange.com' + }, + { + id: 'xspotlight', + url: 'START_NFT_EXPLORER_ADDRESS_STOP' + } +]); + +networks.forEach((network) => { + schema.validate(network, { strict: true }).catch(({ errors }) => { + console.error(`Config invalid format for ${network.id}`, errors); + }); +});