Skip to content

Commit d1ceda5

Browse files
authored
Merge pull request #15 from github-developer/cleanup
docs: clean up
2 parents 53c4ad7 + 6e01330 commit d1ceda5

4 files changed

Lines changed: 16 additions & 25 deletions

File tree

.github/workflows/cicd.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ on:
1212

1313
env:
1414
GITHUB_REPO: ${{ secrets.REPO }} # Should be a private repository, see https://help.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners
15-
TOKEN: ${{ secrets.TOKEN }} # Personal Access Token used to register and deregister runners. GITHUB_TOKEN isn't good for most use cases because it is only valid for one hour.
15+
TOKEN: ${{ secrets.TOKEN }} # Personal Access Token used to register and deregister runners since GITHUB_TOKEN is only valid for one hour.
1616
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
1717
GKE_CLUSTER: self-hosted-runner-test-cluster
1818
GKE_SECRETS: self-hosted-runner-creds
19-
GCP_REGION: us-west1
19+
GCP_ZONE: us-west1-a
2020
IMAGE: self-hosted-runner
2121

2222
jobs:
@@ -30,10 +30,10 @@ jobs:
3030

3131
# Configure Google Cloud credentials
3232
- name: Configure Google Cloud credentials
33-
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master # until 0.2.0 release is available
33+
uses: GoogleCloudPlatform/github-actions/setup-gcloud@0.1.3
3434
with:
35-
service_account_email: ${{ secrets.GCP_EMAIL }}
3635
service_account_key: ${{ secrets.GCP_KEY }}
36+
project_id: ${{ secrets.GCP_PROJECT }}
3737

3838
# Insert other testing and linting steps here, eg. container analysis (https://cloud.google.com/container-registry/docs/container-analysis)
3939

@@ -55,10 +55,10 @@ jobs:
5555

5656
# Configure Google Cloud credentials
5757
- name: Configure Google Cloud credentials
58-
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master # until 0.2.0 release is available
58+
uses: GoogleCloudPlatform/github-actions/setup-gcloud@0.1.3
5959
with:
60-
service_account_email: ${{ secrets.GCP_EMAIL }}
6160
service_account_key: ${{ secrets.GCP_KEY }}
61+
project_id: ${{ secrets.GCP_PROJECT }}
6262

6363
# Use gcloud CLI to configure docker authentication for subsequent push
6464
- run: |
@@ -71,7 +71,7 @@ jobs:
7171
# Configure Kubernetes
7272
- name: Configure Kubernetes
7373
run: |
74-
gcloud container clusters get-credentials $GKE_CLUSTER --region $GCP_REGION --project $GCP_PROJECT
74+
gcloud container clusters get-credentials $GKE_CLUSTER --zone $GCP_ZONE
7575
7676
# Push the Docker image to Google Container Registry
7777
- name: Publish

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
> An example configuration and usage of GitHub Actions [self hosted runners](https://help.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) on [Anthos GKE](https://cloud.google.com/anthos/gke).
44
5+
![Self Hosted Runner CI/CD ](https://github.com/github-developer/self-hosted-runners-anthos/workflows/.github/workflows/cicd.yml/badge.svg)
6+
57
A Continuous Integration [job](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobs) builds the image and publishes it to Google Container Registry, and a Continuous Deployment job deploys it to Google Kubernetes Engine (GKE). The self hosted runners in this cluster are made available to the GitHub repository configured via the `GITHUB_REPO` environment variable below.
68

7-
⚠️ Note that this use case is considered experimental and _not officially supported by GitHub at this time_. Additionally [it’s recommended](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) not to use self-hosted runners on public repositories for a number of security reasons.
9+
Because a Docker-in-Docker sidecar pod has been used in this project, these self-hosted runners can also run container builds. Though this approach offers build flexibility, it requires a [`privileged` security context](https://github.com/github-developer/self-hosted-runners-anthos/blob/cb2ee160def13ec3fff256ea43804cafe9fb7e20/deployment.yml#L55) and therefore extends the trust boundary to the whole cluster. Extra caution is recommended with this approach or [removing the sidecar](https://github.com/github-developer/self-hosted-runners-anthos/blob/cb2ee160def13ec3fff256ea43804cafe9fb7e20/deployment.yml#L45) if your application doesn’t require container builds.
10+
11+
⚠️ Note that this use case is considered experimental and _not officially supported by GitHub at this time_. Additionally [it’s recommended](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) not to use self-hosted runners on public repositories for a number of security reasons.
812

913
## Setup
1014

@@ -42,15 +46,15 @@ gcloud services enable \
4246
* Create GKE cluster ([docs](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster))
4347

4448
```
45-
gcloud container clusters create self-hosted-runner-test-cluster --region us-west1
49+
gcloud container clusters create self-hosted-runner-test-cluster
4650
```
4751

4852
* Register cluster to the environ [docs](https://cloud.google.com/anthos/docs/setup/cloud#gcloud)
4953
```
5054
gcloud container hub memberships register self-hosted-anthos-membership \
51-
--project=self-hosted-runner-test-897234 \
52-
--gke-uri=https://container.googleapis.com/v1/projects/self-hosted-runner-test-897234/locations/us-west1/clusters/self-hosted-runner-test-cluster \ #
53-
--service-account-key-file=/path-to/service-account-key.json
55+
--project=self-hosted-runner-test-myid \
56+
--gke-uri=https://container.googleapis.com/v1/projects/self-hosted-runner-test-myid/locations/us-west1/clusters/self-hosted-runner-test-cluster \
57+
--service-account-key-file=/path-to/service-account-key.json
5458
```
5559

5660
* Get the credentails for this cluster
@@ -68,7 +72,6 @@ kubectl create secret generic self-hosted-runner-creds \
6872

6973
* Set these as secrets in your GitHub repository:
7074
* `GCP_PROJECT`: ID of your Google Cloud Platform project, eg. `self-hosted-runner-test-897234`
71-
* `GCP_EMAIL`: Service Account email, eg. `runner-admin@self-hosted-runner-test.iam.gserviceaccount.com`
7275
* `GCP_KEY`: Download your [Service Account JSON credentials](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) and Base64 encode them, eg. output of `cat ~/path/to/my/credentials.json | base64`
7376
* `TOKEN`: Personal Access Token. From the [documentation](https://developer.github.com/v3/actions/self_hosted_runners/), "Access tokens require `repo scope` for private repos and `public_repo scope` for public repos".
7477

script/setup.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

startup.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
#!/bin/bash
22

3-
# Remove runner upon receiving an EXIT signal
4-
function remove_runner {
5-
echo "\nCaught EXIT signal. Removing runner and exiting.\n"
6-
REMOVE_TOKEN=$(curl --data "" -H "Authorization: Bearer $TOKEN" https://api.github.com/repos/$GITHUB_REPO/actions/runners/remove-token | jq -r '.token')
7-
./config.sh remove --token $REMOVE_TOKEN
8-
exit $?
9-
}
10-
11-
# Watch for EXIT signal to be able to shut down gracefully
12-
trap remove_runner EXIT
13-
143
# Generate
154
CONFIG_TOKEN=$(curl --data "" --header "Authorization: Bearer $TOKEN" https://api.github.com/repos/$GITHUB_REPO/actions/runners/registration-token | jq -r '.token')
165

0 commit comments

Comments
 (0)