Skip to content

Linuxfabrik: Build Linux (x86_64) #6

Linuxfabrik: Build Linux (x86_64)

Linuxfabrik: Build Linux (x86_64) #6

name: 'Linuxfabrik: Build Linux (x86_64)'
on:
workflow_dispatch:
inputs:
package-version:
description: 'The version ("major.minor.patch"). If empty, version is taken from `version.txt`, and revision is auto-incremented.'
required: false
default: ''
lib-repo-ref:
description: 'The branch, tag, or SHA to checkout from the lib repo. Defaults to the current branch or tag.'
required: false
default: ''
check-plugin:
description: 'If you only want to compile a specific check plugin, specify its name, for example `cpu-usage`, otherwise leave empty to build all plugins.'
required: false
default: 'cpu-usage'
distros:
description: 'Comma-separated list of operating systems to build on. Supported: `debian11,debian12,rocky8,rocky9,ubuntu2004,ubuntu2204,ubuntu2404`.'
required: false
default: 'rocky9'
env:
# we use this to get a (mostly) unique directory, therefore avoiding folder collisions when multiple workflows are running
BASE_DIR: '${{ github.sha }}-${{ github.run_id }}_${{ github.run_attempt }}'
# modify the default permissions granted to the GITHUB_TOKEN
permissions:
contents: 'read'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
set-matrix:
runs-on:
- 'ubuntu-24.04'
outputs:
matrix: '${{ steps.generate-matrix.outputs.matrix }}'
steps:
- name: 'Generate Matrix'
id: 'generate-matrix'
run: |
distros="${{ inputs.distros }}"
matrix=$(echo "$distros" | jq --compact-output --raw-input '{"distros": split(",")}')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build-packages:
runs-on:
- 'ubuntu-24.04'
needs:
- 'set-matrix'
strategy:
matrix:
distro: '${{ fromJson(needs.set-matrix.outputs.matrix).distros }}'
steps:
- name: 'Debug Environment and Inputs'
run: >
echo
check-plugin=${{ inputs.check-plugin }}
lib-repo-ref=${{ inputs.lib-repo-ref }}
package-iteration=${{ inputs.package-iteration }}
distros=${{ inputs.distros }}
- name: 'Checkout the monitoring-plugins repo'
uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # v4.2.2
with:
path: '${{ env.BASE_DIR }}/repos/monitoring-plugins'
- name: 'Checkout the lib repo'
uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # v4.2.2
with:
repository: 'Linuxfabrik/lib'
ref: '${{ inputs.lib-repo-ref || github.ref_name }}'
path: '${{ env.BASE_DIR }}/repos/lib'
- name: 'mkdir -p ${{ env.BASE_DIR }}/build'
run: 'mkdir -p ${{ env.BASE_DIR }}/build'
- name: 'mkdir -p ${{ env.BASE_DIR }}/build/${{ matrix.distro }}'
run: 'mkdir -p ${{ env.BASE_DIR }}/build/${{ matrix.distro }}'
- name: 'Synchronize cached writes to persistent storage'
run: 'sync'
- name: '⚙️ apt-get -y install podman'
run: |
sudo apt-get update
sudo apt-get -y install podman
- name: 'Build the container for ${{ matrix.distro }}'
run: >
podman build
--file "${{ env.BASE_DIR }}/repos/monitoring-plugins/build/${{ matrix.distro }}/Containerfile"
--tag "lfmp-build-${{ matrix.distro }}"
- name: 'Build the packages for ${{ matrix.distro }}'
run: >
podman run
--rm
--mount type=bind,source=${{ env.BASE_DIR }}/build/${{ matrix.distro }},destination=/build,relabel=private
--mount type=bind,source=${{ env.BASE_DIR }}/repos,destination=/repos,relabel=shared,ro=true
"lfmp-build-${{ matrix.distro }}"
/bin/bash -x
/repos/monitoring-plugins/build/${{ matrix.distro }}/build.sh
${{ inputs.package-version || github.ref_name }}
${{ inputs.package-iteration || '1' }}
${{ inputs.check-plugin || '' }}
# this would not work on the Github-hosted runners, as each job is isolated there,
# but works when self-hosted (since there are no parallel jobs)
upload-outputs:
runs-on:
- 'ubuntu-24.04'
needs: # we want this to run after the build jobs
- 'build-packages'
# if: '${{ always() }}' # however, we want to upload the artifacts even if one of the job fails
steps:
- name: 'Upload build output as artifact for packaging later on'
uses: 'actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08' # v4.6.0
with:
name: "monitoring-plugins-linux-${{ inputs.arch || 'X64' }}"
path: '${{ env.BASE_DIR }}/build/'