Skip to content

Commit

Permalink
reset
Browse files Browse the repository at this point in the history
Signed-off-by: Collin McNeese <collinmcneese@github.com>
  • Loading branch information
collinmcneese committed Mar 23, 2024
0 parents commit 4bdb447
Show file tree
Hide file tree
Showing 19 changed files with 788 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @collinmcneese
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: "docker"
directory: "/docker"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
# This is the name of your group, it will be used in PR titles and branch names
actions-deps:
# A pattern can be...
patterns:
- "*"
82 changes: 82 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test Docker Build

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, labeled]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-image:
strategy:
matrix:
path: [docker, actions-runner-controller]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Output Collector
id: output-collector
uses: collinmcneese/file-output-collector@main
with:
file: "./VERSION"

- name: Prep
run: |
echo Building with Runner version ${{ steps.output-collector.outputs.output }}
echo ${{ steps.output-collector.outputs.output }} | grep 2
- name: Log in to the Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for ${{ matrix.path }}
if: ${{ matrix.path == 'docker' }}
id: meta-docker
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Extract metadata (tags, labels) for ${{ matrix.path }}
if: ${{ matrix.path == 'actions-runner-controller' }}
id: meta-arc
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build Docker image for ${{ matrix.path }}
if: ${{ matrix.path == 'docker' }}
uses: docker/build-push-action@af5a7ed5ba88268d5278f7203fb52cd833f66d6e
with:
context: ./docker
push: false
labels: ${{ steps.meta-docker.outputs.labels }}
build-args: |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.output-collector.outputs.output }}
- name: Build Docker image for ${{ matrix.path }}
if: ${{ matrix.path == 'actions-runner-controller' }}
uses: docker/build-push-action@af5a7ed5ba88268d5278f7203fb52cd833f66d6e
with:
context: ./actions-runner-controller
push: false
labels: ${{ steps.meta-arc.outputs.labels }}
build-args: |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc:${{ steps.output-collector.outputs.output }}
100 changes: 100 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Create and publish a Docker image

on:
workflow_dispatch:
push:
branches:
- main
paths:
- VERSION
- 'docker/**'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
strategy:
matrix:
path: [docker, actions-runner-controller, arc-container-dind]
environment: publish
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Output Collector
id: output-collector
uses: collinmcneese/file-output-collector@main
with:
file: "./VERSION"
- name: Prep
run: |
echo Building with Runner version ${{ steps.output-collector.outputs.output }}
echo ${{ steps.output-collector.outputs.output }} | grep 2
- name: Log in to the Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}


- name: Extract metadata (tags, labels) for ${{ matrix.path }}
if: ${{ matrix.path == 'docker' }}
id: meta-docker
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Extract metadata (tags, labels) for ${{ matrix.path }}
if: ${{ matrix.path == 'actions-runner-controller' }}
id: meta-arc
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and Push Docker image for ${{ matrix.path }}
if: ${{ matrix.path == 'docker' }}
uses: docker/build-push-action@af5a7ed5ba88268d5278f7203fb52cd833f66d6e
with:
context: ./docker
push: true
labels: ${{ steps.meta-docker.outputs.labels }}
build-args: |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.output-collector.outputs.output }}
- name: Build and Push Docker image for ${{ matrix.path }}
if: ${{ matrix.path == 'actions-runner-controller' }}
uses: docker/build-push-action@af5a7ed5ba88268d5278f7203fb52cd833f66d6e
with:
context: ./actions-runner-controller
push: true
labels: ${{ steps.meta-arc.outputs.labels }}
build-args: |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc:${{ steps.output-collector.outputs.output }}
- name: Build and Push Docker image for ${{ matrix.path }}
if: ${{ matrix.path == 'arc-container-dind' }}
uses: docker/build-push-action@af5a7ed5ba88268d5278f7203fb52cd833f66d6e
with:
context: ./arc-container-dind
push: true
labels: ${{ steps.meta-arc.outputs.labels }}
build-args: |
RUNNER_VERSION=${{ steps.output-collector.outputs.output }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc-container-dind:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arc-container-dind:${{ steps.output-collector.outputs.output }}
86 changes: 86 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Check for updates against releases from github.com/actions/runner

name: self-update

on:
schedule:
- cron: '0 9 * * *'
workflow_dispatch:


jobs:
get-runner-version:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.get-runner-version.outputs.result }}
steps:
- name: Get latest runner version
id: get-runner-version
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const latest = await github.rest.repos.getLatestRelease({
owner: 'actions',
repo: 'runner'
})
let version = latest.data.tag_name.substring(1)
return version
- name: Log latest runner version
run: echo ${{ steps.get-runner-version.outputs.result }}
# Compare the latest runner version with the contents of VERSION
# If they don't match, update VERSION and create a pull request
update-runner-version:
needs: get-runner-version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update runner version
id: update-runner-version
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
const fs = require('fs');
const path = require('path');
const latest = '${{ needs.get-runner-version.outputs.latest }}';
const versionPath = path.join('${{ github.workspace }}', 'VERSION');
const current = fs.readFileSync(versionPath, 'utf8');
let changed;
if (current.trim() === latest.trim()) {
console.log('Runner is already up to date')
changed = 'false'
return changed
} else {
console.log('Runner is out of date')
changed = 'true'
fs.writeFileSync(versionPath, latest)
return changed
}
- name: Log changed
run: echo 'VERSION changed -- ${{ steps.update-runner-version.outputs.result }}'
- name: Commit Changes
if: steps.update-runner-version.outputs.result == 'true'
run: |
# If the runner version has changed, commit the change, push the branch and create a pull request
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add VERSION
git commit -m 'Update runner version to ${{ needs.get-runner-version.outputs.latest }}'
- name: Create Pull Request
if: steps.update-runner-version.outputs.result == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{secrets.GITHUB_TOKEN}}
commit-message: Update runner version to ${{ needs.get-runner-version.outputs.latest }}
title: Update runner version to ${{ needs.get-runner-version.outputs.latest }}
body: |
This pull request updates the runner version to ${{ needs.get-runner-version.outputs.latest }}.
Please review and merge if no changes are required.
branch: update-runner-version-${{ needs.get-runner-version.outputs.latest }}
branch-suffix: timestamp
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local*
.env
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2022 collinmcneese

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# GitHub Actions Runners Examples

[![Create and publish a Docker image](https://github.com/collinmcneese/github_actions_runners/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/collinmcneese/github_actions_runners/actions/workflows/docker-publish.yml)

Working repository with reference examples for building self-hosted runners for GitHub Actions.

The contents of this repository are _not_ meant to be run in a production environment and are for refernce example only. This is still an active _Work In Progress_ and likely should not be used by anyone, for any reason.

## References

- [https://github.com/actions/runner/](https://github.com/actions/runner/)

## Container Image

Builds a [GitHub Actions Runner](https://github.com/actions/runner/) container :ship:.

This repository has a reference [docker](./docker) example which contains a `Dockerfile` for building an image along with a `docker-compose` configuration for local testing.

The image configuration built from this example is published to [GitHub Packages](https://github.com/collinmcneese/github_actions_runners/pkgs/container/github_actions_runners) and can be pulled rather than performing a local build for quick testing.

The container image reference:

- Is meant for [organization](https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners#adding-a-self-hosted-runner-to-an-organization) or [repository](https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners#adding-a-self-hosted-runner-to-a-repository) scoped runners. See [Docs](https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners) for additional information.

### Building & Using the Container Image Locally

- Create `docker/.env` file using the reference [docker/.env.example](docker/.env.example)

```shell
GHRUNNER_ORGANIZATION=''
# Optionally specify a Repository
# GHRUNNER_REPOSITORY=''
GHRUNNER_ACCESS_TOKEN=''
GHRUNNER_LABELS="self-hosted,Linux,x64,dependabot"
# Specify the base GitHub URL if not using github.com
# GHRUNNER_GITHUB_BASE_URL='https://myGHES.com'
```
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.314.1
Loading

0 comments on commit 4bdb447

Please sign in to comment.