Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
philwelz committed Jan 26, 2024
0 parents commit 03d1369
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Action

on:
workflow_dispatch:
push:
branches:
- main

defaults:
run:
working-directory: ./
shell: bash

jobs:
build:
name: gh-runner
uses: ./.github/workflows/docker-build.yaml
with:
REGISTRY: ghcr.io
ORGANISATION_NAME: philwelz
64 changes: 64 additions & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build & Publish to Registry

on:
workflow_call:
inputs:
### Values from CICD Workflow ###
REGISTRY:
required: true
type: string
description: 'The Environemnt which should be used.'
ORGANISATION_NAME:
type: string
required: true
description: 'The Subscription ID which should be used.'

env:
IMAGE: '${{ inputs.REGISTRY }}/${{ inputs.ORGANISATION_NAME }}/gh-runner'

jobs:
docker-build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]

- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ${{ inputs.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: |
${{ env.IMAGE }}
tags: |
type=raw,latest
type=sha,prefix=,suffix=,short=true
- name: Build and push the fred version of the WebApp
uses: docker/[email protected]
with:
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64
push: true
context: ./gh-runner
file: ./gh-runner/Dockerfile
tags: ${{ steps.meta.outputs.tags }}

- name: Display image tag in summary
run: |
echo "### Build & release! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Released image:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- ${{steps.meta.outputs.tags}}" >> $GITHUB_STEP_SUMMARY
15 changes: 15 additions & 0 deletions gh-runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ghcr.io/actions/actions-runner:2.311.0

USER root

# install curl and jq
RUN apt-get update && apt-get install -y curl jq && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

USER runner

ENTRYPOINT ["./entrypoint.sh"]
29 changes: 29 additions & 0 deletions gh-runner/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh -l

# Retrieve a short lived runner registration token using the PAT
REGISTRATION_TOKEN="$(curl -X POST -fsSL \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: Bearer $GITHUB_PAT" \
-H 'X-GitHub-Api-Version: 2022-11-28' \
"$REGISTRATION_TOKEN_API_URL" \
| jq -r '.token')"

# Configure
if [[ "${ephemeralRunner}" == "true" ]]; then

./config.sh \
--url $REPO_URL \
--token $REGISTRATION_TOKEN \
--unattended \
--ephemeral \
&& ./run.sh

else

./config.sh \
--url $REPO_URL \
--token $REGISTRATION_TOKEN \
--unattended \
&& ./run.sh

fi

0 comments on commit 03d1369

Please sign in to comment.