Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
ci: use multi-environment docker build (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan authored Aug 14, 2023
1 parent a73811e commit f0b6997
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 51 deletions.
95 changes: 53 additions & 42 deletions .github/workflows/docker_build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Docker_build_push
on:
release:
types: [created]
workflow_dispatch:

env:
REGISTRY: ghcr.io
Expand All @@ -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
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 ./
Expand All @@ -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
3 changes: 2 additions & 1 deletion packages/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
12 changes: 8 additions & 4 deletions packages/frontend/src/hooks/useEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
)
Expand All @@ -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)],
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}

0 comments on commit f0b6997

Please sign in to comment.