Skip to content

Commit da20a2a

Browse files
authored
feat: e2e runner setup (#690)
* rf: linting * feat(e2e): inital setup * add: scratch dockerfile for relayer version * rf: reuse workflow * fix: stop runner after all jobs are completed successfully * fix: release binary download * fix: subnet and security group id * add(Makefile): e2e test, add(ci): missing e2e test step * fix(ci): relayer dockerfile download url * fix(ci): use inputs for stop job * fix(ci): ouput syntax for resusable workflow * rf(ci): receive relayer version conditionally
1 parent bea923a commit da20a2a

12 files changed

+287
-2
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Description:
1+
## Description
22

33
### Commit Message
44

@@ -14,7 +14,7 @@ see the [guidelines](https://github.com/icon-project/community/blob/main/guideli
1414
version: <log entry>
1515
```
1616

17-
## Checklist:
17+
## Checklist
1818

1919
- [ ] I have performed a self-review of my own code
2020
- [ ] I have documented my code in accordance with the [documentation guidelines](https://github.com/icon-project/community/blob/main/guidelines/technical/software-development-guidelines.md#documentation)

.github/packer/builder.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
set -euof
4+
5+
install_deps() {
6+
sudo yum install -y git docker make tar perl-Digest-SHA libicu
7+
}
8+
9+
configure_docker() {
10+
sudo systemctl enable docker --now
11+
sudo usermod -aG docker ec2-user
12+
}
13+
14+
build_goloop_images() {
15+
git clone https://github.com/icon-project/goloop.git
16+
cd goloop
17+
make goloop-image
18+
make goloop-icon-image
19+
docker tag goloop iconloop/goloop-icon
20+
rm -rf ../goloop
21+
}
22+
23+
pull_archway_images() {
24+
docker pull archwaynetwork/archwayd:sha-8f53ac8
25+
}
26+
27+
configure_relayer() {
28+
mv /tmp/Dockerfile .
29+
cat > build.sh <<EOF
30+
#!/bin/sh
31+
docker build -t relayer --build-args VERSION=$1 .
32+
EOF
33+
chmod +x build.sh
34+
}
35+
36+
build_services() {
37+
build_goloop_images
38+
pull_archway_images
39+
configure_relayer
40+
}
41+
42+
cleanup(){
43+
sudo yum uninstall -y git make tar perl-Digest-SHA
44+
}
45+
46+
install_deps
47+
configure_docker
48+
build_services
49+
cleanup

.github/packer/builds.pkr.hcl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
build {
2+
name = local.name
3+
sources = ["source.amazon-ebs.linux"]
4+
5+
provisioner "shell" {
6+
execute_command = "sudo -S bash -c '{{ .Path }}'"
7+
script = "${path.root}/builder.sh"
8+
}
9+
10+
provisioner "file" {
11+
source = "${path.root}/relayer.Dockerfile"
12+
destination = "/tmp/Dockerfile"
13+
}
14+
}

.github/packer/locals.pkr.hcl

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
locals {
2+
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
3+
name = "github-runner"
4+
}

.github/packer/relayer.Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM alpine:latest AS build-env
2+
3+
RUN apk add --no-cache tar
4+
5+
ARG VERSION=0.1.0-alpha.7
6+
ARG BASE_URL=https://github.com/icon-project/ibc-relay/releases/download
7+
ARG PLATFORM=linux
8+
ARG ARCH=amd64
9+
10+
ADD $BASE_URL/v${VERSION}/ibc-relay_${VERSION}_${PLATFORM}_${ARCH}.tar.gz .
11+
12+
RUN tar -xvf ibc-relay_${VERSION}_linux_amd64.tar.gz && \
13+
mv ibc-relay_${VERSION}_linux_amd64/rly .
14+
15+
FROM scratch
16+
17+
COPY --from=build-env /rly /usr/local/bin/rly
18+
19+
WORKDIR /root/.relayer
20+
21+
ENTRYPOINT ["/usr/local/bin/rly"]

.github/packer/require.pkr.hcl

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
packer {
2+
required_plugins {
3+
amazon = {
4+
version = ">= 1.2.6"
5+
source = "github.com/hashicorp/amazon"
6+
}
7+
}
8+
}

.github/packer/sources.pkr.hcl

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# source ami to use
2+
3+
source "amazon-ebs" "linux" {
4+
ami_name = local.name
5+
instance_type = var.instance_type
6+
region = var.aws_region
7+
ssh_username = var.ssh_username
8+
source_ami_filter {
9+
filters = {
10+
name = "al2023-ami-2023.*.*-kernel-6.*-x86_64"
11+
root-device-type = "ebs"
12+
virtualization-type = "hvm"
13+
}
14+
most_recent = true
15+
owners = ["amazon"]
16+
}
17+
tags = {
18+
Name = local.name
19+
Project = "IBC"
20+
ManagedBy = "Packer"
21+
}
22+
}

.github/packer/variables.pkr.hcl

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
variable "aws_region" {
2+
type = string
3+
default = "us-east-1"
4+
}
5+
6+
variable "instance_type" {
7+
type = string
8+
default = "c5.xlarge"
9+
}
10+
11+
variable "ssh_username" {
12+
type = string
13+
default = "ec2-user"
14+
}
15+
16+
variable "github_runner_version" {
17+
type = string
18+
default = "2.308.0"
19+
}

.github/workflows/e2e-runner.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Trigger on Comment
2+
on:
3+
issue_comment:
4+
types: [created]
5+
permissions:
6+
contents: read
7+
issues: read
8+
pull-requests: read
9+
statuses: write
10+
jobs:
11+
start-runner:
12+
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/run e2e')
13+
uses: ./.github/workflows/runner-start.yml
14+
secrets: inherit
15+
with:
16+
relayer_version: ${{ vars.relayer_version == '' && '0.1.0-alpha.7' || vars.relayer_version }}
17+
e2e:
18+
name: E2E tests
19+
runs-on: self-hosted
20+
needs: start-runner
21+
steps:
22+
- name: Get PR branch
23+
uses: xt0rted/pull-request-comment-branch@v2
24+
id: comment-branch
25+
- name: Set latest commit status as pending
26+
uses: myrotvorets/set-commit-status-action@master
27+
with:
28+
sha: ${{ steps.comment-branch.outputs.head_sha }}
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
status: pending
31+
- name: Checkout PR branch
32+
uses: actions/checkout@v3
33+
with:
34+
ref: ${{ steps.comment-branch.outputs.head_ref }}
35+
36+
- name: Set up Go 1.21
37+
uses: actions/setup-go@v4
38+
with:
39+
go-version: 1.21
40+
41+
- name: Run e2e tests
42+
run: make e2e
43+
44+
- name: Set latest commit status as ${{ job.status }}
45+
uses: myrotvorets/set-commit-status-action@master
46+
if: always()
47+
with:
48+
sha: ${{ steps.comment-branch.outputs.head_sha }}
49+
token: ${{ secrets.GITHUB_TOKEN }}
50+
status: ${{ job.status }}
51+
stop-runner:
52+
uses: ./.github/workflows/runner-stop.yml
53+
secrets: inherit
54+
with:
55+
label: ${{ needs.start-runner.outputs.label }}
56+
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
57+
needs:
58+
- start-runner
59+
- e2e

.github/workflows/runner-start.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
relayer_version:
5+
description: "Relayer version"
6+
type: string
7+
default: "0.1.0-alpha.7"
8+
required: true
9+
outputs:
10+
label:
11+
description: "Label of the self-hosted runner"
12+
value: ${{ jobs.runner-start.outputs.label }}
13+
ec2-instance-id:
14+
description: "ID of the EC2 instance"
15+
value: ${{ jobs.runner-start.outputs.ec2-instance-id }}
16+
jobs:
17+
runner-start:
18+
name: Start runner
19+
runs-on: ubuntu-latest
20+
outputs:
21+
label: ${{ steps.start.outputs.label }}
22+
ec2-instance-id: ${{ steps.start.outputs.ec2-instance-id }}
23+
steps:
24+
- name: Configure AWS credentials
25+
uses: aws-actions/configure-aws-credentials@v3
26+
with:
27+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
28+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
29+
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
30+
- name: Get aws ami id built by packer
31+
id: ami-id
32+
run: |
33+
ami_id=$(aws ec2 describe-images \
34+
--filters "Name=tag:Name,Values=github-runner" "Name=tag:Project,Values=IBC" "Name=tag:ManagedBy,Values=Packer" \
35+
--query 'Images[*].[ImageId]' \
36+
--output text --max-items 1)
37+
echo "AMI_ID=$ami_id" >> $GITHUB_OUTPUT
38+
- uses: actions/checkout@v3
39+
- name: Start EC2 instance
40+
id: start
41+
uses: machulav/ec2-github-runner@v2
42+
with:
43+
mode: start
44+
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
ec2-image-id: ${{ steps.ami-id.outputs.AMI_ID }}
46+
ec2-instance-type: c5.2xlarge
47+
subnet-id: subnet-f1fcd4df
48+
security-group-id: sg-03cb8034e27e1caeb
49+
aws-resource-tags: >
50+
[
51+
{"Key": "Name", "Value": "ec2-github-runner"},
52+
{"Key": "Repository", "Value": "${{ github.repository }}"},
53+
{"Key": "Project", "Value": "IBC"}
54+
]
55+
pre-runner-script: |
56+
./build.sh ${{ inputs.relayer_version }}

.github/workflows/runner-stop.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
label:
5+
description: "Label of the self-hosted runner"
6+
type: string
7+
required: true
8+
ec2-instance-id:
9+
description: "ID of the EC2 instance"
10+
type: string
11+
required: true
12+
jobs:
13+
runner-stop:
14+
name: Stop self-hosted EC2 runner
15+
runs-on: self-hosted
16+
steps:
17+
- name: Configure AWS credentials
18+
uses: aws-actions/configure-aws-credentials@v3
19+
with:
20+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
21+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
22+
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
23+
- name: Stop EC2 runner
24+
uses: machulav/ec2-github-runner@v2
25+
with:
26+
mode: stop
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
label: ${{ inputs.label }}
29+
ec2-instance-id: ${{ inputs.ec2-instance-id }}

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ optimize-build:
6262
gobuild:
6363
go build .
6464

65+
e2e:
66+
@echo "Running e2e tests..."
67+
go test -v ./test/e2e -testify.m TestE2E_all
68+
6569
e2e-demo-setup:
6670
@echo "Configuring e2e demo..."
6771
export PRESERVE_DOCKER=true && \

0 commit comments

Comments
 (0)