zabbix-docker/.github/workflows/CI.yml

226 lines
7.8 KiB
YAML
Raw Normal View History

2020-09-07 18:54:40 +02:00
name: CI
on:
release:
types:
- published
push:
branches:
2020-09-08 21:01:39 +02:00
- '3.0'
- '4.0'
- '5.0'
- 'trunk'
2020-09-07 18:54:40 +02:00
paths-ignore:
- '.env*'
- 'docker-compose*.yaml'
- '*/rhel/*'
- "**.md"
defaults:
run:
shell: bash
jobs:
build:
env:
2020-09-08 21:01:39 +02:00
LATEST_BRANCH: "${{ github.event.repository.default_branch }}"
2020-09-07 18:54:40 +02:00
DOCKER_REPOSITORY: "zabbix"
strategy:
fail-fast: false
matrix:
build:
- agent
- agent2
- java-gateway
- proxy-mysql
- proxy-sqlite3
- server-mysql
- server-pgsql
- snmptraps
- web-apache-mysql
- web-apache-pgsql
- web-nginx-mysql
- web-nginx-pgsql
os:
- alpine
- ubuntu
- centos
exclude:
- os: centos
build: agent2
- os: ubuntu
build: agent2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
2020-09-07 23:16:26 +02:00
- name: Install buildx
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
BUILDX_VERSION="0.4.2"
QEMU_TAG="latest"
mkdir -p ~/.docker/cli-plugins/
curl -L https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION}/buildx-v${BUILDX_VERSION}.linux-amd64 \
-o ~/.docker/cli-plugins/docker-buildx
chmod +x ~/.docker/cli-plugins/docker-buildx
docker pull -q multiarch/qemu-user-static:latest
docker run --rm --privileged multiarch/qemu-user-static:${QEMU_TAG} --reset -p yes --credential yes
docker buildx create --name builder-${GITHUB_SHA::8} --driver docker-container --use
docker buildx inspect --bootstrap
docker info
docker buildx inspect
- name: Available platforms
run: docker buildx inspect | grep Platforms
2020-09-07 18:54:40 +02:00
- name: Prepare platform list
id: platform
run: |
2020-09-07 23:16:26 +02:00
DOCKER_PLATFORM="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
2020-09-07 18:54:40 +02:00
if [ "${{ matrix.os }}" == "ubuntu" ]; then
2020-09-07 23:16:26 +02:00
DOCKER_PLATFORM="linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
fi
if [ "${{ matrix.os }}" == "ubuntu" ] && [ "${{ matrix.build }}" == "snmptraps" ]; then
DOCKER_PLATFORM="linux/amd64,linux/arm64"
2020-09-07 18:54:40 +02:00
fi
if [ "${{ matrix.os }}" == "centos" ]; then
2020-09-08 21:01:39 +02:00
DOCKER_PLATFORM="linux/amd64,linux/arm64,linux/ppc64le"
2020-09-07 18:54:40 +02:00
fi
if [ "${{ matrix.build }}" == "java-gateway" ]; then
DOCKER_PLATFORM=${DOCKER_PLATFORM%",linux/ppc64le"}
fi
echo ::set-output name=list::${DOCKER_PLATFORM}
2020-09-07 23:16:26 +02:00
- name: Prepare environment (push)
2020-09-07 18:54:40 +02:00
if: github.event_name == 'push'
id: prepare_push
run: |
2020-09-07 23:16:26 +02:00
TAGS_ARRAY=()
2020-09-07 18:54:40 +02:00
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
GIT_BRANCH="${{ github.ref }}"
GIT_BRANCH=${GIT_BRANCH:11}
2020-09-08 21:01:39 +02:00
echo "::debug::Branch - ${GIT_BRANCH}"
2020-09-07 18:54:40 +02:00
2020-09-08 21:01:39 +02:00
if [ "${GIT_BRANCH}" == "trunk" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}")
else
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}-latest")
fi
2020-09-07 18:54:40 +02:00
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
2020-09-07 23:16:26 +02:00
TAGS_ARRAY+=("$IMAGE_NAME:latest")
2020-09-07 18:54:40 +02:00
fi
if [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
2020-09-07 23:16:26 +02:00
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-latest")
2020-09-07 18:54:40 +02:00
fi
2020-09-07 23:16:26 +02:00
TAGS=$(printf -- "--tag %s " "${TAGS_ARRAY[@]}")
2020-09-07 18:54:40 +02:00
2020-09-08 21:01:39 +02:00
echo "::debug::Tags - ${TAGS}"
2020-09-07 18:54:40 +02:00
echo ::set-output name=image_name::${IMAGE_NAME}
2020-09-07 23:16:26 +02:00
echo ::set-output name=image_tag_versions::$(printf -- "|%s" "${TAGS_ARRAY[@]}")
2020-09-07 18:54:40 +02:00
echo ::set-output name=buildx_args::--platform "${{ steps.platform.outputs.list }}" \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS} \
--file ./${{ matrix.build }}/${{ matrix.os }}/Dockerfile ./${{ matrix.build }}/${{ matrix.os }}
2020-09-07 23:16:26 +02:00
- name: Prepare environment (release)
2020-09-08 21:01:39 +02:00
if: github.event_name == 'release' && github.event.action == 'published'
2020-09-07 18:54:40 +02:00
id: prepare_release
run: |
2020-09-07 23:16:26 +02:00
TAGS_ARRAY=()
2020-09-07 18:54:40 +02:00
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
RELEASE_VERSION="${{ github.ref }}"
RELEASE_VERSION=${RELEASE_VERSION:10}
GIT_BRANCH=${RELEASE_VERSION%.*}
2020-09-08 21:01:39 +02:00
echo "::debug::Release version ${RELEASE_VERSION}. Branch ${GIT_BRANCH}"
2020-09-07 18:54:40 +02:00
2020-09-07 23:16:26 +02:00
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${RELEASE_VERSION}")
2020-09-07 18:54:40 +02:00
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
2020-09-07 23:16:26 +02:00
TAGS_ARRAY+=("$IMAGE_NAME:latest")
2020-09-07 18:54:40 +02:00
fi
2020-09-07 23:16:26 +02:00
TAGS=$(printf -- "--tag %s " "${TAGS_ARRAY[@]}")
2020-09-07 18:54:40 +02:00
echo ::set-output name=image_name::${IMAGE_NAME}
2020-09-07 23:16:26 +02:00
echo ::set-output name=image_tag_versions::$(printf -- "|%s" "${TAGS_ARRAY[@]}")
2020-09-07 18:54:40 +02:00
echo ::set-output name=buildx_args::--platform "${{ steps.platform.outputs.list }}" \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
2020-09-07 23:16:26 +02:00
$TAGS \
2020-09-07 18:54:40 +02:00
--file ./${{ matrix.build }}/${{ matrix.os }}/Dockerfile ./${{ matrix.build }}/${{ matrix.os }}
2020-09-07 23:16:26 +02:00
- name: Build images
env:
DOCKER_CLI_EXPERIMENTAL: enabled
2020-09-07 18:54:40 +02:00
run: |
2020-09-07 23:16:26 +02:00
if [ ! -z "${{ steps.prepare_push.outputs.buildx_args }}" ]; then
BUILDX_ARGS="${{ steps.prepare_push.outputs.buildx_args }}"
elif [ ! -z "${{ steps.prepare_release.outputs.buildx_args }}" ]; then
BUILDX_ARGS="${{ steps.prepare_release.outputs.buildx_args }}"
2020-09-08 21:01:39 +02:00
else
exit 1
2020-09-07 23:16:26 +02:00
fi
docker buildx build --cache-to "type=local,dest=/tmp/.buildx-cache" \
--output "type=image,push=false" \
${BUILDX_ARGS}
- name: Docker Hub login
if: success()
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push images from cache
if: success()
env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
if [ ! -z "${{ steps.prepare_push.outputs.buildx_args }}" ]; then
BUILDX_ARGS="${{ steps.prepare_push.outputs.buildx_args }}"
elif [ ! -z "${{ steps.prepare_release.outputs.buildx_args }}" ]; then
BUILDX_ARGS="${{ steps.prepare_release.outputs.buildx_args }}"
fi
docker buildx build --cache-from "type=local,src=/tmp/.buildx-cache" \
2020-09-08 21:01:39 +02:00
--output "type=image,push=${{ secrets.AUTO_PUSH_IMAGES }}" \
2020-09-07 23:16:26 +02:00
${BUILDX_ARGS}
- name: Inspect images
run: |
2020-09-08 21:01:39 +02:00
echo "::debug::push - ${{ steps.prepare_push.outputs.buildx_args }}"
echo "::debug::release - ${{ steps.prepare_release.outputs.buildx_args }}"
2020-09-07 23:16:26 +02:00
if [ ! -z "${{ steps.prepare_push.outputs.image_tag_versions }}" ]; then
IMAGE_TAG_VERSIONS="${{ steps.prepare_push.outputs.image_tag_versions }}"
2020-09-08 21:01:39 +02:00
echo "::debug::tags push raw - $IMAGE_TAG_VERSIONS"
2020-09-07 23:16:26 +02:00
elif [ ! -z "${{ steps.prepare_release.outputs.image_tag_versions }}" ]; then
IMAGE_TAG_VERSIONS="${{ steps.prepare_release.outputs.image_tag_versions }}"
2020-09-08 21:01:39 +02:00
echo "::debug::tags release raw - $IMAGE_TAG_VERSIONS"
2020-09-07 23:16:26 +02:00
fi
IMAGE_TAG_VERSIONS=${IMAGE_TAG_VERSIONS%%+(|)}
IFS='|' read -r -a IMAGE_TAG_VERSIONS <<< $IMAGE_TAG_VERSIONS
for version in ${IMAGE_TAG_VERSIONS[@]}; do
echo "Checking \"$version\"... "
docker buildx imagetools inspect $version
2020-09-08 21:01:39 +02:00
done