Skip to content

Commit

Permalink
Merge branch 'main' into fe-make-l1blockexplorer-config-not-required
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyl-ivanchuk committed Oct 16, 2023
2 parents c6bf554 + 8f42c78 commit 4ed8cef
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ jobs:
file: packages/worker/Dockerfile
no-cache: true

- name: Build and push Docker image for App
uses: docker/build-push-action@v4
with:
push: true
tags: |
"matterlabs/block-explorer-app:latest"
"matterlabs/block-explorer-app:v${{ needs.createReleaseVersion.outputs.releaseVersion }}"
"matterlabs/block-explorer-app:${{ steps.setVersionForFlux.outputs.imageTag }}"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-app:latest"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-app:v${{ needs.createReleaseVersion.outputs.releaseVersion }}"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-app:${{ steps.setVersionForFlux.outputs.imageTag }}"
file: packages/app/Dockerfile
no-cache: true

deployFrontendToStaging:
name: Deploy Block Explorer frontend to staging
runs-on: ubuntu-latest
Expand Down
74 changes: 74 additions & 0 deletions docker-compose-cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '3.2'

services:
app:
build:
context: .
dockerfile: ./packages/app/Dockerfile
environment:
- VITE_APP_ENVIRONMENT=local
ports:
- '3010:3010'
depends_on:
- api
restart: unless-stopped

worker:
build:
context: .
dockerfile: ./packages/worker/Dockerfile
environment:
- PORT=3001
- LOG_LEVEL=verbose
- NODE_ENV=development
- DATABASE_HOST=postgres
- DATABASE_USER=postgres
- DATABASE_PASSWORD=postgres
- DATABASE_NAME=block-explorer
- BLOCKCHAIN_RPC_URL=http://host.docker.internal:3050
- BATCHES_PROCESSING_POLLING_INTERVAL=1000
ports:
- '3001:3001'
- '9229:9229'
- '9230:9230'
restart: unless-stopped

api:
build:
context: .
dockerfile: ./packages/api/Dockerfile
environment:
- PORT=3020
- METRICS_PORT=3005
- LOG_LEVEL=verbose
- NODE_ENV=development
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/block-explorer
ports:
- '3020:3020'
- '3005:3005'
- '9231:9229'
- '9232:9230'
depends_on:
- worker
restart: unless-stopped

postgres:
image: "postgres:14"
logging:
driver: none
volumes:
- postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=block-explorer

volumes:
postgres:
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
build:
context: .
dockerfile: ./packages/app/Dockerfile
target: development-stage
command: npm run --prefix packages/app dev -- --host
ports:
- '3010:3010'
Expand Down
31 changes: 28 additions & 3 deletions packages/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:18.17.1-alpine
ENV NODE_ENV=development
FROM node:18.17.1-alpine AS base-stage
ENV NODE_ENV=production

WORKDIR /usr/src/app
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
Expand All @@ -8,5 +8,30 @@ COPY --chown=node:node .npmrc .npmrc
COPY --chown=node:node lerna.json ./
COPY --chown=node:node package*.json ./
COPY --chown=node:node ./packages/app/package*.json ./packages/app/
RUN npm ci --ignore-scripts && npm cache clean --force
COPY --chown=node:node ./packages/app/. ./packages/app
RUN rm -f .npmrc

FROM base-stage AS development-stage
ENV NODE_ENV=development
COPY --chown=node:node .npmrc .npmrc
RUN npm ci
COPY --chown=node:node ./packages/app/. ./packages/app
RUN rm -f .npmrc

FROM development-stage AS build-stage
RUN npm run build

FROM base-stage AS production-stage
COPY --chown=node:node --from=build-stage /usr/src/app/packages/app/dist ./packages/app/dist
RUN npm i -g http-server

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

ARG PORT=3010
ENV PORT $PORT

USER node
WORKDIR /usr/src/app/packages/app/dist

CMD http-server -p $PORT
3 changes: 3 additions & 0 deletions packages/app/src/composables/useAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export default (context = useContext()) => {
const item = ref(<null | AddressItem>null);

const getContractVerificationInfo = async (address: string): Promise<ContractVerificationInfo | null> => {
if (!context.currentNetwork.value.verificationApiUrl) {
return null;
}
try {
return await $fetch(`${context.currentNetwork.value.verificationApiUrl}/contract_verification/info/${address}`);
} catch (e) {
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/composables/useContractABI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { checksumAddress } from "@/utils/formatters";

const retrieveAddressInfo = useMemoize(
async (address: Address, context: Context = useContext()) => {
if (!context.currentNetwork.value.verificationApiUrl) {
return null;
}
return await $fetch(`${context.currentNetwork.value.verificationApiUrl}/contract_verification/info/${address}`);
},
{
Expand Down
1 change: 0 additions & 1 deletion packages/app/src/configs/dev.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"networks": [
{
"apiUrl": "http://localhost:3020",
"verificationApiUrl": "http://127.0.0.1:3070",
"bridgeUrl": "http://localhost:3000/bridge",
"hostnames": [
"localhost"
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type NetworkConfig = {
name: string;
icon: string;
verificationApiUrl: string;
verificationApiUrl?: string;
apiUrl: string;
newProverUrl: string;
rpcUrl: string;
Expand Down
1 change: 0 additions & 1 deletion packages/app/src/configs/local.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"networks": [
{
"apiUrl": "http://localhost:3020",
"verificationApiUrl": "http://127.0.0.1:3070",
"bridgeUrl": "http://localhost:3000/bridge",
"hostnames": [
"localhost"
Expand Down
16 changes: 16 additions & 0 deletions packages/app/tests/composables/useAddress.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ describe("useAddresses", () => {
});
});

it("doesn't make contract verification request when network has no verificationApiUrl", async () => {
const currentNetwork = computed(() => ({ apiUrl: "http://api.url" }));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { item, getByAddress } = useAddress({ currentNetwork } as any);
await getByAddress("0xc31f9d4cbf557b6cf0ad2af66d44c358f7fa7a1c");
expect($fetch).toHaveBeenCalledOnce();
expect($fetch).toHaveBeenCalledWith("http://api.url/address/0xc31f9d4cbf557b6cf0ad2af66d44c358f7fa7a1c");
expect(item.value).toEqual({
address: "0xc31f9d4cbf557b6cf0ad2af66d44c358f7fa7a1c",
balances: {},
type: "contract",
verificationInfo: null,
proxyInfo: null,
});
});

it("takes proxy implementation contract from implementation function when it exists", async () => {
const { item, getByAddress } = useAddress();
await getByAddress("0xc31f9d4cbf557b6cf0ad2af66d44c358f7fa7a1c");
Expand Down
10 changes: 9 additions & 1 deletion packages/app/tests/composables/useContractABI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref } from "vue";
import { computed, ref } from "vue";

import { describe, expect, it, type SpyInstance, vi } from "vitest";

Expand Down Expand Up @@ -66,6 +66,14 @@ describe("useContractABI:", () => {
expect(isRequestFailed.value).toEqual(true);
mock.mockRestore();
});
it("doesn't make request when there is no verification api url", async () => {
const mock = ($fetch as unknown as SpyInstance).mockClear();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { getCollection } = useContractABI({ currentNetwork: computed(() => ({})) } as any);
await getCollection(["0x5550000000000000000000000000000000000000"]);
expect(mock).toHaveBeenCalledTimes(0);
mock.mockRestore();
});
it("caches the results", async () => {
const mock = ($fetch as unknown as SpyInstance).mockClear();
const { getCollection } = useContractABI();
Expand Down
4 changes: 2 additions & 2 deletions packages/app/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { Provider } from "zksync-web3";

export const GOERLI_NETWORK: NetworkConfig = {
name: "goerli",
verificationApiUrl: "",
verificationApiUrl: "https://zksync2-testnet-explorer.zksync.dev",
apiUrl: "https://block-explorer-api.testnets.zksync.dev",
icon: "",
l2ChainId: 280,
Expand All @@ -37,7 +37,7 @@ export const GOERLI_NETWORK: NetworkConfig = {
};
export const GOERLI_BETA_NETWORK: NetworkConfig = {
name: "goerli-beta",
verificationApiUrl: "",
verificationApiUrl: "https://zksync2-testnet-explorer.zksync.dev",
apiUrl: "https://block-explorer-api.mock.zksync.dev",
icon: "",
l2ChainId: 270,
Expand Down

0 comments on commit 4ed8cef

Please sign in to comment.