Build and Push Self-Hosted Runner #310
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Self-Hosted Runner | |
| on: | |
| # Trigger the workflow manually | |
| workflow_dispatch: | |
| # Trigger the workflow daily | |
| schedule: | |
| - cron: "0 0 * * *" # Runs daily at midnight UTC | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build_and_push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout the repository | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| # Fetch the latest GitHub Actions Runner release version | |
| - name: Get Latest Runner Version | |
| id: runner_version | |
| run: | | |
| latest_release=$(curl -s https://api.github.com/repos/actions/runner/releases/latest | jq -r '.tag_name' | sed 's/^v//') | |
| echo "runner_version=${latest_release#v}" >> $GITHUB_ENV | |
| # Set up QEMU for multi-platform builds | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| # Set up Docker Buildx | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Log in to GitHub Container Registry | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Build and push the Docker image | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| pull: true | |
| push: true | |
| tags: ghcr.io/terrateamio/self-hosted-runner:latest | |
| platforms: linux/amd64,linux/arm64 | |
| build-args: | | |
| GH_RUNNER_VERSION=${{ env.runner_version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |