Skip to content

Commit f3fbc1e

Browse files
Ramon Medeirosalinefm
Ramon Medeiros
authored andcommitted
Add Github Actions
1 parent 591c737 commit f3fbc1e

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed

.github/scripts/setup_instance.sh

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
DISKS="gcloud compute disks"
6+
IMAGES="gcloud compute images"
7+
INSTANCES="gcloud compute instances"
8+
VMX="https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
9+
DEFAULT_ZONE=us-central1-a
10+
11+
function createDisk() {
12+
# Create disk
13+
#
14+
# $1: disk name
15+
# $2: image project
16+
# $3: image-family
17+
# $4: zone
18+
zone=${4:-$DEFAULT_ZONE}
19+
20+
diskName=$1
21+
${DISKS} create $diskName \
22+
--image-project $2 \
23+
--image-family $3 \
24+
--size 20GB \
25+
--zone $zone
26+
}
27+
28+
function createImage() {
29+
# Create image with nested virtualization
30+
#
31+
# $1: image name
32+
# $2: disk name
33+
# $3: zone
34+
zone=${3:-$DEFAULT_ZONE}
35+
36+
imageName=$1
37+
${IMAGES} create $imageName \
38+
--source-disk $2 \
39+
--source-disk-zone $zone \
40+
--licenses "${VMX}"
41+
}
42+
43+
function createVM() {
44+
# Create VM with nested virtualization
45+
#
46+
# $1: VM name
47+
# $2: image name
48+
# $3: zone
49+
zone=${3:-$DEFAULT_ZONE}
50+
51+
instanceName=$1
52+
${INSTANCES} create $1 \
53+
--zone $zone \
54+
--min-cpu-platform "Intel Haswell" \
55+
--image $2
56+
}
57+
58+
# Entrypoint
59+
#
60+
# $1: vm name
61+
# $2: image project
62+
# $3: image family
63+
# $4: zone
64+
vmName=$1
65+
imageProject=$2
66+
imageFamily=$3
67+
zone=${4:-$DEFAULT_ZONE}
68+
69+
# create disk
70+
diskName=$vmName-disk
71+
createDisk $vmName-disk $imageProject $imageFamily $zone
72+
73+
# create image
74+
imageName=$vmName-image
75+
createImage $imageName $diskName $zone
76+
77+
# create vm
78+
createVM $1 $imageName $zone
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
function get_deps() {
6+
echo $(python3 -c "import yaml;print(' '.join(yaml.load(open('dependencies.yaml'), Loader=yaml.FullLoader)[\"$1\"][\"$2\"]))")
7+
}
8+
9+
10+
# install deps
11+
sudo apt update
12+
sudo apt install -y python3-pip
13+
sudo apt install -y $(get_deps development-deps common)
14+
sudo apt install -y $(get_deps development-deps ubuntu)
15+
16+
sudo apt install -y $(get_deps runtime-deps common)
17+
sudo apt install -y $(get_deps runtime-deps ubuntu | sed 's/python3-cheetah//')
18+
19+
pip3 install -r requirements-UBUNTU.txt
20+
pip3 install -r requirements-dev.txt
21+
22+
# autogen and make
23+
./autogen.sh --system
24+
make

.github/workflows/CI.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: kimchi-CI
2+
on: ["push"]
3+
4+
env:
5+
VM_NAME: ubuntu-${{ github.sha }}
6+
ZONE: us-central1-a
7+
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
8+
WOK_DIR: wok
9+
KIMCHI_DIR: wok/src/wok/plugins/kimchi/
10+
11+
jobs:
12+
run-kimchi-tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
17+
with:
18+
version: '270.0.0'
19+
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
20+
service_account_key: ${{ secrets.GCP_SA_KEY }}
21+
- run: gcloud config set project $PROJECT_ID
22+
23+
- uses: actions/checkout@v2-beta
24+
25+
- name: create instance
26+
run: bash .github/scripts/setup_instance.sh $VM_NAME ubuntu-os-cloud ubuntu-1804-lts
27+
shell: bash
28+
29+
- name: checkout repos
30+
run: |
31+
gcloud compute ssh $VM_NAME --zone=$ZONE --command "git clone https://github.com/kimchi-project/wok"
32+
gcloud compute ssh $VM_NAME --zone=$ZONE --command "git clone https://github.com/$GITHUB_REPOSITORY $KIMCHI_DIR"
33+
gcloud compute ssh $VM_NAME --zone=$ZONE --command "cd $KIMCHI_DIR; git checkout $GITHUB_SHA"
34+
shell: bash
35+
36+
- name: setup wok deps
37+
run: |
38+
gcloud compute ssh $VM_NAME --zone=$ZONE --command "cd $WOK_DIR; bash .github/scripts/setup_wok_ubuntu.sh"
39+
shell: bash
40+
41+
- name: setup kimchi deps
42+
run: gcloud compute ssh $VM_NAME --zone=$ZONE --command "cd $KIMCHI_DIR; bash .github/scripts/setup_kimchi_ubuntu.sh"
43+
shell: bash
44+
45+
- name: run tests
46+
run: gcloud compute ssh $VM_NAME --zone=$ZONE --command "cd $KIMCHI_DIR; sudo make check-local; sudo make check"
47+
shell: bash
48+
49+
- name: Cleanup instance
50+
if: always()
51+
run: |
52+
gcloud compute instances delete ${VM_NAME} --delete-disks=all --zone=$ZONE -q || true
53+
gcloud compute images delete ${VM_NAME}-image -q || true
54+
gcloud compute disks delete ${VM_NAME}-disk --zone=$ZONE -q || true
55+
shell: bash

docs/CI.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# How to setup Kimchi CI
2+
3+
Due to nested virtualization requirements, most of CI tools does not offer the minimum requirement to test kimchi. To solve this, we have an integration with [Google Cloud](https://cloud.google.com/), which create an instance and trigger the tests.
4+
5+
# Create a service account in GCP
6+
7+
To run the tests, its necessary to create a service account with the following iam roles:
8+
9+
* `roles/iam.serviceAccountUser`
10+
* `roles/compute.admin`
11+
12+
Here is a script to help
13+
```
14+
# create account
15+
$ gcloud iam service-accounts create [SA-NAME] \
16+
--description "[SA-DESCRIPTION]" \
17+
--display-name "[SA-DISPLAY-NAME]"
18+
19+
# create the key to be store as a secret
20+
$ gcloud iam service-accounts keys create ~/key.json \
21+
--iam-account [SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com
22+
23+
# add iam roles
24+
$ gcloud projects add-iam-policy-binding [PROJECT-ID] --member=serviceAccount:[SA-EMAIL] --role=roles/iam.serviceAccountUser
25+
26+
$ gcloud projects add-iam-policy-binding [PROJECT-ID] --member=serviceAccount:[SA-EMAIL] --role=roles/compute.admin
27+
```
28+
29+
# Setting up secrets
30+
31+
The code for the CI is already at our repo, you just need to set some Github Actions Secrets, the procedure is described here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets
32+
33+
1) Create a secret named `GCP_PROJECT` with the project ID
34+
2) Create a secret named `GCP_SA_EMAIL` with the service account email
35+
3) Create a secret named `GCP_SA_KEY` with the service account json with base64: `cat my-key.json | base64`
36+
37+
# Testing the CI
38+
Create a PR to see if the PR works

0 commit comments

Comments
 (0)