Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
288f53c
Updated runs-on to self-hosted,.
dannymartinm Nov 29, 2021
a48a7e5
Updated runs-on jobs to self-hosted.
dannymartinm Nov 29, 2021
6245235
Updated runs-on matrix
dannymartinm Nov 29, 2021
c636ff0
Updated runs-on matrix, cache pip
dannymartinm Nov 29, 2021
23ae887
added mkdir hostedtoolcache
dannymartinm Nov 29, 2021
385d5d8
commented mkdir hostedtoolcache
dannymartinm Nov 29, 2021
5b432cb
removed mkdir hostedtoolcache
dannymartinm Nov 29, 2021
26f6887
removed -name var
dannymartinm Nov 29, 2021
b6ad39e
Updated runs-on matrix values
dannymartinm Nov 30, 2021
01b36de
Added Install Docker step
dannymartinm Nov 30, 2021
a5189e7
Install apt-get
dannymartinm Nov 30, 2021
7513e48
Updated docker installation
dannymartinm Nov 30, 2021
b520505
Added CIBW_BEFORE_ALL_LINUX docker install
dannymartinm Nov 30, 2021
116e67a
Fixed format issue
dannymartinm Nov 30, 2021
0855378
Removed sudo from CIBW_BEFORE_ALL_LINUX command
dannymartinm Nov 30, 2021
d83e614
Added version and yum to docker-ce
dannymartinm Nov 30, 2021
dc81f4f
Updatrd CIBW_BEFORE_ALL_LINUX
dannymartinm Nov 30, 2021
57e40a3
Removed CIBW_BEFORE_ALL_LINUX
dannymartinm Nov 30, 2021
aff96da
Removed matrix variable and added self-hosted instead.
dannymartinm Nov 30, 2021
306c35f
Removed self-hosteed from matrix wheels
dannymartinm Nov 30, 2021
3e85be2
Updated python_tests to runs-on self-hosted runner.
dannymartinm Dec 1, 2021
b6b87cc
Removed ubuntu,macos and windows from matrix for testing self-hosted …
dannymartinm Dec 1, 2021
30b4bfe
Included 'self' in Run test basic unix if condition.
dannymartinm Dec 1, 2021
798a0ec
Testing py36 only in self-hosted runner.
dannymartinm Dec 1, 2021
c7dccbb
Added ubuntu-latest in matrix
dannymartinm Dec 1, 2021
f8bacc9
Testing with windows-latest os
dannymartinm Dec 1, 2021
0ed2b6c
Incremented tox nodes to 8
dannymartinm Dec 1, 2021
583efdc
runs-on ubuntu-latest
dannymartinm Dec 1, 2021
f4997b5
Reduced tox nodes to 4
dannymartinm Dec 1, 2021
6d8b7c3
Added Dockerfile, entrypoint and docker-compose file to create the se…
dannymartinm Dec 7, 2021
7628139
Added github-actions-pod yml file with dind and local beam-ga image.
dannymartinm Dec 10, 2021
e2c0d6e
Added command to install brew on MacOS
dannymartinm Dec 13, 2021
40773f4
Set brew command to PATH in MacOS.
dannymartinm Dec 13, 2021
8e578ce
Updated Dockerfile for having the docker.sock in the volume. Added gi…
dannymartinm Dec 15, 2021
d219432
Added k8s github-actions-deployment yml file and Licensed message to …
dannymartinm Dec 16, 2021
76034b1
Added k8s dind pod attempt.
dannymartinm Dec 16, 2021
077472f
Included Fer's java_tests changes.
dannymartinm Dec 17, 2021
ac692fe
Beam 12812 githubactions (#4)
GiomarWize Dec 17, 2021
645249f
Added branch beam-12812-githubactions to push and pull events.
dannymartinm Dec 17, 2021
b725431
GCC dependency error fixed (#5)
elink21 Dec 20, 2021
87813b0
Added branch beam-12812-githubactions to push and pull events in go_t…
dannymartinm Dec 20, 2021
def5d8c
Added branch beam-12812-githubactions name into the checkout ref.
dannymartinm Dec 20, 2021
00389b6
Removed branch beam-12812-githubactions name from push&pull triggers …
dannymartinm Dec 20, 2021
b64ab22
Added macos and windows latest to run py38 tests.
dannymartinm Dec 23, 2021
c78fb4e
Added py37 tests.
dannymartinm Dec 23, 2021
c5124b6
tox workers set to 6
dannymartinm Dec 23, 2021
6b18cd1
Testing py37 only in ubuntu,macos and windows.
dannymartinm Dec 23, 2021
0943c70
Added pip upgrade tox. Testing py37 only in windows.
dannymartinm Dec 23, 2021
8eafcec
Added pip upgrade only for windows os
dannymartinm Dec 23, 2021
62a9457
Remove sudo from pip upgrade wOS
dannymartinm Dec 23, 2021
759f856
Single pip install if not wOS
dannymartinm Dec 23, 2021
e363dcc
Added py versions for testing in all the versions. Commented windows …
dannymartinm Dec 23, 2021
54c16ba
Kubernetes vertical and horizontal pod autoscaling files added. Inclu…
dannymartinm Dec 23, 2021
6ab41e5
Commented Run test basic windows step to run the rest of the steps.
dannymartinm Dec 27, 2021
2835975
Running on windowsOS only and reduced pytest nodes to 2.
dannymartinm Dec 27, 2021
2b78c01
Using ubuntu-latest for testing winOS
dannymartinm Dec 27, 2021
8bde978
Using ubuntu-latest for testing winOS
dannymartinm Dec 27, 2021
4a056a5
Added matrix.os to run windows os
dannymartinm Dec 27, 2021
529d748
Added windows-latest in runs-on
dannymartinm Dec 27, 2021
fbeb771
Updated runs-on
dannymartinm Dec 27, 2021
8d0fb50
Updated runs-on and matrix.os
dannymartinm Dec 27, 2021
b507ba0
Updated build_playground_backend.yml, build_playground_frontend.yml a…
dannymartinm Dec 27, 2021
73ed95c
Self hosted winwos
dannymartinm Dec 27, 2021
388c76a
Updated build_wheels.yml runs-on step
dannymartinm Dec 28, 2021
cad12dd
Install dependencies step added in build_playground_backend.yml
dannymartinm Dec 28, 2021
ceb91df
Updated runs-on to run over the matrix.os array including self-hosted…
dannymartinm Dec 28, 2021
6659e8e
Added workflow run when pushing to 'beam-12812-githubactions' branch …
dannymartinm Dec 28, 2021
0efca1f
Fixed typo in matrix.os runs-on variable. Added Install Java step in …
dannymartinm Dec 28, 2021
77f29ff
Added Install py3 venv step in local_env_tests.yml
dannymartinm Dec 28, 2021
8cc396a
Fixed Install py3 venv command in local_env_tests
dannymartinm Dec 28, 2021
24671af
Removed brew install commands in build_wheels
dannymartinm Dec 28, 2021
a8c56e6
Remove Install build esentials from go_tests.yml as the current Docke…
dannymartinm Dec 28, 2021
9d4ce0e
Updated Dockerfile of the linux self-hosted runner (#6)
GiomarWize Dec 29, 2021
6c1d75c
Updated entrypoint.sh to scapping GITHUB_TOKEN variable that was caus…
dannymartinm Jan 5, 2022
1a17a5d
Added Clean GitHub workspace step in python_tests.yml for every check…
dannymartinm Jan 5, 2022
d869c0f
Added if conditions to remove only if the directory exists and os is …
dannymartinm Jan 5, 2022
7e9ca71
Testing Clean workspace for Windows
dannymartinm Jan 5, 2022
943e7cf
Testing Clean workspace for Windows and removing if condiiton
dannymartinm Jan 5, 2022
d5dd83a
Added privileges to remove GitHub Workspace command.
dannymartinm Jan 5, 2022
df9d980
Added * to remove GitHub Workspace files
dannymartinm Jan 5, 2022
558d731
Added Clear GitHub Workspace step for Check GCP Variables job.
dannymartinm Jan 6, 2022
6acaab0
Added Clean Workspace for Build python source distribution job.
dannymartinm Jan 6, 2022
8b91eb3
Added Clean Workspace step in all the workflows.yml files
dannymartinm Jan 6, 2022
a5c3a50
Included branch name to trigger all the workflows at the same time wh…
dannymartinm Jan 6, 2022
0cd1abc
Updated k8s deployment to increase the replicas to 5
dannymartinm Jan 6, 2022
825bfe1
Updated hpa name to match linux pods.
dannymartinm Jan 10, 2022
19d403e
Tox nodes set to 4. Removed Install tox windows step ib python_tests.
dannymartinm Jan 10, 2022
55c0c83
Tox nodes set back to 6
dannymartinm Jan 10, 2022
eb14a67
Updated aarch64 to run in self-hosted in build_wheels.
dannymartinm Jan 10, 2022
1915deb
Refactor folders and added README for self-hosted linux runners.
dannymartinm Jan 11, 2022
84bd4fc
Added ubuntu-20.04 tag for self-hosted runs-on specification in workf…
dannymartinm Jan 12, 2022
f44d95d
Added ubuntu-20.04 tag for matrix self-hosted runs-on specification i…
dannymartinm Jan 12, 2022
cec0283
Replaced startsWith condition to contains to check if the Array has t…
dannymartinm Jan 12, 2022
388e2ed
Updated build_wheels name to display the tags in the step name.
dannymartinm Jan 12, 2022
cf86bbe
Updated build_wheels name to display the tags in the step name fromJSON.
dannymartinm Jan 12, 2022
7c33e03
Updated name in build_wheels to display ad filter the matrix os.
dannymartinm Jan 12, 2022
0af0b8b
Updated matrix values to have an array in build_wheels
dannymartinm Jan 12, 2022
7541ce1
Fixed syntax issue in matrix values to have an array in build_wheels
dannymartinm Jan 12, 2022
4996e27
Join matrix name to display it correctly in the Step name.
dannymartinm Jan 12, 2022
89f0d6b
Added empty lines at the end of the files to avoid possible issues.
dannymartinm Jan 12, 2022
525c225
Removed Clean GitHub workspace for windows TODO step.
dannymartinm Jan 12, 2022
684cbbb
Reduced maxReplicas in HorziontalPodAutoscaler yml file.
dannymartinm Jan 12, 2022
ee00734
Updated github-actions version in Dockerfile. Added enable-vertical-p…
dannymartinm Jan 12, 2022
a6b811b
Included master changes in build_playground_frontend.yml file.
dannymartinm Jan 13, 2022
25084b7
Reverted build_playground_frontend.yml file changes
dannymartinm Jan 13, 2022
c51eb29
Included master changes in build_playground_backend.yml to get the la…
dannymartinm Jan 13, 2022
698b141
Included master changes in build_playground_frontend.yml to get the l…
dannymartinm Jan 13, 2022
51b228a
Added privileges to run commands in build_playground_frontend workflow
dannymartinm Jan 13, 2022
9239fe5
Included master changes in java_tests file to get the latest setup go…
dannymartinm Jan 13, 2022
ecdc207
Updated set up go step to include the matrix.os runs-on in java_tests
dannymartinm Jan 13, 2022
ecc2545
Added playground_deploy_examples.yml from master branch and updated t…
dannymartinm Jan 13, 2022
3a14921
Added privileges to mv command.
dannymartinm Jan 13, 2022
3d67aca
Removed beam-12812-githubactions push in workflows.
dannymartinm Jan 13, 2022
e627105
Beam 12812 githubactions (#11)
GiomarWize Jan 13, 2022
f122b71
Merge branch 'master' into beam-12812-githubactions
dannymartinm Jan 13, 2022
f7c04ee
Beam 12812 github actions - Fix whitespace errors (#12)
GiomarWize Jan 13, 2022
2252ecb
Merge branch 'master' into beam-12812-githubactions
dannymartinm Jan 21, 2022
79addbd
Merge branch 'master' into beam-12812-githubactions
dannymartinm Jan 27, 2022
3c92cd2
Updating github actions version and added delete k8s deployment file.
dannymartinm Feb 2, 2022
4e1a7b7
Merge branch 'master' into beam-12812-githubactions
dannymartinm Feb 3, 2022
2b35ac1
Updated entrypoint to register the runner at Organization level inste…
dannymartinm Feb 4, 2022
ad10ec5
Merge branch 'apache:master' into beam-12812-githubactions
dannymartinm Feb 4, 2022
7eea84b
Merge branch 'apache:master' into beam-12812-githubactions
dannymartinm Feb 9, 2022
c2b9173
Added ubuntu self-hosted runner in label_prs workflwo.
dannymartinm Feb 10, 2022
b4a97a9
Merge branch 'master' into beam-12812-githubactions
dannymartinm Feb 11, 2022
c17d6e4
Updated stale workflow in order to run in ubuntu self-hosted runner.
dannymartinm Feb 11, 2022
e69412c
Replaced startWith with contains in Install sha512sum step in build_w…
dannymartinm Feb 12, 2022
b4a946e
Merge branch 'apache:master' into beam-12812-githubactions
dannymartinm Feb 17, 2022
7d444a1
BEAM-12812 - Included Windows workflows changes for self-hosted runne…
dannymartinm Feb 17, 2022
c85cb45
Updated k8s HorizontalPodAutoscaler and README values.
dannymartinm Feb 18, 2022
df0d72e
BEAM-12812 Windows self-hosted runners scripts and documentation (#17)
elink21 Feb 18, 2022
db9baeb
Fixed linter issues in README file.
dannymartinm Feb 18, 2022
cc05032
Renamed root folder from dockerized-gh-actions-runners to gh-actions-…
dannymartinm Feb 18, 2022
6b31620
Merge branch 'master' into beam-12812-githubactions
dannymartinm Mar 3, 2022
c8c3b29
Updated new master workflows to runs-on self-hosted ubuntu OS. Added …
dannymartinm Mar 3, 2022
9aab7da
Fixing lint issue in yaml FE workflow file.
dannymartinm Mar 3, 2022
f1dbbc2
Added GCP links for the Delete unused self-hosted runners cronjob text.
dannymartinm Mar 3, 2022
89f49ed
Added GCP links for GKE resources and Windows Disk image in README file.
dannymartinm Mar 3, 2022
eb26a7f
Updated GitHub Actions RUNNER_VERSION in Dockerfile.
dannymartinm Mar 9, 2022
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
86 changes: 86 additions & 0 deletions .github/gh-actions-self-hosted-runners/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
# GitHub Actions - Self-hosted Runners
The current GitHub Actions workflows are being tested on multiple operating systems, such as Ubuntu, Windows and MacOS. The way to migrate these runners from GitHub to GCP is by implementing self-hosted runners, so we have started implementing them in both Ubuntu and Windows environments, going with Google Kubernetes Engine and Google Cloud Compute VMs instances respectively.

In addition, we are working on researching the best way to implement the MacOS self-hosted runners.

## Ubuntu
Ubuntu Self-hosted runners are stored in Artifact Registry and implemented using Google Kubernetes Engine with the following specifications:

#### Cluster
* Cluster: [github-actions-linux-runners](https://console.cloud.google.com/kubernetes/clusters/details/us-central1-a/github-actions-linux-runners/details?project=apache-beam-testing)
* Image: [linux-github-actions-runner](https://console.cloud.google.com/artifacts/docker/apache-beam-testing/us-central1/beam-github-actions/linux-github-actions-runner?project=apache-beam-testing)

#### Node
* Machine Type: 2-custom-6-18432
* Disk Size: 100 GB
* CPU: 6 vCPUs
* Memory : 18 GB

#### Pod
* Image: $LOCAL_IMAGE_NAME LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:latest
* CPU: 2
* Memory: 1028 Mi
* Volumes: docker.sock
* Secret env variables: Kubernetes Secrets

#### AutoScaling
* Horizontal Pod Autoscaling
* 5-10 nodes
* HorizontalPodAutoscaler
* Min replicas: 10
* Max replicas: 20
* CPU utilization: 70%
* Vertical Pod Autoscaling: updateMode: "Auto"


## Windows
Windows Virtual machines have the following specifications

#### VM specifications
* Instace Template: _TODO: Add GCP link when final resources are in place._
* Machine Type: n2-standard-2
* Disk Size: 70 GB
* Disk Image: [disk-image-windows-runner](https://console.cloud.google.com/compute/imagesDetail/projects/apache-beam-testing/global/images/disk-image-windows-runner?project=apache-beam-testing)
* CPU: 2 vCPUs
* Memory : 8 GB

#### Instance group settings
* Region: us-west1 (multizone)
* Scale-out metric: 70% of CPU Usage.
* Cooldown period: 300s

#### Notes:
At first glance we considered implementing Windows runners using K8s, however this was not optimal because of the following reasons:

* VS Build tools are required for certain workflows, unfortunately official images that support this dependency are huge in size, reaching 20GB easily which is not an ideal case for k8S management.
* Windows Subsystem For Linux(WSL) is a feature that allows to execute bash scripts inside Windows which removes tech debt by avoiding writing steps in powershell, but this feature is disabled with payload removed in Windows containers.


## Self-Hosted Runners Architecture
![Diagram](diagrams/self-hosted-runners-architecture.png)

## Cronjob - Delete Unused Self-hosted Runners

Depending on the termination event, sometimes the removal script for offline runners is not triggered correctly from inside the VMs or K8s pod, because of that an additional pipeline was created in order to clean up the list of GitHub runners in the group.

This was implemented using a [Cloud Function](https://console.cloud.google.com/functions/details/us-central1/remove-self-hosted-runners-group?env=gen1&project=apache-beam-testing&tab=source) subscribed to a [Pub/Sub](https://console.cloud.google.com/cloudpubsub/topic/detail/remove-runners?referrer=search&project=apache-beam-testing) topic, the topic is triggered through a [Cloud Scheduler](https://console.cloud.google.com/cloudscheduler/jobs/edit/us-central1/runners-clean-up-schedule?project=apache-beam-testing) that is executed once per day, the function consumes a [GitHub API](https://docs.github.com/en/rest/reference/actions#delete-a-self-hosted-runner-from-an-organization) to delete offline self-hosted runners from the organization retrieving the token with its service account to secrets manager.


![Delete Offline Self-hosted Runners](diagrams/self-hosted-runners-delete-function.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
# GitHub Actions - Self-hosted Linux Runners
These folders contain the required resources to deploy the GitHub Actions self-hosted runners for the workflows running in Ubuntu OS.
* /docker
* Dockerfile and entrypoint: Resources needed to create a new self-hosted-runner image.
* docker-compose.yml: In case you would like to test and run the self-hosted runner locally.

* /kubernetes
* Kubernetes files to create the resources needed to deploy the sel-hosted runners.

## Docker

#### How to build a new image and push it to the Artifact Registry?
* Create the image locally

`docker build -t $LOCAL_IMAGE_NAME:TAG .`

* Tag the local image with the GCP repository name

`docker tag $LOCAL_IMAGE_NAME LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:latest`

* Make sure you are authenticated to the gcloud repository

`gcloud auth configure-docker us-central1-docker.pkg.dev`

* Push the tagged image to the repository

`docker push LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:latest`

#### How to run a self-hosted locally?

* Create a `.var.env` file from the `example.var.env` file and replace the corresponding values

* Run the container

`docker-compose up`

* You will be able to see the self-hosted runner in the Settings of your GitHub repository

## Kubernetes
* Configure your Kubernetes local context

`gcloud container clusters get-credentials $CLUSTER_NAME --zone us-central1-a --project $PROJECT-ID`

* Update the `github-actions-secrets.yml` file with its corresponding encrypted in base64 values

`echo $GITHUB_TOKEN | base64`
`echo GITHUB_REPO | base64`

* Replace in `github-actions-deployment.yml` file the `$IMAGE_URL` variable with the corresponding image URL: `LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE`

* In case you would like to create the deployment from scratch, run the `run-k8s-deployment.sh` script to do the Kubernetes deployment in the GKE cluster. Make sure you have the GKE context selected in your local machine

`./run-k8s-deployment.sh`

* Otherwise, apply only the changes. Make sure you have the GKE context selected in your local machine

`kubectl apply -f github-actions-$FILE_NAME.yml`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

FROM ubuntu:20.04

ARG RUNNER_VERSION=2.288.1

RUN apt-get -yqq update
#Install APT packages
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yqq acl aria2 apt-transport-https binutils bison brotli build-essential bzip2 ca-certificates coreutils curl dbus dnsutils dpkg fakeroot file flex fonts-noto-color-emoji ftp gnupg2 haveged imagemagick iproute2 iputils-ping jq lib32z1 libc++-dev libc++abi-dev libcurl4 libgbm-dev libgconf-2-4 libgsl-dev libgtk-3-0 libicu66 libkrb5-3 liblttng-ust0 libmagic-dev libmagickcore-dev libmagickwand-dev libsecret-1-dev libssl1.1 libsqlite3-dev libxss1 locales m4 mediainfo mercurial net-tools netcat openssh-client p7zip-full p7zip-rar parallel pass patchelf pkg-config pollinate python-is-python3 rpm rsync shellcheck sqlite3 ssh sshpass subversion sudo swig telnet texinfo time tk tzdata unzip upx wget xorriso xvfb xz-utils zip zlib1g zsync
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*
RUN useradd -m actions && usermod -aG sudo actions && echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER actions
WORKDIR /home/actions

RUN curl -O -L https://github.com/actions/runner/releases/download/v$RUNNER_VERSION/actions-runner-linux-x64-$RUNNER_VERSION.tar.gz
RUN tar xzf ./actions-runner-linux-x64-$RUNNER_VERSION.tar.gz

COPY --chown=actions:actions entrypoint.sh ./entrypoint.sh

RUN sudo chmod u+x ./entrypoint.sh
RUN curl -fsSL https://get.docker.com -o get-docker.sh
RUN sudo sh get-docker.sh

CMD ["/home/actions/entrypoint.sh"]
ENTRYPOINT ["/bin/bash"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

version: "3.0"
services:
runner:
build: .
entrypoint: ["/home/actions/entrypoint.sh"]
image: $IMAGE_URL:${TAG:-latest}
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
env_file:
- ./var.env
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

sudo chmod 666 /var/run/docker.sock

#escaping env variables to avoid issues in k8s deployment
GITHUB_TOKEN=$(echo "$GITHUB_TOKEN")

registration_url="https://api.github.com/orgs/$ORG_NAME/actions/runners/registration-token"
echo "Requesting registration Org URL at '${registration_url}'"
payload=$(curl -sX POST -H "Authorization: token $GITHUB_TOKEN" ${registration_url})
RUNNER_TOKEN=$(echo $payload | jq '.token' --raw-output)
echo "export RUNNER_TOKEN3=$RUNNER_TOKEN" | sudo tee /etc/bash.bashrc > /dev/null && source /etc/bash.bashrc

./config.sh \
--name $(hostname) \
--token ${RUNNER_TOKEN} \
--url https://github.com/$ORG_NAME \
--work _work \
--unattended \
--replace \
--labels ubuntu-20.04,ubuntu-latest \
--runnergroup ${ORG_RUNNER_GROUP}

remove() {
./config.sh remove --unattended --token "${RUNNER_TOKEN}"
}
trap 'remove; exit 130' INT
trap 'remove; exit 143' TERM
trap 'remove; exit 143' QUIT
trap 'remove; exit 143' ABRT
trap 'remove; exit 0' EXIT

./run.sh "$*" &
wait $!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
# var.env example, please create a var.env file with the corresponding values of the variables
GITHUB_TOKEN=
ORG_NAME=
ORG_RUNNER_GROUP=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
kubectl delete -f github-actions-hpa.yml
kubectl delete -f github-actions-vpa.yml
kubectl delete -f github-actions-secrets.yml
kubectl delete -f github-actions-deployment.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu-runners
labels:
name: github-actions
spec:
selector:
matchLabels:
name: github-actions
replicas: 5
template:
metadata:
labels:
name: github-actions
spec:
containers:
- name: github-actions-ubuntu-runner
image: $IMAGE_URL:latest # replace variable manually
securityContext:
privileged: true
envFrom:
- secretRef:
name: github-actions-secrets
volumeMounts:
- name: docker-sock
mountPath: /var/run/docker.sock
resources:
requests:
memory: "1028Mi"
cpu: "2"
lifecycle:
preStop:
exec:
command: [ "/bin/sh", "-c",'./config.sh remove --unattended --token "${RUNNER_TOKEN}"' ]
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: hpa-github-actions-linux
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ubuntu-runners
minReplicas: 10
maxReplicas: 20
targetCPUUtilizationPercentage: 70
Loading