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: add docker build for amd64 / arm64, e2e tests, publishing ghcr #503

Merged
merged 23 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 36 additions & 17 deletions .github/workflows/build-push-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,76 @@ on:
tags:
- "*"

env:
PLATFORMS: 'linux/amd64,linux/arm64'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build-push-image:
name: Build and push Docker image
runs-on: [matterlabs-ci-runner]
set-tags:
name: Set Docker Tags
runs-on: ubuntu-latest
outputs:
base_tag: ${{ steps.set_tag.outputs.base_tag }}
steps:
- uses: actions/checkout@v4

- name: Set git SHA
- name: Set Git SHA
id: git_sha
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Set Docker tag
id: docker_tag
- name: Determine Base Tag
id: set_tag
run: |
ts=$(date +%s%N | cut -b1-13)
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "tag=${{ steps.git_sha.outputs.sha_short }}-${ts}" >> $GITHUB_OUTPUT
echo "base_tag=${{ steps.git_sha.outputs.sha_short }}-${ts}" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "tag=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT
echo "base_tag=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "tag=none" >> $GITHUB_OUTPUT
echo "base_tag=none" >> $GITHUB_OUTPUT
else
echo "Unsupported event ${GITHUB_EVENT_NAME} or ref ${GITHUB_REF}, only refs/heads/, refs/tags/ and pull_request are supported."
echo "Unsupported event ${GITHUB_EVENT_NAME} or ref ${GITHUB_REF}. Only refs/heads/main, refs/tags/*, and pull_request are supported."
exit 1
fi

build-push-image:
name: Build and Push Docker Image
runs-on: matterlabs-ci-runner-high-performance
needs: set-tags
steps:
- uses: actions/checkout@v4

- name: Login to GAR
run: |
gcloud auth configure-docker us-docker.pkg.dev -q

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved

- name: Set up Docker Buildx
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v3

# For now, we're only pushing to the internal registry
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
platforms: ${{ env.PLATFORMS }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/era-test-node:${{ steps.docker_tag.outputs.tag }}
us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/era-test-node:latest
ghcr.io/${{ github.repository_owner }}/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}
us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}

- name: Print image digest to summary
run: |
echo "Image tag: ${{ steps.docker_tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "Image tags: ghcr.io/${{ github.repository_owner }}/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}" >> $GITHUB_STEP_SUMMARY
echo "Image tags: us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}" >> $GITHUB_STEP_SUMMARY
85 changes: 85 additions & 0 deletions .github/workflows/e2e-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Run e2e tests against Docker node

on:
workflow_call:
push:
branches:
- main
pull_request:

jobs:
test-docker-image:
name: e2e tests on Docker node
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image locally
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
tags: test-anvil-zksync:latest

- name: Start Docker container
run: |
echo "Starting Docker container with test-anvil-zksync image..."
docker run --rm -d -p 8011:8011 -v $PWD/logs:/logs --name test_anvil_zksync test-anvil-zksync:latest

- name: Wait for the node to be ready
run: |
echo "Waiting for the node to be ready..."
MAX_RETRIES=10
COUNTER=0
URL="http://localhost:8011"
DATA='{"jsonrpc": "2.0", "id": "1", "method": "eth_chainId", "params": []}'

while [ $COUNTER -lt $MAX_RETRIES ]; do
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "content-type: application/json" -d "$DATA" $URL || true)
if [ "$RESPONSE" -eq 200 ]; then
echo "Node is running!"
break
else
echo "Node not ready, retrying in 1 second..."
COUNTER=$((COUNTER + 1))
sleep 1
fi
done

if [ $COUNTER -eq $MAX_RETRIES ]; then
echo "Failed to contact node after $MAX_RETRIES attempts. Are you sure the node is running at $URL ?"
docker stop test_anvil_zksync
exit 1
fi

- name: Install dependencies for e2e tests
working-directory: ./e2e-tests
run: |
echo "Installing e2e test dependencies..."
yarn install --frozen-lockfile

- name: Compile contracts and run e2e tests
working-directory: ./e2e-tests
env:
ANVIL_LOG_PATH: "${{ github.workspace }}/logs/anvil-zksync.log"
run: |
echo "Compiling contracts and running e2e tests..."
yarn hardhat compile
yarn test

- name: Stop Docker container
if: always()
run: |
echo "Stopping Docker container..."
docker stop test_anvil_zksync

- name: Print test result summary
run: |
echo "Tests completed successfully!"
15 changes: 13 additions & 2 deletions e2e-tests/test/anvil-apis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ethers } from "hardhat";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import * as hre from "hardhat";
import * as fs from "node:fs";
import * as path from "node:path";

const provider = getTestProvider();

Expand Down Expand Up @@ -90,19 +91,29 @@ describe("anvil_setBlockTimestampInterval & anvil_removeBlockTimestampInterval",

describe("anvil_setLoggingEnabled", function () {
it("Should disable and enable logging", async function () {
const logFilePath = process.env.ANVIL_LOG_PATH || path.resolve("../anvil-zksync.log");

// Arrange
const wallet = new Wallet(RichAccounts[0].PrivateKey, provider);
const userWallet = Wallet.createRandom().connect(provider);

// Act
await provider.send("anvil_setLoggingEnabled", [false]);
const logSizeBefore = fs.statSync("../anvil-zksync.log").size;

let logSizeBefore = 0;
if (fs.existsSync(logFilePath)) {
logSizeBefore = fs.statSync(logFilePath).size;
}
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved

await wallet.sendTransaction({
to: userWallet.address,
value: ethers.parseEther("0.1"),
});
const logSizeAfter = fs.statSync("../anvil-zksync.log").size;

let logSizeAfter = 0;
if (fs.existsSync(logFilePath)) {
logSizeAfter = fs.statSync(logFilePath).size;
}

// Reset
await provider.send("anvil_setLoggingEnabled", [true]);
Expand Down
Loading