Skip to content

Commit b255c79

Browse files
philippecamachoshenkeyao
authored andcommitted
Improve gitHub action enclave test (#183)
* Refactor running tests in EC2 instance. * Pinpoint version of aws-nitro-enclaves-cli * Fix bug ethereum-optimism#4736 of foundry. Faster execution of commands inside nix shell. * Cachix configuration * Use pre-installed AMI.
1 parent faaa0bc commit b255c79

File tree

8 files changed

+97
-48
lines changed

8 files changed

+97
-48
lines changed

.github/workflows/enclave.yaml

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21+
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
2125
- uses: aws-actions/configure-aws-credentials@v4
2226
name: configure aws credentials
2327
with:
@@ -69,7 +73,7 @@ jobs:
6973
- name: Launch EC2 Instance
7074
id: ec2
7175
run: |
72-
AMI_ID=ami-0fe972392d04329e1
76+
AMI_ID=ami-0ff5662328e9bbc2f
7377
INSTANCE_ID=$(aws ec2 run-instances \
7478
--image-id "$AMI_ID" \
7579
--count 1 \
@@ -96,53 +100,17 @@ jobs:
96100
echo "DNS=$DNS" >> $GITHUB_ENV
97101
echo "dns=$DNS" >> $GITHUB_OUTPUT
98102
99-
- name: Install dependencies
100-
run: |
101-
echo "Current branch: $BRANCH_NAME"
102-
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS << EOF
103-
set -e
104-
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon
105-
source ~/.bashrc
106-
mkdir -p ~/.config/nix
107-
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
108-
sudo yum update
109-
sudo yum install git -y
110-
sudo yum install docker -y
111-
sudo amazon-linux-extras install aws-nitro-enclaves-cli -y
112-
git clone https://github.com/EspressoSystems/optimism-espresso-integration.git
113-
cd optimism-espresso-integration
114-
git checkout "$BRANCH_NAME"
115-
git submodule update --init --recursive
116-
nix develop
117-
EOF
118-
119-
- name: Configure and start enclave service
103+
- name: Upload run-tests.sh to EC2
120104
run: |
121-
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS << 'EOF'
122-
set -e
123-
sudo nitro-cli --version
124-
sudo systemctl stop nitro-enclaves-allocator.service
125-
echo -e '---\nmemory_mib: 4096\ncpu_count: 2' | sudo tee /etc/nitro_enclaves/allocator.yaml
126-
sudo systemctl start nitro-enclaves-allocator.service
127-
EOF
128-
129-
- name: Start docker service
130-
run: |
131-
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS << 'EOF'
132-
set -e
133-
sudo usermod -a -G docker ec2-user
134-
sudo service docker start
135-
sudo chown ec2-user /var/run/docker.sock
136-
EOF
105+
scp -o StrictHostKeyChecking=no -i key.pem espresso/scripts/run-tests-github-actions.sh ec2-user@$DNS:/home/ec2-user/
106+
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS "chmod +x run-tests-github-actions.sh"
137107
138-
# Compile contracts first to avoid text file busy error
139-
- name: Run tests
108+
- name: Run test script on EC2
109+
timeout-minutes: 40
140110
run: |
141-
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -i key.pem ec2-user@$DNS << 'EOF'
142-
set -e
143-
cd /home/ec2-user/optimism-espresso-integration
144-
nix develop --command just compile-contracts
145-
nix develop --command just espresso-enclave-tests
111+
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -i key.pem ec2-user@$DNS << EOF
112+
export BRANCH_NAME=$BRANCH_NAME
113+
./run-tests-github-actions.sh ${{ secrets.CACHIX_AUTH_TOKEN }}
146114
EOF
147115
148116
- name: Terminate EC2 instance

README_ESPRESSO.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,9 @@ In order to run the tests for the enclave in EC2 via github actions one must cre
313313
]
314314
}
315315
```
316+
317+
Currently, the github workflow in `.github/workflows/enclave.yaml` relies on a custom AWS AMI with id `ami-0ff5662328e9bbc2f`.
318+
In order to refresh this AMI one needs to:
319+
1. Create an AWS EC2 instance with the characteristics described in (see `.github/workflows/enclave.yaml` *Launch EC2 Instance* job).
320+
2. Copy the script `espresso/scrips/enclave-prepare-ami.sh` in the EC2 instance (e.g. using scp) and run it.
321+
3. [Export the AMI instance](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/tkv-create-ami-from-instance.html).
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
set -x
4+
5+
echo "[*] Setting up Nix"
6+
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon --no-confirm
7+
source /etc/profile.d/nix.sh
8+
nix-env -iA cachix -f https://cachix.org/api/v1/install
9+
mkdir -p ~/.config/nix
10+
echo "trusted-users = root ec2-user" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon
11+
12+
13+
echo "[*] Installing dependencies..."
14+
sudo yum update -y
15+
sudo yum install -y git docker
16+
sudo amazon-linux-extras enable aws-nitro-enclaves-cli
17+
sudo yum install -y aws-nitro-enclaves-cli-1.4.2
18+
19+
20+
# Workaround due to https://github.com/foundry-rs/foundry/issues/4736
21+
sudo yum install -y gcc
22+
curl https://sh.rustup.rs -sSf | sh -s -- -y
23+
. $HOME/.cargo/env
24+
cargo install svm-rs
25+
svm install 0.8.15
26+
svm install 0.8.19
27+
svm install 0.8.22
28+
svm install 0.8.25
29+
svm install 0.8.28
30+
svm install 0.8.30
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
set -x
4+
5+
echo "[*] Setting up Cachix"
6+
cachix authtoken $1
7+
cachix use espresso-systems-private
8+
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
9+
10+
echo "[*] Cloning repo and checking out branch $BRANCH_NAME..."
11+
git clone https://github.com/EspressoSystems/optimism-espresso-integration.git
12+
cd optimism-espresso-integration
13+
git checkout "$BRANCH_NAME"
14+
git submodule update --init --recursive
15+
# Poblate cachix cahe
16+
nix flake archive --json | jq -r '.path,(.inputs|to_entries[].value.path)' | cachix push espresso-systems-private
17+
18+
echo "[*] Starting Docker..."
19+
sudo systemctl enable --now docker
20+
sudo usermod -a -G docker ec2-user
21+
sudo chown ec2-user /var/run/docker.sock
22+
23+
echo "[*] Configuring Nitro Enclaves..."
24+
sudo systemctl stop nitro-enclaves-allocator.service || true
25+
echo -e '---\nmemory_mib: 4096\ncpu_count: 2' | sudo tee /etc/nitro_enclaves/allocator.yaml
26+
sudo systemctl start nitro-enclaves-allocator.service
27+
28+
29+
echo "[*] Running tests in nix develop shell..."
30+
31+
nix develop --command bash -c "just compile-contracts-fast && just build-batcher-enclave-image && just espresso-enclave-tests"

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
pkgs.awscli2
103103
pkgs.just
104104
pkgs.pnpm
105+
pkgs.cargo
105106
];
106107
shellHook = ''
107108
export FOUNDRY_DISABLE_NIGHTLY_WARNING=1

justfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ run-test12: compile-contracts
2020
compile-contracts:
2121
(cd packages/contracts-bedrock && just build-dev)
2222

23+
compile-contracts-fast:
24+
(cd packages/contracts-bedrock && forge build --offline --skip "/**/test/**")
25+
2326
build-batcher-enclave-image:
2427
(cd kurtosis-devnet && just op-batcher-enclave-image)
2528

@@ -30,8 +33,9 @@ espresso_tests_timeout := "35m"
3033
espresso-tests timeout=espresso_tests_timeout: compile-contracts
3134
go test -timeout={{timeout}} -p=1 -count=1 ./espresso/environment
3235

33-
espresso-enclave-tests timeout=espresso_tests_timeout: compile-contracts build-batcher-enclave-image
34-
ESPRESSO_RUN_ENCLAVE_TESTS=true go test -timeout={{timeout}} -p=1 -count=1 ./espresso/enclave-tests/...
36+
espresso-enclave-tests:
37+
ESPRESSO_RUN_ENCLAVE_TESTS=true go test -timeout={{espresso_tests_timeout}} -p=1 -count=1 ./espresso/enclave-tests/...
38+
3539

3640
IMAGE_NAME := "ghcr.io/espressosystems/espresso-sequencer/espresso-dev-node:release-colorful-snake"
3741
remove-espresso-containers:

op-batcher/batcher/espresso.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,15 @@ func (l *BatchSubmitter) registerBatcher(ctx context.Context) error {
996996
return nil
997997
}
998998

999+
log.Info("Batch authenticator address", "value", l.RollupConfig.BatchAuthenticatorAddress)
1000+
code, err := l.L1Client.CodeAt(ctx, l.RollupConfig.BatchAuthenticatorAddress, nil)
1001+
if err != nil {
1002+
return fmt.Errorf("Failed to check code at contrat address: %w", err)
1003+
}
1004+
if len(code) == 0 {
1005+
return fmt.Errorf("No contract deployed at this address %w", err)
1006+
}
1007+
9991008
batchAuthenticator, err := bindings.NewBatchAuthenticator(l.RollupConfig.BatchAuthenticatorAddress, l.L1Client)
10001009
if err != nil {
10011010
return fmt.Errorf("failed to create BatchAuthenticator contract bindings: %w", err)

0 commit comments

Comments
 (0)