Update NCPA to 3.1.1 #132
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
pull_request: | |
branches: | |
- master | |
- develop | |
jobs: | |
build: | |
if: "!contains(github.event.head_commit.message, 'skip ci')" | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
architecture: [linux-amd64, linux-arm64] | |
outputs: | |
version: ${{ steps.prep.outputs.version }} | |
branch: ${{ steps.prep.outputs.branch }} | |
time: ${{ steps.vars.outputs.time }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Check if architecture exists | |
id: arch_check | |
run: | | |
(test -f Dockerfile.${{ matrix.architecture }} && echo "check=passed" >> $GITHUB_OUTPUT) || echo "check=failed" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
if: "contains(steps.arch_check.outputs.check, 'passed')" | |
uses: docker/setup-qemu-action@v3.0.0 | |
- name: Set up Docker Buildx | |
if: "contains(steps.arch_check.outputs.check, 'passed')" | |
uses: docker/setup-buildx-action@v3.3.0 | |
with: | |
install: true | |
version: latest | |
driver-opts: image=moby/buildkit:master | |
- name: Login to docker.io | |
if: "contains(steps.arch_check.outputs.check, 'passed')" | |
uses: docker/login-action@v3.2.0 | |
with: | |
registry: docker.io | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to ghcr.io | |
if: "contains(steps.arch_check.outputs.check, 'passed')" | |
uses: docker/login-action@v3.2.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Prepare | |
if: "contains(steps.arch_check.outputs.check, 'passed')" | |
id: prep | |
run: | | |
{ | |
ARCHITECTURE=${{ matrix.architecture }} | |
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | |
echo "title=$(echo ${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//} | tr '[:upper:]' '[:lower:]')" | |
echo "revision=${GITHUB_SHA}" | |
echo "source=$(echo ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/tree/${GITHUB_REF//refs\/heads\//} | tr '[:upper:]' '[:lower:]')" | |
echo "vendor=${{ github.repository_owner }}" | |
echo "url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/blob/master/README.md" | |
echo "platform=${ARCHITECTURE//-/\/}" | |
echo "cache=$(echo ${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}-cache-${{ matrix.architecture }} | tr '[:upper:]' '[:lower:]')" | |
echo "tag=$(echo ${GITHUB_REPOSITORY}:${GITHUB_REF//refs\/heads\//}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER}-${{ matrix.architecture }} | tr '[:upper:]' '[:lower:]' | sed s/docker-//)" | |
} >> $GITHUB_OUTPUT | |
VERSION=$(grep nagiosVersion Dockerfile.${{ matrix.architecture }} | awk -F= '{print $2}' | tr -d '" \\') | |
if [[ -z ${VERSION} ]]; then | |
VERSION=$(date --utc --date=@$(git show -s --format=%ct $(git rev-parse --short HEAD)) +'%Y%m%d%H%M%S') | |
fi | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
BRANCH="${GITHUB_REF//refs\/heads\//}" | |
if [[ -n ${BRANCH} ]]; then | |
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT | |
fi | |
echo $GITHUB_OUTPUT | |
- name: Build and push | |
continue-on-error: true | |
if: "contains(steps.arch_check.outputs.check, 'passed')" | |
id: build_attempt1 | |
uses: docker/build-push-action@v5.4.0 | |
with: | |
push: true | |
platforms: ${{ steps.prep.outputs.platform }} | |
file: ./Dockerfile.${{ matrix.architecture }} | |
cache-from: docker.io/${{ steps.prep.outputs.cache }} | |
cache-to: docker.io/${{ steps.prep.outputs.cache }} | |
tags: | | |
docker.io/${{ steps.prep.outputs.tag }} | |
ghcr.io/${{ steps.prep.outputs.tag }} | |
labels: | | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.title=${{ steps.prep.outputs.title }} | |
org.opencontainers.image.revision=${{ steps.prep.outputs.revision }} | |
org.opencontainers.image.source=${{ steps.prep.outputs.source }} | |
org.opencontainers.image.vendor=${{ steps.prep.outputs.vendor }} | |
org.opencontainers.image.url=${{ steps.prep.outputs.url }} | |
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | |
build-args: | | |
GITHUB_TOKEN=${{ secrets.GHCR_TOKEN }} | |
BUILD_ARCHITECTURE=${{ matrix.architecture }} | |
${{ steps.prep.outputs.build-args }} | |
publish: | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
registry: [docker.io, ghcr.io] | |
needs: [build] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Login to docker.io | |
if: matrix.registry == 'docker.io' | |
uses: docker/login-action@v3.2.0 | |
with: | |
registry: docker.io | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to ghcr.io | |
if: matrix.registry == 'ghcr.io' | |
uses: docker/login-action@v3.2.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Create manifests | |
continue-on-error: true | |
id: manifest_attempt1 | |
env: | |
DOCKER_CLI_EXPERIMENTAL: enabled | |
run: | | |
IMAGE=${{ matrix.registry }}/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' | sed s/docker-//) | |
TAG=${{ needs.build.outputs.branch }} | |
SOURCE=${IMAGE}:${TAG}-${GITHUB_SHA:0:7}-${GITHUB_RUN_NUMBER} | |
VERSION=${{ needs.build.outputs.version }} | |
docker buildx imagetools create -t ${IMAGE}:${TAG} ${SOURCE}-linux-amd64 ${SOURCE}-linux-arm64 | |
docker buildx imagetools create -t ${IMAGE}:${TAG}-${VERSION} ${SOURCE}-linux-amd64 ${SOURCE}-linux-arm64 | |
if [[ ${GITHUB_REF//refs\/heads\//} == master ]]; then | |
docker buildx imagetools create -t ${IMAGE}:latest ${SOURCE}-linux-amd64 ${SOURCE}-linux-arm64 | |
fi |