Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance management of custom docker images #91

Merged
merged 40 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9ea5a93
chore: move `zkevm-contracts.Dockerfile`
leovct Apr 26, 2024
fa1561e
feat: add zkevm-bridge-ui patch
leovct Apr 26, 2024
7b25759
ci: add cron job to build the zkevm-bridge-ui image
leovct Apr 26, 2024
61b1e7d
ci: add cron job to build zkevm-contracts images
leovct Apr 26, 2024
5179b25
ci: fix zkevm-contracts build
leovct Apr 26, 2024
6af704e
feat: add zkevm-bridge-ui Dockerfile
leovct Apr 26, 2024
e0a3629
docs: remove zkevm-cache-contracts page
leovct Apr 26, 2024
2d116f3
chore: clean up
leovct Apr 26, 2024
b725be4
doc: add docs to build images locally
leovct Apr 26, 2024
3a16677
test
leovct Apr 26, 2024
348221b
fix: zkevm-bridge-ui job
leovct Apr 26, 2024
0d00d0f
ci: add concurency in ci
leovct Apr 26, 2024
4725242
ci: same
leovct Apr 26, 2024
b5841f6
test
leovct Apr 26, 2024
e9cd4ec
fix: issue with zkevm-bridge-ui
leovct Apr 26, 2024
e17f136
test
leovct Apr 26, 2024
d8a3ec7
chore: nit
leovct Apr 26, 2024
0d1b9f5
docs: update README
leovct Apr 26, 2024
0572cff
docs: nit
leovct Apr 26, 2024
06091fc
ci: build images every week instead of every day
leovct Apr 26, 2024
bc02d16
fix: push to docker hub in the meantime
leovct Apr 29, 2024
ddf8251
chore: pull images from docker hub
leovct Apr 29, 2024
631ca70
fix: npm install issue
leovct Apr 29, 2024
0326102
ci: fix hadolint in ci lint check
leovct Apr 29, 2024
01f1b8a
fix: network helper Dockerfile
leovct Apr 29, 2024
8af07fc
fix: zkevm-contracts Dockerfile
leovct Apr 29, 2024
47309f6
fix: zkem-bridge-ui Dockerfile
leovct Apr 29, 2024
44c801f
fix: revert npm ci install fix
leovct Apr 29, 2024
0edb9c1
test
leovct Apr 29, 2024
4911ef8
fix: npm install issues
leovct Apr 29, 2024
cf02b22
Merge branch 'main' into chore/enhance-management-of-custom-docker-im…
leovct Apr 29, 2024
b6b73b8
chore: nit
leovct Apr 29, 2024
326f22d
Merge branch 'main' into chore/enhance-management-of-custom-docker-im…
leovct Apr 29, 2024
10ce449
chore: move workload to `docker/`
leovct Apr 29, 2024
a8ca779
docs: explain how to build the workload img locally
leovct Apr 29, 2024
5b74f82
ci: build workload img
leovct Apr 29, 2024
35fd484
chore: lint workload Dockerfile
leovct Apr 29, 2024
1f938f1
chore: nit
leovct Apr 29, 2024
bda2105
chore: update zkevm-contracts tags
leovct Apr 29, 2024
dccacc4
docs: update zkevm-contracts section
leovct Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: deploy
name: Deploy

on:
pull_request:
Expand Down
118 changes: 118 additions & 0 deletions .github/workflows/docker-image-builder-cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
name: Docker Image Builder Cron

on:
schedule:
- cron: '0 6 * * 1' # Every Monday at 6 AM Paris time (UTC+2).
workflow_dispatch:
pull_request: # TODO: Remove this. This is just for testing purposes.

concurrency:
group: docker-image-builder-cron-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
ZKEVM_BRIDGE_UI_BRANCH: develop
POLYCLI_VERSION: main

jobs:
zkevm-contracts:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
fork:
- id: fork4
branch: v1.1.0-fork.4
- id: fork5
branch: v2.0.0-fork.5
- id: fork6
branch: v3.0.0-fork.6
- id: fork7
branch: v4.0.0-fork.7
- id: fork8
branch: v5.0.1-rc.2-fork.8
- id: fork9
branch: v6.0.0-rc.1-fork.9
- id: develop
branch: develop

steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v5
with:
file: docker/zkevm-contracts.Dockerfile
build-args: |
ZKEVM_CONTRACTS_BRANCH=${{ matrix.fork.branch }}
POLYCLI_VERSION=${{ env.POLYCLI_VERSION }}
tags: ${{ secrets.DOCKERHUB_USERNAME }}/zkevm-contracts:${{ matrix.fork.id }}
platforms: linux/amd64,linux/arm64
push: true

zkevm-bridge-ui:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Clone zkevm-bridge-ui repository
run: |
mkdir /opt/zkevm-bridge-ui
git clone --branch ${{ env.ZKEVM_BRIDGE_UI_BRANCH }} https://github.com/0xPolygonHermez/zkevm-bridge-ui /opt/zkevm-bridge-ui

- name: Apply patches
working-directory: /opt/zkevm-bridge-ui
run: |
patch -p1 -i ${{ github.workspace }}/docker/zkevm-bridge-ui/deploy.sh.diff
patch -p1 -i ${{ github.workspace }}/docker/zkevm-bridge-ui/env.ts.diff

- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: /opt/zkevm-bridge-ui
file: /opt/zkevm-bridge-ui/Dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/zkevm-bridge-ui:multi-network
platforms: linux/amd64,linux/arm64
push: true

workload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v5
with:
file: docker/workload.Dockerfile
build-args: |
POLYCLI_VERSION=${{ env.POLYCLI_VERSION }}
tags: ${{ secrets.DOCKERHUB_USERNAME }}/workload:0.0.1
platforms: linux/amd64,linux/arm64
push: true
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: lint
name: Lint

on:
pull_request:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
run: yamllint --config-file ${{ github.workspace }}/.yamllint.yml .

- name: Run hadolint
run: find . -type f -name 'Dockerfile*' | sort | xargs -I {} hadolint --config ${{ github.workspace }}/.hadolint.yml {}
run: find . -type f -name '*.Dockerfile' | sort | xargs -I {} hadolint --config ${{ github.workspace }}/.hadolint.yml {}

- name: Run shellcheck
run: find . -type f -name '*.sh' | sort | xargs -I {} shellcheck {}
3 changes: 2 additions & 1 deletion .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: regression-tests
---
name: Regression Tests

on:
workflow_dispatch:
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion doc-drafts/trigger-a-reorg/network-helper.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ WORKDIR /opt/polygon-cli
RUN git clone https://github.com/maticnetwork/polygon-cli.git . \
&& CGO_ENABLED=0 go build -o polycli main.go

FROM nicolaka/netshoot:latest
FROM nicolaka/netshoot:v0.12
LABEL author="devtools@polygon.technology"
LABEL description="Helper image to debug network issues"
COPY --from=polycli-builder /opt/polygon-cli/polycli /usr/local/bin/polycli
28 changes: 0 additions & 28 deletions doc-drafts/zkevm-contracts-images-builder.sh

This file was deleted.

72 changes: 72 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Custom Docker Images for Kurtosis CDK

We maintain a suite of custom Docker images tailored specifically for deploying the CDK stack. These images serve various purposes, including hosting distinct zkEVM contracts (each fork tagged separately), adapting the bridge UI to support relative URLs, and applying specific workloads.

We ensure the continuous availability of our custom Docker images through an automated build process. A [cron](../.github/workflows/docker-image-builder-cron.yml) job is configured to run weekly, automatically triggering the build and push of these images. This ensures that the images are regularly updated with the latest changes and dependencies. Moreover, should immediate updates or manual initiation of the image building process be required, users can access the GitHub UI for manual triggering. Alternatively, the images can be built locally by following the provided guide.

## Local Image Building

If you ever need to build these images locally, here's a brief guide.

### zkEVM Contracts

To build a local image containing all npm dependencies and zkEVM contracts compiled for fork ID 9, follow these steps:

```bash
docker build . \
--tag local/zkevm-contracts:fork9 \
--build-arg ZKEVM_CONTRACTS_BRANCH=v6.0.0-rc.1-fork.9 \
--build-arg POLYCLI_VERSION=main \
--file zkevm-contracts.Dockerfile
```

```bash
$ docker images --filter "reference=local/zkevm-contracts"
REPOSITORY TAG IMAGE ID CREATED SIZE
local/zkevm-contracts fork9 54d894c6a5bd 10 minutes ago 2.3GB
```

Here's a quick reference matrix for mapping fork IDs to branches/releases:

| Fork ID | Branch |
| ------- | ------------------ |
| fork4 | v1.1.0-fork.4 |
| fork5 | v2.0.0-fork.5 |
| fork6 | v3.0.0-fork.6 |
| fork7 | v4.0.0-fork.7 |
| fork8 | v5.0.1-rc.2-fork.8 |
| fork9 | develop |

## zkEVM Bridge UI

To build the zkEVM Bridge UI image locally, use the following command:

```bash
docker build zkevm-bridge-ui \
--tag local/zkevm-bridge-ui:multi-network \
--build-arg ZKEVM_BRIDGE_UI_TAG=develop \
--file zkevm-bridge-ui/zkevm-bridge-ui.Dockerfile
```

```bash
$ docker images --filter "reference=local/zkevm-bridge-ui"
REPOSITORY TAG IMAGE ID CREATED SIZE
local/zkevm-bridge-ui multi-network 040905e1cabe 28 seconds ago 377MB
```

## Workload

To build the workload image locally, use the following command:

```bash
docker build . \
--tag local/workload:0.0.1 \
--build-arg POLYCLI_VERSION=main \
--file workload.Dockerfile
```

```bash
$ docker images --filter "reference=local/workload"
REPOSITORY TAG IMAGE ID CREATED SIZE
local/workload 0.0.1 3f85f026aaf9 2 seconds ago 490MB
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ LABEL description="Helper image capable of executing diverse workloads"

COPY --from=polycli-builder /opt/polygon-cli/polycli /usr/bin/polycli
# WARNING (DL3008): Pin versions in apt get install.
# WARNING (DL3013): Pin versions in pip.
# WARNING (DL4006): Set the SHELL option -o pipefail before RUN with a pipe in it
# WARNING (SC1091): (Sourced) file not included in mock.
# hadolint ignore=DL3008,DL4006,SC1091
# hadolint ignore=DL3008,DL3013,DL4006,SC1091
RUN apt-get update \
&& apt-get install --yes --no-install-recommends curl jq git python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install yq \
&& pip3 install --no-cache-dir yq \
&& curl --silent --location --proto "=https" https://foundry.paradigm.xyz | bash \
&& /root/.foundry/bin/foundryup \
&& cp /root/.foundry/bin/* /usr/local/bin
13 changes: 13 additions & 0 deletions docker/zkevm-bridge-ui/deploy.sh.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index 22e5b09..00da634 100644
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -21,6 +21,9 @@ echo "VITE_POLYGON_ZK_EVM_NETWORK_ID=$POLYGON_ZK_EVM_NETWORK_ID" >> $ENV_FILENAM
# BRIDGE API env vars
echo "VITE_BRIDGE_API_URL=$BRIDGE_API_URL" >> $ENV_FILENAME

+# Support for relative URLS
+echo "VITE_RESOLVE_RELATIVE_URLS=$RESOLVE_RELATIVE_URLS" >> $ENV_FILENAME
+
# FIAT EXCHANGE RATES API env vars
echo "VITE_ENABLE_FIAT_EXCHANGE_RATES=$ENABLE_FIAT_EXCHANGE_RATES" >> $ENV_FILENAME
100 changes: 100 additions & 0 deletions docker/zkevm-bridge-ui/env.ts.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
diff --git a/src/adapters/env.ts b/src/adapters/env.ts
index 034b982..bfa5d93 100644
--- a/src/adapters/env.ts
+++ b/src/adapters/env.ts
@@ -31,6 +31,7 @@ interface Env {
VITE_REPORT_FORM_PLATFORM_ENTRY?: string;
VITE_REPORT_FORM_URL?: string;
VITE_REPORT_FORM_URL_ENTRY?: string;
+ VITE_RESOLVE_RELATIVE_URLS?: string;
}

type GetFiatExchangeRatesEnvParams = Pick<
@@ -180,6 +181,7 @@ const envToDomain = ({
VITE_REPORT_FORM_PLATFORM_ENTRY,
VITE_REPORT_FORM_URL,
VITE_REPORT_FORM_URL_ENTRY,
+ VITE_RESOLVE_RELATIVE_URLS,
}: Env): Promise<domain.Env> => {
const polygonZkEVMNetworkId = z.coerce.number().positive().parse(VITE_POLYGON_ZK_EVM_NETWORK_ID);
const isOutdatedNetworkModalEnabled = stringBooleanParser.parse(
@@ -188,7 +190,30 @@ const envToDomain = ({
const forceUpdateGlobalExitRootForL1 = stringBooleanParser.parse(
VITE_ETHEREUM_FORCE_UPDATE_GLOBAL_EXIT_ROOT
);
- const bridgeApiUrl = VITE_BRIDGE_API_URL;
+
+ const isSupportForRelativeUrlsEnabled = stringBooleanParser.parse(VITE_RESOLVE_RELATIVE_URLS);
+
+ let bridgeApiUrl: string;
+ if (isSupportForRelativeUrlsEnabled) {
+ bridgeApiUrl = window.location.origin + VITE_BRIDGE_API_URL;
+ } else {
+ bridgeApiUrl = VITE_BRIDGE_API_URL;
+ }
+
+ let ethereumRpcUrl: string;
+ if (isSupportForRelativeUrlsEnabled) {
+ ethereumRpcUrl = window.location.origin + VITE_ETHEREUM_RPC_URL;
+ } else {
+ ethereumRpcUrl = VITE_ETHEREUM_RPC_URL;
+ }
+
+ let zkevmRpcUrl: string;
+ if (isSupportForRelativeUrlsEnabled) {
+ zkevmRpcUrl = window.location.origin + VITE_POLYGON_ZK_EVM_RPC_URL;
+ } else {
+ zkevmRpcUrl = VITE_POLYGON_ZK_EVM_RPC_URL;
+ }
+
const outdatedNetworkModal: domain.Env["outdatedNetworkModal"] = isOutdatedNetworkModalEnabled
? {
isEnabled: true,
@@ -208,13 +233,13 @@ const envToDomain = ({
explorerUrl: VITE_ETHEREUM_EXPLORER_URL,
poeContractAddress: VITE_ETHEREUM_PROOF_OF_EFFICIENCY_CONTRACT_ADDRESS,
rollupManagerAddress: VITE_ETHEREUM_ROLLUP_MANAGER_ADDRESS,
- rpcUrl: VITE_ETHEREUM_RPC_URL,
+ rpcUrl: ethereumRpcUrl,
},
polygonZkEVM: {
bridgeContractAddress: VITE_POLYGON_ZK_EVM_BRIDGE_CONTRACT_ADDRESS,
explorerUrl: VITE_POLYGON_ZK_EVM_EXPLORER_URL,
networkId: polygonZkEVMNetworkId,
- rpcUrl: VITE_POLYGON_ZK_EVM_RPC_URL,
+ rpcUrl: zkevmRpcUrl,
},
}).then((chains) => {
const ethereumChain = chains.find((chain) => chain.key === "ethereum");
@@ -250,7 +275,7 @@ const envToDomain = ({
const envParser = StrictSchema<Env, domain.Env>()(
z
.object({
- VITE_BRIDGE_API_URL: z.string().url(),
+ VITE_BRIDGE_API_URL: z.string(),
VITE_ENABLE_DEPOSIT_WARNING: z.string(),
VITE_ENABLE_FIAT_EXCHANGE_RATES: z.string(),
VITE_ENABLE_OUTDATED_NETWORK_MODAL: z.string().optional(),
@@ -260,7 +285,7 @@ const envParser = StrictSchema<Env, domain.Env>()(
VITE_ETHEREUM_FORCE_UPDATE_GLOBAL_EXIT_ROOT: z.string(),
VITE_ETHEREUM_PROOF_OF_EFFICIENCY_CONTRACT_ADDRESS: z.string().length(42),
VITE_ETHEREUM_ROLLUP_MANAGER_ADDRESS: z.string().length(42),
- VITE_ETHEREUM_RPC_URL: z.string().url(),
+ VITE_ETHEREUM_RPC_URL: z.string(),
VITE_FIAT_EXCHANGE_RATES_API_KEY: z.string().optional(),
VITE_FIAT_EXCHANGE_RATES_API_URL: z.string().url().optional(),
VITE_FIAT_EXCHANGE_RATES_ETHEREUM_USDC_ADDRESS: z.string().length(42).optional(),
@@ -271,11 +296,12 @@ const envParser = StrictSchema<Env, domain.Env>()(
VITE_POLYGON_ZK_EVM_BRIDGE_CONTRACT_ADDRESS: z.string().length(42),
VITE_POLYGON_ZK_EVM_EXPLORER_URL: z.string().url(),
VITE_POLYGON_ZK_EVM_NETWORK_ID: z.string(),
- VITE_POLYGON_ZK_EVM_RPC_URL: z.string().url(),
+ VITE_POLYGON_ZK_EVM_RPC_URL: z.string(),
VITE_REPORT_FORM_ERROR_ENTRY: z.string().optional(),
VITE_REPORT_FORM_PLATFORM_ENTRY: z.string().optional(),
VITE_REPORT_FORM_URL: z.string().optional(),
VITE_REPORT_FORM_URL_ENTRY: z.string().optional(),
+ VITE_RESOLVE_RELATIVE_URLS: z.string().optional(),
})
.transform(envToDomain)
);
Loading
Loading