Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example: Build Container image with Podman (Rocky Linux 9) #2

Open
Cyclenerd opened this issue Jan 4, 2025 · 0 comments
Open

Example: Build Container image with Podman (Rocky Linux 9) #2

Cyclenerd opened this issue Jan 4, 2025 · 0 comments
Labels
example Example GitHub Action

Comments

@Cyclenerd
Copy link
Owner

This GitHub Action example workflow automates the creation of a GitHub Actions Runner on Hetzner Cloud, builds a Container image with Podman using that runner, and then automatically deletes the runner to avoid unnecessary costs. It utilizes the Cyclenerd/hcloud-github-runner GitHub Action for managing the runner lifecycle and leverages the podman build command for efficient image building and pushing to the GitHub Container Registry.

Image used: rocky-9 Rocky Linux 9

name: "Podman"

on:
  workflow_dispatch:

jobs:
  create-runner:
    name: Create Runner
    runs-on: ubuntu-24.04
    outputs:
      label: ${{ steps.create-runner.outputs.label }}
      server_id: ${{ steps.create-runner.outputs.server_id }}
    steps:
      - name: Create runner
        id: create-runner
        uses: Cyclenerd/hcloud-github-runner@v1
        with:
          mode: create
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          hcloud_token: ${{ secrets.HCLOUD_TOKEN }}
          server_type: cx22
          # Use Rocky Linux 9 base image
          image: rocky-9
          # Install Podman
          pre_runner_script: |
            dnf install podman -y
          # Add SSH key to disable root password generation and email notifications
          # ssh_key: 123

  build:
    name: Build Image
    needs:
      - create-runner # required to get output from the create-runner job
    runs-on: ${{ needs.create-runner.outputs.label }}
    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v4
      - name: Login to GitHub container registry 🏭
        # https://docs.docker.com/reference/cli/docker/login/
        run: podman login ghcr.io -u "${{ github.repository_owner }}" -p "${{ secrets.github_token }}"
      - name: Build Container image 🧪
        # Replace "ghcr.io/cyclenerd/hcloud-github-runner:example"
        run: |
          podman build . \
            --file "Dockerfile" \
            --tag "ghcr.io/cyclenerd/hcloud-github-runner:example"
      - name: Push Container image 📤
        # Replace "ghcr.io/cyclenerd/hcloud-github-runner:example"
        run: podman push "ghcr.io/cyclenerd/hcloud-github-runner:example"

  delete-runner:
    name: Delete Runner
    needs:
      - create-runner # required to get output from the create-runner job
      - build # required to wait when the main job is done
    runs-on: ubuntu-24.04
    if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
    steps:
      - name: Delete runner
        uses: Cyclenerd/hcloud-github-runner@v1
        with:
          mode: delete
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          hcloud_token: ${{ secrets.HCLOUD_TOKEN }}
          name: ${{ needs.create-runner.outputs.label }}
          server_id: ${{ needs.create-runner.outputs.server_id }}
@Cyclenerd Cyclenerd added the example Example GitHub Action label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example Example GitHub Action
Projects
None yet
Development

No branches or pull requests

1 participant