Skip to content

Commit

Permalink
feat: get relayer version from comment, fix: ami build
Browse files Browse the repository at this point in the history
  • Loading branch information
debendraoli committed Sep 20, 2023
1 parent 26bcb55 commit 3b22f05
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 36 deletions.
22 changes: 11 additions & 11 deletions .github/packer/builder.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -euof
set -euof pipefail

install_deps() {
sudo yum install -y git docker make tar perl-Digest-SHA libicu
Expand All @@ -13,24 +13,22 @@ configure_docker() {

build_goloop_images() {
git clone https://github.com/icon-project/goloop.git
cd goloop
make goloop-image
make goloop-icon-image
make goloop-image -C goloop
make goloop-icon-image -C goloop
docker tag goloop iconloop/goloop-icon
rm -rf ../goloop
}

pull_archway_images() {
docker pull archwaynetwork/archwayd:sha-8f53ac8
}

configure_relayer() {
mv /tmp/Dockerfile .
cat > build.sh <<EOF
cat <<EOT > ~/build.sh
#!/bin/sh
docker build -t relayer --build-args VERSION=$1 .
EOF
chmod +x build.sh
version=\$(echo "\$VERSION" | sed 's/v//')
docker build -t relayer --build-arg VERSION=\$version .
EOT
chmod +x ~/build.sh
}

build_services() {
Expand All @@ -40,7 +38,9 @@ build_services() {
}

cleanup(){
sudo yum uninstall -y git make tar perl-Digest-SHA
rm -rf goloop
sudo yum remove -y tar perl-Digest-SHA
sudo yum clean all
}

install_deps
Expand Down
12 changes: 6 additions & 6 deletions .github/packer/builds.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ build {
name = local.name
sources = ["source.amazon-ebs.linux"]

provisioner "shell" {
execute_command = "sudo -S bash -c '{{ .Path }}'"
script = "${path.root}/builder.sh"
}

provisioner "file" {
source = "${path.root}/relayer.Dockerfile"
destination = "/tmp/Dockerfile"
destination = "Dockerfile"
}

provisioner "shell" {
execute_command = "sudo -S sh -c '{{ .Path }}'"
script = "${path.root}/builder.sh"
}
}
20 changes: 15 additions & 5 deletions .github/workflows/e2e-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ permissions:
pull-requests: read
statuses: write
jobs:
start-runner:
parse-args:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/run e2e')
runs-on: ubuntu-latest
steps:
- name: Parse relayer version
id: relay
run: |
echo "RELAYER_VERSION=$(echo ${{ github.event.comment.body }} | sed -n 's/.*\/run e2e \(.*\)/\1/p')" >> $GITHUB_ENV
outputs:
relayer_version: ${{ steps.relay.outputs.RELAYER_VERSION }}
start-runner:
needs: parse-args
uses: ./.github/workflows/runner-start.yml
secrets: inherit
with:
relayer_version: ${{ vars.relayer_version == '' && '0.1.0-alpha.7' || vars.relayer_version }}
relayer_version: ${{ needs.parse-args.outputs.relayer_version }}
e2e:
name: E2E tests
runs-on: self-hosted
runs-on: ${{ needs.start-runner.outputs.label }}
needs: start-runner
steps:
- name: Get PR branch
Expand All @@ -39,7 +49,7 @@ jobs:
go-version: 1.21

- name: Run e2e tests
run: make e2e
run: ./scripts/execute-test.sh --clean --use-docker --build-ibc --build-xcall --xcall-branch main --test e2e

- name: Set latest commit status as ${{ job.status }}
uses: myrotvorets/set-commit-status-action@master
Expand All @@ -56,4 +66,4 @@ jobs:
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
needs:
- start-runner
- e2e
- e2e
53 changes: 53 additions & 0 deletions .github/workflows/packer-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
push:
branches:
- main
paths:
- ".github/packer/*"

jobs:
start-runner:
uses: ./.github/workflows/runner-start.yml
secrets: inherit
build:
needs: start-runner
runs-on: ${{ needs.start-runner.outputs.label }}
defaults:
run:
working-directory: ./.github/packer
env:
PRODUCT_VERSION: latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Build
uses: hashicorp/setup-packer@main
with:
version: ${{ env.PRODUCT_VERSION }}
- name: Run `packer init`
id: init
run: "packer init ."
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Run `packer validate`
id: validate
run: "packer validate ."
- name: Build and Publish AMI
run: packer build -color=false .
stop-runner:
uses: ./.github/workflows/runner-stop.yml
secrets: inherit
with:
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
needs:
- start-runner
- build
18 changes: 7 additions & 11 deletions .github/workflows/runner-start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
relayer_version:
description: "Relayer version"
type: string
default: "0.1.0-alpha.7"
required: true
outputs:
label:
description: "Label of the self-hosted runner"
Expand Down Expand Up @@ -36,21 +34,19 @@ jobs:
--output text --max-items 1)
echo "AMI_ID=$ami_id" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
- id: relay
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: icon-project/ibc-relay
- name: Start EC2 instance
id: start
uses: machulav/ec2-github-runner@v2
uses: machulav/ec2-github-runner
with:
mode: start
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GH_RUNNER_PAT }}
ec2-image-id: ${{ steps.ami-id.outputs.AMI_ID }}
ec2-instance-type: c5.2xlarge
subnet-id: subnet-f1fcd4df
security-group-id: sg-03cb8034e27e1caeb
aws-resource-tags: >
[
{"Key": "Name", "Value": "ec2-github-runner"},
{"Key": "Repository", "Value": "${{ github.repository }}"},
{"Key": "Project", "Value": "IBC"}
]
pre-runner-script: |
./build.sh ${{ inputs.relayer_version }}
./build.sh ${{ inputs.relayer_version == '' && steps.relay.outputs.release || inputs.relayer_version }}
4 changes: 2 additions & 2 deletions .github/workflows/runner-stop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
uses: machulav/ec2-github-runner@v2
with:
mode: stop
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GH_RUNNER_PAT }}
label: ${{ inputs.label }}
ec2-instance-id: ${{ inputs.ec2-instance-id }}
ec2-instance-id: ${{ inputs.ec2-instance-id }}
6 changes: 5 additions & 1 deletion scripts/execute-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ if [ "$clean" = "true" ]; then
clean_contracts
fi

if [ "$use_docker" = "true" ]; then
make build-builder-img & wait
fi

if [ "$build_ibc" = "true" ]; then
echo "building IBC contracts..."
if [ "$use_docker" = "true" ]; then
Expand Down Expand Up @@ -121,4 +125,4 @@ case "$test" in
echo "Error: Unknown test type '$test'."
exit 1
;;
esac
esac

0 comments on commit 3b22f05

Please sign in to comment.