mirror of
https://github.com/manios/docker-nagios.git
synced 2026-07-19 09:23:51 +00:00
232 lines
14 KiB
YAML
232 lines
14 KiB
YAML
name: Nagios Build
|
|
# This workflow is triggered on pushes to the repository.
|
|
# Taken from tutorial
|
|
# https://github.com/gitschooldude/hello
|
|
# https://www.youtube.com/watch?v=-xIXFxuZCMI
|
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
|
# https://github.com/marketplace/actions/docker-login
|
|
# https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions/58034787
|
|
|
|
on: [push]
|
|
|
|
jobs:
|
|
nagios-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Print all github.* variables
|
|
id: step_one_print_all
|
|
run: |
|
|
echo "github.action : ${{ github.action }}"
|
|
echo "github.action_path : ${{ github.action_path }}"
|
|
echo "github.actor : ${{ github.actor }}"
|
|
echo "github.base_ref : ${{ github.base_ref }}"
|
|
echo 'github.event : ${{ toJson(github.event) }}'
|
|
echo "github.event_name : ${{ github.event_name }}"
|
|
echo "github.event_path : ${{ github.event_path }}"
|
|
echo "github.head_ref : ${{ github.head_ref }}"
|
|
echo "github.job : ${{ github.job }}"
|
|
echo "github.ref : ${{ github.ref }}"
|
|
echo "github.repository : ${{ github.repository }}"
|
|
echo "github.repository_owner : ${{ github.repository_owner }}"
|
|
echo "github.run_id : ${{ github.run_id }}"
|
|
echo "github.run_number : ${{ github.run_number }}"
|
|
echo "github.sha : ${{ github.sha }}"
|
|
echo "github.token : ${{ github.token }}"
|
|
echo "github.workflow : ${{ github.workflow }}"
|
|
echo "github.workspace : ${{ github.workspace }}"
|
|
echo "my docker tag: ${{ env.action_mytag }}"
|
|
- name: Set the value of a the Docker tag for branches other than master
|
|
id: step_two_branches_all
|
|
if: ${{ (startsWith( github.ref, 'refs/heads') == true) && (github.ref != 'refs/heads/master') }}
|
|
run: |
|
|
echo "action_mytag=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
|
|
- name: Set the value of the Docker tag for git tags
|
|
id: step_set_docker_tag_for_git_tags
|
|
if: ${{ startsWith( github.ref, 'refs/tags') == true}}
|
|
run: |
|
|
echo "action_mytag=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
- name: Set the value of the Docker tag for master branch
|
|
id: step_branch_master
|
|
if: ${{ github.ref == 'refs/heads/master' }}
|
|
run: |
|
|
echo "action_mytag=latest" >> $GITHUB_ENV
|
|
- name: Print the Docker tag value which will be used
|
|
id: step_print_docker_tag
|
|
run: |
|
|
echo "My docker tag will be: ${{ env.action_mytag }}"
|
|
- name: Login to DockerHub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
-
|
|
name: Checkout
|
|
uses: actions/checkout@v4
|
|
-
|
|
name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
-
|
|
name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
-
|
|
name: Available platforms
|
|
run: echo ${{ steps.buildx.outputs.platforms }}
|
|
-
|
|
name: Cache Docker layers for this Git branch
|
|
uses: actions/cache@v4
|
|
id: cache
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.ref }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-${{ github.ref }}
|
|
- name: Docker Buildx (build and cache)
|
|
run: |
|
|
docker buildx build \
|
|
--progress plain \
|
|
--cache-from "type=local,src=/tmp/.buildx-cache" \
|
|
--cache-to "type=local,dest=/tmp/.buildx-cache" \
|
|
--platform linux/386,linux/amd64,linux/arm64 \
|
|
--label "gitCommit=${{ github.sha }}" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
--tag ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} \
|
|
--output "type=image,push=false" -f Dockerfile .
|
|
- name: Docker Buildx (build and cache) for linux/arm/v6,linux/arm/v7 (Alpine 3.12)
|
|
run: |
|
|
docker buildx build \
|
|
--progress plain \
|
|
--cache-from "type=local,src=/tmp/.buildx-cache" \
|
|
--cache-to "type=local,dest=/tmp/.buildx-cache" \
|
|
--platform linux/arm/v6,linux/arm/v7 \
|
|
--label "gitCommit=${{ github.sha }}" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
--tag ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} \
|
|
--output "type=image,push=false" -f alpine3-12.dockerfile .
|
|
- name: 'Docker Buildx: Push to Dockerhub'
|
|
run: |
|
|
echo "== This branch is : ${GITHUB_REF}"
|
|
echo "Will push image ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub"
|
|
docker buildx build \
|
|
--progress plain \
|
|
--cache-from "type=local,src=/tmp/.buildx-cache" \
|
|
--platform linux/386,linux/amd64,linux/arm64 \
|
|
--label "gitCommit=${{ github.sha }}" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
--tag ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} \
|
|
--output "type=image,push=true" -f Dockerfile .
|
|
- name: 'Docker Buildx: Push to Dockerhub for linux/arm/v6,linux/arm/v7 (Alpine 3.12)'
|
|
run: |
|
|
echo "== This branch is : ${GITHUB_REF}"
|
|
echo "Will push image ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub"
|
|
docker buildx build \
|
|
--progress plain \
|
|
--cache-from "type=local,src=/tmp/.buildx-cache" \
|
|
--platform linux/arm/v6,linux/arm/v7 \
|
|
--label "gitCommit=${{ github.sha }}" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
--tag ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} \
|
|
--output "type=image,push=true" -f alpine3-12.dockerfile .
|
|
- name: 'Docker Buildx: Push to GitHub Container Registry'
|
|
run: |
|
|
echo "== This branch is : ${GITHUB_REF}"
|
|
echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub"
|
|
docker buildx build \
|
|
--progress plain \
|
|
--cache-from "type=local,src=/tmp/.buildx-cache" \
|
|
--platform linux/386,linux/amd64,linux/arm64 \
|
|
--label "gitCommit=${{ github.sha }}" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
--tag ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} \
|
|
--output "type=image,push=true" -f Dockerfile .
|
|
- name: 'Docker Buildx: Push to GitHub Container Registry for linux/arm/v6,linux/arm/v7 (Alpine 3.12)'
|
|
run: |
|
|
echo "== This branch is : ${GITHUB_REF}"
|
|
echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub"
|
|
docker buildx build \
|
|
--progress plain \
|
|
--cache-from "type=local,src=/tmp/.buildx-cache" \
|
|
--platform linux/arm/v6,linux/arm/v7 \
|
|
--label "gitCommit=${{ github.sha }}" \
|
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
|
--tag ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} \
|
|
--output "type=image,push=true" -f alpine3-12.dockerfile .
|
|
- name: Download and configure jq
|
|
run: |
|
|
echo "Download jq"
|
|
wget https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64
|
|
echo "Configure jq"
|
|
mv jq-linux-amd64 jq
|
|
chmod 744 jq
|
|
- name: Create a new unified manifest for Dockerhub
|
|
run: |
|
|
echo "Download manifest of ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }}"
|
|
docker buildx imagetools inspect ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} --raw > manifest1.json
|
|
echo "Download manifest of ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }}"
|
|
docker buildx imagetools inspect ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} --raw > manifest2.json
|
|
ls -l manifest*json
|
|
SHA256_AMD64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "amd64") | .digest')
|
|
SHA256_ARM64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm64") | .digest')
|
|
SHA256_I386=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "386") | .digest')
|
|
SHA256_ARMV6=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v6") | .digest')
|
|
SHA256_ARMV7=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v7") | .digest')
|
|
echo "Creating new manifest: ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}"
|
|
set -eux
|
|
docker manifest create --amend ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \
|
|
"${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" \
|
|
"${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" \
|
|
"${GITHUB_ACTOR}/nagios@${SHA256_I386}" \
|
|
"${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" \
|
|
"${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}"
|
|
echo "Annotating new manifest: ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} with platforms and architectures"
|
|
docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" --arch amd64 --os linux
|
|
docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" --arch arm64 --os linux
|
|
docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_I386}" --arch 386 --os linux
|
|
docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" --arch arm --os linux --variant v6
|
|
docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}" --arch arm --os linux --variant v7
|
|
- name: Create a new unified manifest for GitHub Container Registry
|
|
run: |
|
|
echo "Download manifest of ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }}"
|
|
docker buildx imagetools inspect ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} --raw > manifest1.json
|
|
echo "Download manifest of ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }}"
|
|
docker buildx imagetools inspect ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} --raw > manifest2.json
|
|
ls -l manifest*json
|
|
SHA256_AMD64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "amd64") | .digest')
|
|
SHA256_ARM64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm64") | .digest')
|
|
SHA256_I386=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "386") | .digest')
|
|
SHA256_ARMV6=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v6") | .digest')
|
|
SHA256_ARMV7=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v7") | .digest')
|
|
echo "Creating new manifest: ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}"
|
|
set -eux
|
|
docker manifest create --amend ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \
|
|
ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" \
|
|
ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" \
|
|
ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_I386}" \
|
|
ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" \
|
|
ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}"
|
|
echo "Annotating new manifest: ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} with platforms and architectures"
|
|
docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" --arch amd64 --os linux
|
|
docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" --arch arm64 --os linux
|
|
docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_I386}" --arch 386 --os linux
|
|
docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" --arch arm --os linux --variant v6
|
|
docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}" --arch arm --os linux --variant v7
|
|
- name: 'Push manifest to DockerHub'
|
|
run: |
|
|
echo "== This branch is : ${GITHUB_REF}"
|
|
echo "Will push image manifest ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub Registry"
|
|
docker manifest push ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}
|
|
- name: 'Push manifest to GitHub Container Registry'
|
|
run: |
|
|
echo "== This branch is : ${GITHUB_REF}"
|
|
echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to GitHub Container Registry"
|
|
docker manifest push ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}
|
|
- name: Inspect image
|
|
run: |
|
|
docker buildx imagetools inspect ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}
|
|
docker buildx imagetools inspect ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}
|
|
|