diff --git a/.github/workflows/docker_build_push.yml b/.github/workflows/docker_build_push.yml index 944e9e6..7a10933 100644 --- a/.github/workflows/docker_build_push.yml +++ b/.github/workflows/docker_build_push.yml @@ -3,7 +3,6 @@ name: Docker_build_push on: release: types: [created] - workflow_dispatch: env: REGISTRY: ghcr.io @@ -12,46 +11,58 @@ env: jobs: docker: name: Build and push docker image to GitHub Container Registry + strategy: + matrix: + environment: [devnet-1] runs-on: ubuntu-latest-16-core + environment: ${{ matrix.environment }} + outputs: + tags: ${{ steps.meta.outputs.tags }} steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v4 - with: - short-length: 7 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=raw,value=test,enable={{is_default_branch}} - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - - name: Push to GitHub Container Registry - uses: docker/build-push-action@v3 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: | - type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }} - type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-main-${{ github.workflow }} - cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }},mode=max + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Inject slug/short variables + uses: rlespinasse/github-slug-action@v4 + with: + short-length: 7 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}},suffix=${{ format('-{0}', matrix.environment) }} + type=semver,pattern={{major}}.{{minor}},suffix=${{ format('-{0}', matrix.environment) }} + + - name: Push to GitHub Container Registry + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VITE_EXECUTOR_SERVICE_ENDPOINT=${{ vars.VITE_EXECUTOR_SERVICE_ENDPOINT }} + VITE_SUBNET_REGISTRATOR_CONTRACT_ADDRESS=${{ vars.VITE_SUBNET_REGISTRATOR_CONTRACT_ADDRESS }} + VITE_ERC20_MESSAGING_CONTRACT_ADDRESS=${{ vars.VITE_ERC20_MESSAGING_CONTRACT_ADDRESS }} + VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS=${{ vars.VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS }} + VITE_TOPOS_SUBNET_ENDPOINT=${{ vars.VITE_TOPOS_SUBNET_ENDPOINT }} + VITE_TRACING_OTEL_COLLECTOR_ENDPOINT=${{ vars.VITE_TRACING_OTEL_COLLECTOR_ENDPOINT }} + VITE_TRACING_SERVICE_NAME=${{ vars.VITE_TRACING_SERVICE_NAME }} + VITE_TRACING_SERVICE_VERSION=${{ vars.VITE_TRACING_SERVICE_VERSION }} + cache-from: | + type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }} + type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-main-${{ github.workflow }} + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:build-cache-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.workflow }},mode=max diff --git a/Dockerfile b/Dockerfile index 0f8387c..d57000b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,14 @@ FROM node:lts-alpine +ARG VITE_EXECUTOR_SERVICE_ENDPOINT +ARG VITE_SUBNET_REGISTRATOR_CONTRACT_ADDRESS +ARG VITE_ERC20_MESSAGING_CONTRACT_ADDRESS +ARG VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS +ARG VITE_TOPOS_SUBNET_ENDPOINT +ARG VITE_TRACING_OTEL_COLLECTOR_ENDPOINT +ARG VITE_TRACING_SERVICE_NAME +ARG VITE_TRACING_SERVICE_VERSION + WORKDIR /usr/src/app COPY package*.json ./ @@ -13,6 +22,4 @@ COPY . ./ RUN npm run frontend:build -RUN npm run backend:build - -CMD npm run backend:start:prod +CMD npm run backend:build && npm run backend:start:prod diff --git a/packages/frontend/src/App.tsx b/packages/frontend/src/App.tsx index 3d9cb34..f744ea2 100644 --- a/packages/frontend/src/App.tsx +++ b/packages/frontend/src/App.tsx @@ -12,6 +12,7 @@ import 'antd/dist/reset.css' import useRegisteredSubnets from './hooks/useRegisteredSubnets' import { toposCoreContract } from './contracts' import { SubnetWithId } from './types' +import { sanitizeURLProtocol } from './utils' const { Content: _Content } = _Layout @@ -43,7 +44,7 @@ const App = () => { if (toposSubnetEndpoint) { const provider = new ethers.providers.JsonRpcProvider( - `http://${toposSubnetEndpoint}` + sanitizeURLProtocol('http', toposSubnetEndpoint) ) const network = await provider.getNetwork() const chainId = network.chainId diff --git a/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts b/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts index e52d18b..b60c26d 100644 --- a/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts +++ b/packages/frontend/src/hooks/useCheckTokenOnReceivingSubnet.ts @@ -5,6 +5,7 @@ import { ErrorsContext } from '../contexts/errors' import { SubnetsContext } from '../contexts/subnets' import { erc20MessagingContract } from '../contracts' import { Token } from '../types' +import { sanitizeURLProtocol } from '../utils' export default function useCheckTokenOnSubnet() { const { setErrors } = React.useContext(ErrorsContext) @@ -20,7 +21,7 @@ export default function useCheckTokenOnSubnet() { const subnetProvider = subnet?.endpoint ? new ethers.providers.WebSocketProvider( - `ws://${subnet?.endpoint}/ws` + sanitizeURLProtocol('ws', `${subnet?.endpoint}/ws`) ) : null diff --git a/packages/frontend/src/hooks/useEthers.ts b/packages/frontend/src/hooks/useEthers.ts index 4e79d54..609b301 100644 --- a/packages/frontend/src/hooks/useEthers.ts +++ b/packages/frontend/src/hooks/useEthers.ts @@ -3,6 +3,7 @@ import React from 'react' import { useMetaMask } from 'metamask-react' import { Subnet } from '../types' +import { sanitizeURLProtocol } from '../utils' interface Args { subnet?: Subnet @@ -20,9 +21,12 @@ export default function useEthers({ subnet, viaMetaMask }: Args = {}) { viaMetaMask && ethereum ? new ethers.providers.Web3Provider(ethereum) : new ethers.providers.WebSocketProvider( - `ws://${ - subnet?.endpoint || import.meta.env.VITE_TOPOS_SUBNET_ENDPOINT - }/ws` + sanitizeURLProtocol( + 'ws', + `${ + subnet?.endpoint || import.meta.env.VITE_TOPOS_SUBNET_ENDPOINT + }/ws` + ) ), [subnet, viaMetaMask, ethereum] ) @@ -49,7 +53,7 @@ export default function useEthers({ subnet, viaMetaMask }: Args = {}) { symbol: subnet.currencySymbol, decimals: 18, }, - rpcUrls: [`http://${subnet.endpoint}`], + rpcUrls: [sanitizeURLProtocol('http', subnet.endpoint)], }) } } diff --git a/packages/frontend/src/utils/index.ts b/packages/frontend/src/utils/index.ts index 115fd91..fbd9937 100644 --- a/packages/frontend/src/utils/index.ts +++ b/packages/frontend/src/utils/index.ts @@ -38,3 +38,9 @@ export function getRawTransaction(tx: Transaction) { return raw } + +export function sanitizeURLProtocol(protocol: 'ws' | 'http', endpoint: string) { + return location.protocol.startsWith('https') + ? `${protocol}s://${endpoint}` + : `${protocol}://${endpoint}` +}