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

ci: automatically creates an EC2 instance for builds #220

Merged
merged 156 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 154 commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
ed03dfa
ci: run on aws
mrq1911 Apr 6, 2021
d8586e5
ci: run always
mrq1911 Apr 6, 2021
67f58df
branching draft - deploy EC2 from CI
Apr 15, 2021
de43fe0
commands inside of workflow
fakirAyoub Apr 15, 2021
6708362
use terraform
fakirAyoub Apr 15, 2021
ddd5c92
go to the right directory for terraform
fakirAyoub Apr 15, 2021
549f89e
where am I
fakirAyoub Apr 15, 2021
57c27db
go to the right directory for terraform
fakirAyoub Apr 15, 2021
cb405a9
node error
fakirAyoub Apr 15, 2021
5b56836
node error
fakirAyoub Apr 15, 2021
201021a
checkout action
fakirAyoub Apr 15, 2021
919504c
switch lib
fakirAyoub Apr 15, 2021
9f4bcd3
setup terraform CLI
fakirAyoub Apr 15, 2021
15acaff
setup terraform CLI
fakirAyoub Apr 15, 2021
cb65946
setup terraform CLI
fakirAyoub Apr 15, 2021
a68e993
where am I
fakirAyoub Apr 15, 2021
8b0f541
infra dir
fakirAyoub Apr 15, 2021
806f0d2
infra dir
fakirAyoub Apr 15, 2021
58ec74f
infra dir
fakirAyoub Apr 15, 2021
fc89f5e
infra dir
fakirAyoub Apr 15, 2021
5fcfc4e
apply infra
fakirAyoub Apr 15, 2021
1698162
separate run commands
fakirAyoub Apr 15, 2021
6dc72bb
separate run commands
fakirAyoub Apr 15, 2021
ab2c5df
separate run commands
fakirAyoub Apr 15, 2021
45e2856
workspace select
fakirAyoub Apr 15, 2021
6076d71
workspace select
fakirAyoub Apr 15, 2021
484b3c9
fix terraform file
fakirAyoub Apr 15, 2021
72cc324
using ssh key
fakirAyoub Apr 16, 2021
8d12ff7
adding security group
fakirAyoub Apr 16, 2021
a9a7e8c
add key
fakirAyoub Apr 16, 2021
8eb5960
add connection
fakirAyoub Apr 16, 2021
8dc4982
fix pem path
fakirAyoub Apr 16, 2021
b6064df
add host
fakirAyoub Apr 16, 2021
cebb52d
add key
fakirAyoub Apr 16, 2021
4e668c3
add key
fakirAyoub Apr 16, 2021
d2fbcee
remove agent
fakirAyoub Apr 16, 2021
529db61
fix paths
fakirAyoub Apr 16, 2021
f719a75
remove key
fakirAyoub Apr 16, 2021
d232117
with custom AMI
fakirAyoub Apr 16, 2021
edd701a
key name
fakirAyoub Apr 16, 2021
8a5da9c
test
fakirAyoub Apr 16, 2021
e4ead60
new AMI image
fakirAyoub Apr 17, 2021
b1fba30
add plan
fakirAyoub Apr 17, 2021
2851e18
add plan
fakirAyoub Apr 17, 2021
faddf06
add ssh type
fakirAyoub Apr 17, 2021
31b4f13
user data
fakirAyoub Apr 17, 2021
ea9f5b5
user data
fakirAyoub Apr 17, 2021
bede23b
agent to false
fakirAyoub Apr 17, 2021
ff6cece
bootstrap runner
fakirAyoub Apr 17, 2021
3a70d8c
variable name
fakirAyoub Apr 17, 2021
a7cde01
with user data
fakirAyoub Apr 17, 2021
e3be90e
test
fakirAyoub Apr 17, 2021
bb70485
wrap
fakirAyoub Apr 17, 2021
799850b
aws image
fakirAyoub Apr 20, 2021
0d8ae19
update access to instance
fakirAyoub Apr 20, 2021
a4b0598
access token
fakirAyoub Apr 20, 2021
760ef23
fix path
fakirAyoub Apr 20, 2021
3b68a61
runner image
fakirAyoub Apr 20, 2021
e9fce81
runner not blocking
fakirAyoub Apr 20, 2021
ca99a80
runner not blocking
fakirAyoub Apr 20, 2021
21defee
runner not blocking
fakirAyoub Apr 20, 2021
3cca767
runner not blocking
fakirAyoub Apr 20, 2021
3c36ac8
run bash
fakirAyoub Apr 20, 2021
27da1fb
run bash
fakirAyoub Apr 20, 2021
de9c1c0
run
fakirAyoub Apr 20, 2021
fb95355
run
fakirAyoub Apr 20, 2021
9788702
run
fakirAyoub Apr 20, 2021
a3bae12
run
fakirAyoub Apr 20, 2021
fcf2655
run
fakirAyoub Apr 21, 2021
24b9247
add run conf
fakirAyoub Apr 21, 2021
5fd8620
run conf
fakirAyoub Apr 21, 2021
dc869eb
run conf
fakirAyoub Apr 21, 2021
5aef88a
run build on the newly created instance
fakirAyoub Apr 21, 2021
de81a23
run build on the newly created instance
fakirAyoub Apr 21, 2021
143734e
sleep between steps
fakirAyoub Apr 21, 2021
8d0b2e0
sleep between steps
fakirAyoub Apr 21, 2021
fbcb1fe
runs on aws
fakirAyoub Apr 21, 2021
08d05ad
runs on aws
fakirAyoub Apr 21, 2021
0ba4dfc
runs on aws
fakirAyoub Apr 21, 2021
f5f5311
check build
fakirAyoub Apr 21, 2021
448199c
check build
fakirAyoub Apr 21, 2021
c2fd57e
check build
fakirAyoub Apr 21, 2021
4c80e4a
check build
fakirAyoub Apr 21, 2021
2ad7286
check build
fakirAyoub Apr 21, 2021
529f5cc
check build
fakirAyoub Apr 21, 2021
717a8b8
check build
fakirAyoub Apr 21, 2021
eb9fc42
needs
fakirAyoub Apr 21, 2021
1ee05a0
needs
fakirAyoub Apr 21, 2021
160ae10
needs
fakirAyoub Apr 21, 2021
16358c9
needs
fakirAyoub Apr 21, 2021
a7ef306
needs
fakirAyoub Apr 21, 2021
00e3dd9
needs
fakirAyoub Apr 21, 2021
1e55137
ref
fakirAyoub Apr 21, 2021
1cc7285
ref
fakirAyoub Apr 21, 2021
db67a26
dynamic branch name
fakirAyoub Apr 21, 2021
9506534
dynamic branch name
fakirAyoub Apr 21, 2021
3d50ddd
dynamic branch name
fakirAyoub Apr 21, 2021
98d1f6f
dynamic branch name
fakirAyoub Apr 21, 2021
12baf18
dynamic branch name
fakirAyoub Apr 21, 2021
5af110a
dynamic branch name
fakirAyoub Apr 21, 2021
be06e34
dynamic branch name
fakirAyoub Apr 21, 2021
470bf77
dynamic branch name
fakirAyoub Apr 21, 2021
a3e204a
dynamic branch name
fakirAyoub Apr 21, 2021
c299998
dynamic branch name
fakirAyoub Apr 21, 2021
23ea17f
dynamic branch name
fakirAyoub Apr 21, 2021
73b403a
dynamic branch name
fakirAyoub Apr 21, 2021
f5a7c88
dynamic branch name
fakirAyoub Apr 21, 2021
9cc523e
dynamic branch name
fakirAyoub Apr 21, 2021
f68d948
dynamic branch name
fakirAyoub Apr 21, 2021
00f28d6
dynamic branch name
fakirAyoub Apr 21, 2021
ef6c8dd
with destroy
fakirAyoub Apr 21, 2021
db3478e
with destroy
fakirAyoub Apr 21, 2021
2029c15
with destroy
fakirAyoub Apr 21, 2021
29de472
with destroy
fakirAyoub Apr 21, 2021
5389a47
with destroy
fakirAyoub Apr 21, 2021
1b4c047
with destroy
fakirAyoub Apr 21, 2021
a4cd496
with destroy
fakirAyoub Apr 21, 2021
aa7e528
with wait
fakirAyoub Apr 21, 2021
5e73e9b
test destroy
fakirAyoub Apr 21, 2021
61aaebd
test destroy
fakirAyoub Apr 21, 2021
46503aa
test destroy
fakirAyoub Apr 21, 2021
b17d5e5
test destroy
fakirAyoub Apr 21, 2021
833a8a3
variabilise s3 bucket key
fakirAyoub Apr 21, 2021
0340884
trigger
fakirAyoub Apr 21, 2021
54c3f58
trigger
fakirAyoub Apr 21, 2021
1e23c56
trigger
fakirAyoub Apr 21, 2021
004c7a1
trigger
fakirAyoub Apr 21, 2021
30aa2e6
trigger
fakirAyoub Apr 21, 2021
598747d
trigger
fakirAyoub Apr 21, 2021
134ae50
trigger
fakirAyoub Apr 21, 2021
ec3fb0b
trigger
fakirAyoub Apr 21, 2021
0123078
trigger
fakirAyoub Apr 21, 2021
f4b8706
trigger with build
fakirAyoub Apr 22, 2021
0bb3225
trigger with build
fakirAyoub Apr 22, 2021
8cf018d
removed init.sh
mrq1911 Apr 22, 2021
bd294be
☠️ test sabotage
mrq1911 Apr 22, 2021
df00dd5
to hash commit
fakirAyoub Apr 23, 2021
6f4e1ff
Merge branch 'aws-runner' of github.com:galacticcouncil/HydraDX-node …
fakirAyoub Apr 23, 2021
b97fcf4
to hash commit
fakirAyoub Apr 23, 2021
2cc847e
to hash commit
fakirAyoub Apr 23, 2021
68f47cc
to hash commit
fakirAyoub Apr 23, 2021
dcc05b5
to hash commit
fakirAyoub Apr 23, 2021
14ce52d
to hash commit
fakirAyoub Apr 23, 2021
27b4a74
destroy runs anyway
fakirAyoub Apr 23, 2021
c91e418
release
fakirAyoub Apr 23, 2021
4540214
release
fakirAyoub Apr 23, 2021
147b9b2
release
fakirAyoub Apr 23, 2021
1fada07
always run destroy
mrq1911 Apr 23, 2021
4a27d23
Revert "☠️ test sabotage"
mrq1911 Apr 24, 2021
af2a11b
Merge branch 'master' into aws-runner
mrq1911 Apr 25, 2021
6cd0675
merge master
mrq1911 Apr 25, 2021
f2e494f
Revert "merge master"
mrq1911 Apr 25, 2021
36e3f73
merged ci changes from master
mrq1911 Apr 25, 2021
f039eed
new EC2 instance image with git 2.31
fakirAyoub Apr 25, 2021
f57a2f3
remove redundant init
mrq1911 Apr 26, 2021
0bc219a
remove redundant init
mrq1911 Apr 26, 2021
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
100 changes: 94 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
name: Build
mrq1911 marked this conversation as resolved.
Show resolved Hide resolved

name: build-and-deploy
#${GITHUB_REF##*/}
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
pop-runner-instance:
name: create and setup infrastructure for branch
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
EC2_SECRET: ${{ secrets.EC2_PWD }}
S3_BACKEND_KEY_NAME: tf-state-${{ github.sha }}
steps:
- name: checkout code
uses: actions/[email protected]
- name: setup node
uses: actions/setup-node@v2
with:
node-version: '14'
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.25
#- name: Declare some variables
# id: vars
#shell: bash
#run: |
# echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
#echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: rewrite tf state key
id: tf-state-key
working-directory: ./infrastructure
run: sed -i 's/BRANCH_ACTOR_KEY/${{ env.S3_BACKEND_KEY_NAME }}/g' infra.tf
- name: Terraform Init
id: init
working-directory: ./infrastructure
run: terraform init
continue-on-error: false

- name: Terraform plan
id: plan
working-directory: ./infrastructure
run: terraform plan -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}"
continue-on-error: false
- name: Terraform apply
id: apply
working-directory: ./infrastructure
run: terraform apply -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}" -auto-approve
continue-on-error: false
- name: Sleep for 20 seconds
uses: jakejarvis/wait-action@master
with:
time: '20s'

build:
runs-on: ${{ github.sha }}
needs: pop-runner-instance
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -48,3 +96,43 @@ jobs:
name: hydra_dx_runtime.wasm
path: target/release/wbuild/hydra-dx-runtime/hydra_dx_runtime.compact.wasm


destroy-runner-instance:
name: destroy infra
runs-on: ubuntu-latest
needs: build
if: always()
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
EC2_SECRET: ${{ secrets.EC2_PWD }}
S3_BACKEND_KEY_NAME: tf-state-${{ github.sha }}
steps:
- name: checkout code
uses: actions/[email protected]
- name: setup node
uses: actions/setup-node@v2
with:
node-version: '14'
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.25
continue-on-error: false
- name: rewrite tf state key
id: tf-state-key
working-directory: ./infrastructure
run: sed -i 's/BRANCH_ACTOR_KEY/${{ env.S3_BACKEND_KEY_NAME }}/g' infra.tf

- name: Terraform Init
id: init
working-directory: ./infrastructure
run: terraform init
continue-on-error: false

- name: Terraform apply
id: apply
working-directory: ./infrastructure
run: terraform destroy -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}" -auto-approve
continue-on-error: false
7 changes: 7 additions & 0 deletions infrastructure/config_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
curl -o actions-runner-linux-x64-2.277.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.277.1/actions-runner-linux-x64-2.277.1.tar.gz

tar xzf ./actions-runner-linux-x64-2.277.1.tar.gz
TOKEN=$(bash get_token.sh $1)
echo $TOKEN
bash config.sh --url https://github.com/galacticcouncil/HydraDX-node --token $TOKEN --name "$2" --work _work --labels aws
bash ./run.sh
8 changes: 8 additions & 0 deletions infrastructure/get_token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
header1="Accept: application/vnd.github.v3+json"
header2="Authorization: token $1"
#apiUrl="https://api.github.com/orgs/galacticcouncil/actions/runners/registration-token"
apiUrl="https://api.github.com/repos/galacticcouncil/HydraDX-node/actions/runners/registration-token"

cmd="$(curl -X POST -H "$header1" -H "$header2" "$apiUrl" | jq -r '.token')"
echo "${cmd}"
55 changes: 55 additions & 0 deletions infrastructure/infra.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Setting Up Remote State
variable "branch_name" {
description = ""
}
terraform {
required_version = ">= 0.12.24"

backend "s3" {
bucket = "hydradx-ci-backend-state"
key = "BRANCH_ACTOR_KEY"
region = "eu-west-1"
}
}

provider "aws" {
region = var.aws_region
}

variable "aws_region" {
description = "The AWS region to create resources in."
default = "eu-west-1"
}

variable "ec2_pwd" {
description = ""
}


resource "aws_instance" "runner-aws" {
ami = "ami-04f71779ae623a544"
instance_type = "c5ad.4xlarge"
subnet_id = "subnet-0ba99ac0d4aea3dc6"
key_name = "aws-ec2-key"
vpc_security_group_ids = ["sg-05f1a5d51f4d92cae"]

tags = {
Type = "Github_Self_Runner"
}
connection {
type = "ssh"
user = "ubuntu"
host = aws_instance.runner-aws.public_ip
password = var.ec2_pwd
timeout = "3m"
}
provisioner "file" {
source = "run_conf.sh"
destination = "/home/ubuntu/run_conf.sh"
}
provisioner "remote-exec" {
inline = [
"tmux new -d 'bash run_conf.sh ${var.branch_name}'"
]
}
}
5 changes: 5 additions & 0 deletions infrastructure/run_conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
bash_source=$(source /home/ubuntu/config_script.sh)
echo $bash_source
bashrun=$(bash -c "config_script.sh $1 &")
echo $bashrun