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

Automated docker build and publication #54

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ on:
branches:
- '*'
jobs:
build:
name: CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup
run: |
sudo apt-get install ruby-dev build-essential debhelper devscripts rpm xalan wget -y
sudo gem install fpm
- name: Build Package
run: ./create_packages
- name: Test Package
run: sudo ./ci_test
CI_DEV:
uses: ./.github/workflows/shared.yml
with:
publish_steps: false
26 changes: 5 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@ on:
- '*'

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: refs/heads/main
- name: Setup
run: |
sudo apt-get install ruby-dev build-essential debhelper devscripts rpm xalan wget -y
sudo gem install fpm
- name: Build Package
run: ./create_packages
- name: Test Package
run: sudo ./ci_test
- uses: ncipollo/release-action@v1
with:
artifacts: "zabbix-agent-extensions*.deb,zabbix-agent-extensions-*.rpm"
CI_RELEASE:
uses: ./.github/workflows/shared.yml
with:
publish_steps: true

54 changes: 54 additions & 0 deletions .github/workflows/shared.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Shared Build Workflow

on:
workflow_call:
inputs:
publish_steps:
description: "Publish artefacts"
required: false
default: false
type: boolean

jobs:
build-pkg:
name: CI-PKGs
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup
run: |
sudo apt-get install ruby-dev build-essential debhelper devscripts rpm xalan wget -y
sudo gem install fpm
- name: Build Package
run: ./create_packages
- name: Test Package
run: sudo ./ci_test
- uses: ncipollo/release-action@v1
if: ${{ inputs.publish_steps }}
with:
artifacts: "zabbix-agent-extensions*.deb,zabbix-agent-extensions-*.rpm"
build-docker:
name: CI-Docker
runs-on: ubuntu-latest
environment: "Docker Upload"
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Login to Docker Hub
if: ${{ inputs.publish_steps }}
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build
run: |
./create_docker build
- name: Publish docker images
if: ${{ inputs.publish_steps }}
run: |
./create_docker publish
4 changes: 3 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
git push
git push --tags
```
* TravisCI builds and tests the release and uploads it to github
* Github builds and tests the release and uploads it to github
* RPM and DEB packages
* Docker Images

7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM zabbix/zabbix-agent:ubuntu-6.4-latest
MAINTAINER [email protected]
# see https://github.com/zabbix/zabbix-docker/blob/7.2/Dockerfiles/agent/ubuntu/Dockerfile
FROM zabbix/zabbix-agent:ubuntu-7.2-latest

ARG BUILD_DATE
USER 0
ADD /docker-scripts /tmp/setup
RUN chmod 755 /tmp/setup/*.sh
Expand All @@ -10,7 +11,7 @@ ADD zabbix-agent-extensions_*_all.deb /tmp/setup
RUN /tmp/setup/04_install_agent_extensions.sh
RUN /tmp/setup/05_perform_upgrade.sh

ENTRYPOINT ["/usr/bin/tini", "--", "/usr/bin/docker-entrypoint.sh"]
ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]

USER 1997

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
zabbix-agent-extensions
=======================

[![Images at Dockerhub](https://www.docker.com/wp-content/uploads/2024/02/cropped-docker-logo-favicon-32x32.png)](https://hub.docker.com/repository/docker/scoopex666/zabbix-agent-with-agent-extensions/)
[![Build package and test](https://github.com/scoopex/zabbix-agent-extensions/actions/workflows/continuous-integration-workflow.yml/badge.svg)](https://github.com/scoopex/zabbix-agent-extensions/actions/workflows/continuous-integration-workflow.yml)
[![Releases](https://github.com/scoopex/zabbix-agent-extensions/actions/workflows/release.yml/badge.svg)](https://github.com/scoopex/zabbix-agent-extensions/actions/workflows/release.yml)

Expand All @@ -9,7 +10,7 @@ zabbix-agent-extensions
A set of zabbix UserParameter scripts and production ready monitoring templates for linux systems.

* this project ist originated on: https://github.com/scoopex/zabbix-agent-extensions
* the ci is implmented with github actions
* the ci is implemented with github actions (creating packages, docker images and testing)
* docker images of a zabbix agent can be obtained at https://hub.docker.com/repository/docker/scoopex666/zabbix-agent-with-agent-extensions

# Monitoring details
Expand Down Expand Up @@ -109,6 +110,8 @@ Install the agent extensions on kubernetes nodes
---------------------------------------------

This procedure deploy zabbix agents on all worker nodes of your kubernetes cluster and provides autodiscovery for all nodes
It is based on the offical [image](https://hub.docker.com/r/zabbix/zabbix-agent).


* Make zabbix available to the deployed agent, i.e. by deploying a zabbix proxy in k8s
* Import template [custom-os-kubernetes-node.xml](http://htmlpreview.github.io/?https://github.com/scoopex/zabbix-agent-extensions/blob/master/zabbix_templates/5.2/documentation/custom-os-kubernetes-node.html)
Expand All @@ -123,7 +126,7 @@ This procedure deploy zabbix agents on all worker nodes of your kubernetes clust
* "Link to templates: Custom - OS - Kubernetes Node"
* Configure deployment
* Download [kubernetes yaml file](https://raw.githubusercontent.com/scoopex/zabbix-agent-extensions/master/zabbix-agent-daemonset-kubernetes.yaml)
* Adapt the file to your own needs
* Adapt the file to your own needs, see [environment variables](https://hub.docker.com/r/zabbix/zabbix-agent)
* Configure `ZBX_ACTIVESERVER`
* Configure `ZBX_PASSIVESERVERS`
* Configure the version of the image [check dockerhub](https://hub.docker.com/repository/docker/scoopex666/zabbix-agent-with-agent-extensions)
Expand All @@ -134,7 +137,6 @@ This procedure deploy zabbix agents on all worker nodes of your kubernetes clust
kubectl logs -n infra-zabbix-agent zabbix-agent-8n4ss -f
```


How to configure the zabbix server/templates
--------------------------------------------

Expand Down
118 changes: 109 additions & 9 deletions create_docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,121 @@

IMAGE_REPO="scoopex666"
IMAGE_NAME="zabbix-agent-with-agent-extensions"
CONTAINER_TEST_NAME="zabbix-agent-extentions-test"
VERSION="${2:-$(git describe --abbrev=0 --tags)}"

if [ "$1" = "build" ];then
docker build -t ${IMAGE_NAME}:${VERSION} -f Dockerfile .
elif [ "$1" = "inspect" ];then
docker run -ti ${IMAGE_NAME}:${VERSION} /bin/bash
elif [ "$1" = "publish" ];then

FAILED_TESTS=""

assertSuccess(){
local STRATEGY="$1"
local CMD="docker exec -u root -ti ${CONTAINER_TEST_NAME} $2"
echo "****************************************************************************"
echo "** EXECUTE: $CMD";
eval "$CMD 2>&1"
local RET="$?"
echo "**"

if [ "$RET" != "0" ];then
echo "** ERROR: execution failed (returncode $RET)"
FAILED_TESTS="$FAILED_TESTS#assertSuccess => $CMD"
echo "****************************************************************************"
if [ "$STRATEGY" = "STOP_ON_ERROR" ];then
exit 100
else
return 100
fi
fi
echo "****************************************************************************"
return 0
}



testPackage(){
buildDocker
docker stop ${CONTAINER_TEST_NAME}
set -x
docker run --privileged --rm \
-d \
--network host \
-v $PWD:/src \
-e ZBX_HOSTNAME=${CONTAINER_TEST_NAME} \
-e ZBX_SERVER_HOST=127.0.0.1 \
-e ZBX_PASSIVESERVERS=127.0.0.1 \
--name ${CONTAINER_TEST_NAME} ${IMAGE_NAME}:${VERSION}
set +x
echo '{ "{#FOO}" : "BAR" }' | docker exec -i -u root ${CONTAINER_TEST_NAME} tee /etc/zabbix/zabbix-discovery-generic/foo-bar.json
assertSuccess STOP_ON_ERROR "ls -l /etc/zabbix/zabbix-discovery-generic/foo-bar.json"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'generic.discovery[foo,json]' | tee /dev/stderr | grep -q -P 'BAR'" # Without sudo

assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.dmesg | tee /dev/stderr | grep -q -P 'OK: ALL OK|ERROR:'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.dmesg | tee /dev/stderr | grep -q -P 'OK: ALL OK|ERROR:'" # Without sudo
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k linux.multipath | tee /dev/stderr | grep -q 'OK:'" # With sudo

assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[zabbix_agentd,minage]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[zabbix_agentd,maxage]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'custom.process[nosuchprocess,maxage]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'zabbix.agent_extensions.version'|tee /dev/stderr | grep -q -P '^\d+'"

docker exec -i -u root ${CONTAINER_TEST_NAME} mkdir -m 755 -p /opt/puppetlabs/puppet/cache/state/
docker exec -i -u root ${CONTAINER_TEST_NAME} cp /src/extension-files/test/last_run_summary.yaml /opt/puppetlabs/puppet/cache/state/last_run_summary.yaml
docker exec -i -u root ${CONTAINER_TEST_NAME} cp /src/extension-files/test/last_run_report.yaml /opt/puppetlabs/puppet/cache/state/last_run_report.yaml

assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[state]'|tee /dev/stderr | grep -q -P '^OK: puppetrun successful, no changes'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[changes,total]'|tee /dev/stderr | grep -q -P '^\d+'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k 'puppet[environment]'|tee /dev/stderr | grep -q -P '^production_master'"

assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k vfs.dev.discovery | tee /dev/stderr | grep -q '#BLOCKDEVICE'"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k vfs.fs.discovery | grep -v /proc"
assertSuccess STOP_ON_ERROR "zabbix_get -s 127.0.0.1 -k nfs.rpc.calls|grep -P '^\d+'"

docker stop ${CONTAINER_TEST_NAME}
echo
echo
echo "*** SUMMARY"
if [ -z "$FAILED_TESTS" ];then
echo "ALL TESTS PASSED"
return 0
else
echo "THE FOLLOWING TESTS FAILED"
echo "$FAILED_TESTS"|tr '#' '\n'|sed '~s,^, ,'
return 1
fi
}

buildDocker(){
set -x
docker rmi ${IMAGE_NAME}:${VERSION}
set -e
docker build --progress plain --build-arg BUILD_DATE="$(date "+%Y-%m-%d")" -t ${IMAGE_NAME}:${VERSION} -f Dockerfile .
set +xe
}

inspectDocker(){
set -x
docker stop ${CONTAINER_TEST_NAME}
exec docker run --network host --rm --name ${CONTAINER_TEST_NAME} -ti ${IMAGE_NAME}:${VERSION} /bin/bash
}

publishDocker(){
buildDocker
set -xe
docker tag ${IMAGE_NAME}:${VERSION} ${IMAGE_REPO}/${IMAGE_NAME}:${VERSION}
docker push ${IMAGE_REPO}/${IMAGE_NAME}:${VERSION}
docker tag ${IMAGE_NAME}:${VERSION} ${IMAGE_REPO}/${IMAGE_NAME}:latest
docker push ${IMAGE_REPO}/${IMAGE_NAME}:latest
set +xe
}

if [ "$1" = "build" ];then
buildDocker
elif [ "$1" = "inspect" ];then
inspectDocker
elif [ "$1" = "publish" ];then
publishDocker
elif [ "$1" = "test" ];then
docker run ${IMAGE_NAME}:${VERSION}
testPackage
else
echo "$0 build|inspect|publish|run"
echo "$0 build|inspect|publish|test"
fi


1 change: 1 addition & 0 deletions docker-scripts/01_phase_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ apt-get dist-upgrade -y
apt-get autoremove -y
apt-get clean
apt-get autoremove -y

rm -rf /var/lib/apt/lists/*

echo "set nocompatible" > /var/lib/zabbix/.vimrc
1 change: 0 additions & 1 deletion docker-scripts/04_install_agent_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ cd /tmp/setup
ls -l /tmp/setup
dpkg -i *.deb
sed -i '~s,/var/lib/zabbix/:/sbin/nologin,/var/lib/zabbix/:/bin/bash,' /etc/passwd
#cat /etc/passwd
Loading