Skip to content

Commit

Permalink
Improve GitHub Actions (#720)
Browse files Browse the repository at this point in the history
* get build scripts and other requirements from main

* adjust github ci/cd for debian12

* add debian12 build scripts

* ci/cd: make sure to use the current branch for the build scripts

* ci/cd: improve handling of branches

* ci/cd: better variable naming

* ci/cd: testing needs to use the same commit as the building workflow

* ci/cd: add cleanup task

* ci/cd: add back jobs for other distros

* ci/cd: adjust whitespace
  • Loading branch information
NavidSassan authored Oct 10, 2023
1 parent 4dafb65 commit 86c5d47
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 63 deletions.
61 changes: 46 additions & 15 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ on:
workflow_dispatch:
inputs:

package-iteration:
description: 'The iteration to give to the package. RPM calls this the ‘release’. FreeBSD calls it ‘PORTREVISION’. Debian calls this ‘debian_revision’'
package-version:
description: 'The version to give to the packages. Defaults to the current tag.'
required: false
default: '1'
default: ''

package-version:
description: 'Which tag to build for. Defaults to the current tag. Note: Specifying commits does not work, as the SHA is not the same in the monitoring-plugins and lib repo.'
lib-repo-ref:
description: 'The branch, tag or SHA to checkout (lib repo). Defaults to the current tag.'
required: false
default: ''

package-iteration:
description: 'The iteration to give to the package. RPM calls this the ‘release’. FreeBSD calls it ‘PORTREVISION’. Debian calls this ‘debian_revision’'
required: false
default: '1'

env:
# we use `${{ github.sha }}-${{ github.run_id }}_${{ github.run_attempt }}` so we get a (mostly) unique directory, to avoid folder collisions when multiple workflows are running
BASE_DIR: '${{ github.sha }}-${{ github.run_id }}_${{ github.run_attempt }}'
Expand All @@ -35,24 +40,16 @@ jobs:

steps:

# checkout the latest version for the build scripts
- name: 'checkout the monitoring-plugins repo'
uses: 'actions/checkout@v3'
with:
path: '${{ env.BASE_DIR }}/repos/monitoring-plugins-latest'

# checkout the given version for the actual monitoring plugins themselves
- name: 'checkout the monitoring-plugins repo'
uses: 'actions/checkout@v3'
with:
path: '${{ env.BASE_DIR }}/repos/monitoring-plugins'
ref: '${{ inputs.package-version || github.ref }}'

- name: 'checkout the lib repo'
uses: 'actions/checkout@v3'
with:
repository: 'Linuxfabrik/lib'
ref: '${{ inputs.package-version || github.ref }}'
ref: '${{ inputs.lib-repo-ref || github.ref_name }}'
path: '${{ env.BASE_DIR }}/repos/lib'

- name: 'mkdir ${{ env.BASE_DIR }}/build'
Expand Down Expand Up @@ -92,14 +89,34 @@ jobs:
- name: 'mkdir ${{ env.BASE_DIR }}/build/debian11'
run: 'mkdir ${{ env.BASE_DIR }}/build/debian11'

- name: 'Build for Debian 10'
- name: 'Build for Debian 11'
run: |-
podman run --interactive --rm \
--mount type=bind,source=${{ env.BASE_DIR }}/build/debian11,destination=/build,relabel=private \
--mount type=bind,source=${{ env.BASE_DIR }}/repos,destination=/repos,relabel=shared,ro=true \
docker.io/library/debian:bullseye /bin/bash -x /repos/monitoring-plugins-latest/build/debian11/build.sh ${{ inputs.package-version || github.ref_name }} ${{ inputs.package-iteration || '1' }}
build-debian12:
runs-on:
- 'rhel8'
- 'self-hosted'
needs:
- 'prepare'

steps:

- name: 'mkdir ${{ env.BASE_DIR }}/build/debian12'
run: 'mkdir ${{ env.BASE_DIR }}/build/debian12'

- name: 'Build for Debian 12'
run: |-
podman run --interactive --rm \
--mount type=bind,source=${{ env.BASE_DIR }}/build/debian12,destination=/build,relabel=private \
--mount type=bind,source=${{ env.BASE_DIR }}/repos,destination=/repos,relabel=shared,ro=true \
docker.io/library/debian:bookworm /bin/bash -x /repos/monitoring-plugins/build/debian12/build.sh ${{ inputs.package-version || github.ref_name }} ${{ inputs.package-iteration || '1' }}
# RHEL
build-rhel7:
runs-on:
Expand Down Expand Up @@ -170,6 +187,7 @@ jobs:
needs: # we want this to run after the above jobs
- 'build-debian10'
- 'build-debian11'
- 'build-debian12'
- 'build-rhel7'
- 'build-rhel8'
- 'build-rhel9'
Expand All @@ -182,3 +200,16 @@ jobs:
with:
name: 'monitoring-plugins-linux-packages'
path: '${{ env.BASE_DIR }}/build/'


cleanup:
runs-on:
- 'rhel8'
- 'self-hosted'
needs: # we want this to run after the above jobs
- 'upload-outputs'

steps:

- name: 'rm -rf ${{ env.BASE_DIR }}'
run: 'rm -rf ${{ env.BASE_DIR }}'
41 changes: 38 additions & 3 deletions .github/workflows/linux-test-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: 'actions/checkout@v3'
with:
path: '${{ env.BASE_DIR }}/repos/monitoring-plugins'
ref: '${{ inputs.package-version || github.ref }}'
ref: '${{ github.event.workflow_run.head_commit }}'

# using this instead of the official `download-artifact` action since this allows cross-workflow
- name: 'download the monitoring-plugins-linux-packages artifact'
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: 'mkdir ${{ env.BASE_DIR }}/output/debian10'
run: 'mkdir ${{ env.BASE_DIR }}/output/debian10'

- name: 'Test on RHEL8'
- name: 'Test on Debian 10'
run: |-
podman run --interactive --rm \
--mount type=bind,source=${{ env.BASE_DIR }}/output/debian10,destination=/output,relabel=private \
Expand All @@ -75,7 +75,7 @@ jobs:
- name: 'mkdir ${{ env.BASE_DIR }}/output/debian11'
run: 'mkdir ${{ env.BASE_DIR }}/output/debian11'

- name: 'Test on RHEL8'
- name: 'Test on Debian 11'
run: |-
podman run --interactive --rm \
--mount type=bind,source=${{ env.BASE_DIR }}/output/debian11,destination=/output,relabel=private \
Expand All @@ -84,6 +84,27 @@ jobs:
docker.io/library/debian:bullseye /bin/bash -x /repos/monitoring-plugins/testing/debian/run-all
test-debian12:
runs-on:
- 'rhel8'
- 'self-hosted'
needs:
- 'prepare'

steps:

- name: 'mkdir ${{ env.BASE_DIR }}/output/debian12'
run: 'mkdir ${{ env.BASE_DIR }}/output/debian12'

- name: 'Test on RHEL8'
run: |-
podman run --interactive --rm \
--mount type=bind,source=${{ env.BASE_DIR }}/output/debian12,destination=/output,relabel=private \
--mount type=bind,source=${{ env.BASE_DIR }}/repos,destination=/repos,relabel=shared,ro=true \
--mount type=bind,source=${{ env.BASE_DIR }}/monitoring-plugins-linux-packages/debian12,destination=/packages,relabel=shared,ro=true \
docker.io/library/debian:bookworm /bin/bash -x /repos/monitoring-plugins/testing/debian/run-all
# RHEL
test-rhel7:
runs-on:
Expand Down Expand Up @@ -157,6 +178,7 @@ jobs:
needs: # we want this to run after the above jobs
- 'test-debian10'
- 'test-debian11'
- 'test-debian12'
- 'test-rhel7'
- 'test-rhel8'
- 'test-rhel9'
Expand All @@ -169,3 +191,16 @@ jobs:
with:
name: 'monitoring-plugins-test-output'
path: '${{ env.BASE_DIR }}/output/'


cleanup:
runs-on:
- 'rhel8'
- 'self-hosted'
needs: # we want this to run after the above jobs
- 'upload-outputs'

steps:

- name: 'rm -rf ${{ env.BASE_DIR }}'
run: 'rm -rf ${{ env.BASE_DIR }}'
10 changes: 5 additions & 5 deletions build/debian10/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

RELEASE="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKET_VERSION="$2" # 2, if there is a bugfix for this package (not for the mp)
PACKAGE_VERSION="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKAGE_ITERATION="$2" # 2, if there is a bugfix for this package (not for the mp)


apt-get -y update
Expand All @@ -17,13 +17,13 @@ apt-get install -y ruby ruby-dev rubygems build-essential
gem install fpm

# prepare venv
. /repos/monitoring-plugins-latest/build/shared/venv.sh
. /repos/monitoring-plugins/build/shared/venv.sh

# compile using pyinstaller
. /repos/monitoring-plugins-latest/build/shared/compile.sh
. /repos/monitoring-plugins/build/shared/compile.sh

# prepare files for fpm
. /repos/monitoring-plugins-latest/build/shared/prepare-fpm.sh
. /repos/monitoring-plugins/build/shared/prepare-fpm.sh

# create packages using fpm
cd /tmp/fpm/check-plugins
Expand Down
10 changes: 5 additions & 5 deletions build/debian11/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

RELEASE="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKET_VERSION="$2" # 2, if there is a bugfix for this package (not for the mp)
PACKAGE_VERSION="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKAGE_ITERATION="$2" # 2, if there is a bugfix for this package (not for the mp)


apt-get -y update
Expand All @@ -17,13 +17,13 @@ apt-get install -y ruby ruby-dev rubygems build-essential
gem install fpm

# prepare venv
. /repos/monitoring-plugins-latest/build/shared/venv.sh
. /repos/monitoring-plugins/build/shared/venv.sh

# compile using pyinstaller
. /repos/monitoring-plugins-latest/build/shared/compile.sh
. /repos/monitoring-plugins/build/shared/compile.sh

# prepare files for fpm
. /repos/monitoring-plugins-latest/build/shared/prepare-fpm.sh
. /repos/monitoring-plugins/build/shared/prepare-fpm.sh

# create packages using fpm
cd /tmp/fpm/check-plugins
Expand Down
35 changes: 35 additions & 0 deletions build/debian12/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

PACKAGE_VERSION="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKAGE_ITERATION="$2" # 2, if there is a bugfix for this package (not for the mp)


apt-get -y update
apt-get -y install git
apt-get -y install python3-dev python3-venv

# dependencies for gem / fpm
apt-get install -y ruby ruby-dev rubygems build-essential

# install fpm using gem
gem install fpm

# prepare venv
. /repos/monitoring-plugins/build/shared/venv.sh

# compile using pyinstaller
. /repos/monitoring-plugins/build/shared/compile.sh

# prepare files for fpm
. /repos/monitoring-plugins/build/shared/prepare-fpm.sh

# create packages using fpm
cd /tmp/fpm/check-plugins
fpm --output-type deb
cp *.deb /build/

cd /tmp/fpm/notification-plugins
fpm --output-type deb
cp *.deb /build/
10 changes: 5 additions & 5 deletions build/rhel7/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

RELEASE="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKET_VERSION="$2" # 2, if there is a bugfix for this package (not for the mp)
PACKAGE_VERSION="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKAGE_ITERATION="$2" # 2, if there is a bugfix for this package (not for the mp)


# subscription-manager repos --enable rhel-7-server-optional-rpms --enable rhel-server-rhscl-7-rpms # not needed in ubi containers
Expand All @@ -29,10 +29,10 @@ source /opt/rh/rh-ruby30/enable # analogous to `scl enable rh-ruby30 bash`
gem install fpm

# prepare venv
. /repos/monitoring-plugins-latest/build/shared/venv.sh
. /repos/monitoring-plugins/build/shared/venv.sh

# compile using pyinstaller
. /repos/monitoring-plugins-latest/build/shared/compile.sh
. /repos/monitoring-plugins/build/shared/compile.sh

# RHEL only - compile .te file to .pp for SELinux
mkdir /tmp/selinux
Expand All @@ -42,7 +42,7 @@ make --file /usr/share/selinux/devel/Makefile linuxfabrik-monitoring-plugins.pp
\cp -a linuxfabrik-monitoring-plugins.pp /tmp/dist/summary/check-plugins

# prepare files for fpm
. /repos/monitoring-plugins-latest/build/shared/prepare-fpm.sh
. /repos/monitoring-plugins/build/shared/prepare-fpm.sh

# create packages using fpm
cd /tmp/fpm/check-plugins
Expand Down
10 changes: 5 additions & 5 deletions build/rhel8/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

RELEASE="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKET_VERSION="$2" # 2, if there is a bugfix for this package (not for the mp)
PACKAGE_VERSION="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKAGE_ITERATION="$2" # 2, if there is a bugfix for this package (not for the mp)


yum -y update
Expand All @@ -23,10 +23,10 @@ yum -y install ruby-devel gcc make rpm-build libffi-devel
gem install fpm

# prepare venv
. /repos/monitoring-plugins-latest/build/shared/venv.sh
. /repos/monitoring-plugins/build/shared/venv.sh

# compile using pyinstaller
. /repos/monitoring-plugins-latest/build/shared/compile.sh
. /repos/monitoring-plugins/build/shared/compile.sh

# RHEL only - compile .te file to .pp for SELinux
mkdir /tmp/selinux
Expand All @@ -36,7 +36,7 @@ make --file /usr/share/selinux/devel/Makefile linuxfabrik-monitoring-plugins.pp
\cp -a linuxfabrik-monitoring-plugins.pp /tmp/dist/summary/check-plugins

# prepare files for fpm
. /repos/monitoring-plugins-latest/build/shared/prepare-fpm.sh
. /repos/monitoring-plugins/build/shared/prepare-fpm.sh

# create packages using fpm
cd /tmp/fpm/check-plugins
Expand Down
10 changes: 5 additions & 5 deletions build/rhel9/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

RELEASE="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKET_VERSION="$2" # 2, if there is a bugfix for this package (not for the mp)
PACKAGE_VERSION="$1" # version number has to start with a digit, for example 2023123101; "main" for the latest development version
PACKAGE_ITERATION="$2" # 2, if there is a bugfix for this package (not for the mp)


yum -y update
Expand All @@ -20,10 +20,10 @@ yum -y install ruby-devel gcc make rpm-build libffi-devel
gem install fpm

# prepare venv
. /repos/monitoring-plugins-latest/build/shared/venv.sh
. /repos/monitoring-plugins/build/shared/venv.sh

# compile using pyinstaller
. /repos/monitoring-plugins-latest/build/shared/compile.sh
. /repos/monitoring-plugins/build/shared/compile.sh

# RHEL only - compile .te file to .pp for SELinux
mkdir /tmp/selinux
Expand All @@ -33,7 +33,7 @@ make --file /usr/share/selinux/devel/Makefile linuxfabrik-monitoring-plugins.pp
\cp -a linuxfabrik-monitoring-plugins.pp /tmp/dist/summary/check-plugins

# prepare files for fpm
. /repos/monitoring-plugins-latest/build/shared/prepare-fpm.sh
. /repos/monitoring-plugins/build/shared/prepare-fpm.sh

# create packages using fpm
cd /tmp/fpm/check-plugins
Expand Down
Loading

0 comments on commit 86c5d47

Please sign in to comment.