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

490 lines
16 KiB
YAML
Raw Normal View History

2021-09-13 19:36:12 +02:00
name: Build images
on:
release:
types:
- published
push:
branches:
- 'trunk'
paths-ignore:
- '.env*'
- 'docker-compose*.yaml'
- '*/rhel/*'
- '*/windows/*'
- "**.md"
defaults:
run:
shell: bash
jobs:
build_base:
timeout-minutes: 70
2021-09-13 21:04:05 +02:00
name: Build ${{ matrix.build }} base on ${{ matrix.os }}
2021-09-13 19:36:12 +02:00
env:
LATEST_BRANCH: "${{ github.event.repository.default_branch }}"
DOCKER_REPOSITORY: "zabbix"
strategy:
fail-fast: false
matrix:
build:
- build-base
os:
- alpine
- ubuntu
- ol
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Prepare platform list
id: platform
run: |
DOCKER_PLATFORM="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x"
if [ "${{ matrix.os }}" == "ubuntu" ]; then
2021-09-14 00:31:35 +02:00
DOCKER_PLATFORM="linux/amd64,linux/arm/v7,linux/arm64"
#,linux/ppc64le"
2021-09-13 19:36:12 +02:00
fi
if [ "${{ matrix.os }}" == "ol" ]; then
DOCKER_PLATFORM="linux/amd64,linux/arm64"
fi
echo ::set-output name=list::${DOCKER_PLATFORM}
- name: Prepare environment (push)
if: github.event_name == 'push'
id: prepare_push
run: |
TAGS_ARRAY=()
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
GIT_BRANCH="${{ github.ref }}"
GIT_BRANCH=${GIT_BRANCH:11}
echo "::debug::Branch - ${GIT_BRANCH}"
if [ "${GIT_BRANCH}" == "trunk" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}")
TAGS_ARRAY+=("$IMAGE_NAME:${GIT_BRANCH}-${{ matrix.os }}")
else
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}-latest")
TAGS_ARRAY+=("$IMAGE_NAME:${GIT_BRANCH}-${{ matrix.os }}-latest")
fi
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:latest")
fi
if [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-latest")
fi
TAGS=$(printf -- "%s, " "${TAGS_ARRAY[@]}")
echo "::debug::Tags - ${TAGS}"
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=image_tag_versions::$(printf -- "%s," "${TAGS_ARRAY[@]}")
- name: Prepare environment (release)
if: github.event_name == 'release' && github.event.action == 'published'
id: prepare_release
run: |
TAGS_ARRAY=()
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
RELEASE_VERSION="${{ github.ref }}"
RELEASE_VERSION=${RELEASE_VERSION:10}
GIT_BRANCH=${RELEASE_VERSION%.*}
echo "::debug::Release version ${RELEASE_VERSION}. Branch ${GIT_BRANCH}"
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${RELEASE_VERSION}")
TAGS_ARRAY+=("$IMAGE_NAME:${RELEASE_VERSION}-${{ matrix.os }}")
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:latest")
fi
TAGS=$(printf -- "--tag %s " "${TAGS_ARRAY[@]}")
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=image_tag_versions::$(printf -- ",%s" "${TAGS_ARRAY[@]}")
- name: Prepare tags
id: prepare_tags
run: |
if [ ! -z "${{ steps.prepare_push.outputs.image_tag_versions }}" ]; then
TAGS="${{ steps.prepare_push.outputs.image_tag_versions }}"
IMAGE_NAME="${{ steps.prepare_push.outputs.image_name }}"
elif [ ! -z "${{ steps.prepare_release.outputs.image_tag_versions }}" ]; then
TAGS="${{ steps.prepare_release.outputs.image_tag_versions }}"
IMAGE_NAME="${{ steps.prepare_release.outputs.image_name }}"
else
exit 1
fi
echo ::set-output name=image_tag_versions::${TAGS}
echo ::set-output name=image_name::${IMAGE_NAME}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.build }}/${{ matrix.os }}
file: ./${{ matrix.build }}/${{ matrix.os }}/Dockerfile
platforms: ${{ steps.platform.outputs.list }}
push: ${{ secrets.AUTO_PUSH_IMAGES }}
tags: ${{ steps.prepare_tags.outputs.image_tag_versions }}
- name: Image digest
2021-09-13 21:04:05 +02:00
run: |
echo ${{ steps.docker_build.outputs.digest }}
2021-09-13 21:40:08 +02:00
echo "${{ steps.docker_build.outputs.digest }}" > ${{ matrix.build }}_${{ matrix.os }}
2021-09-13 21:17:54 +02:00
- uses: actions/upload-artifact@v2
with:
2021-09-13 21:26:49 +02:00
name: ${{ matrix.build }}_${{ matrix.os }}
2021-09-13 21:40:08 +02:00
path: ${{ matrix.build }}_${{ matrix.os }}
2021-09-13 21:26:49 +02:00
if-no-files-found: error
2021-09-13 19:36:12 +02:00
build_base_database:
timeout-minutes: 70
2021-09-13 19:42:05 +02:00
needs: build_base
name: Build ${{ matrix.build }} base on ${{ matrix.os }}
2021-09-13 19:36:12 +02:00
env:
LATEST_BRANCH: "${{ github.event.repository.default_branch }}"
DOCKER_REPOSITORY: "zabbix"
strategy:
fail-fast: false
matrix:
build:
2021-09-13 22:14:34 +02:00
- build-mysql
- build-pgsql
- build-sqlite3
2021-09-13 19:36:12 +02:00
os:
- alpine
- ubuntu
- ol
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Prepare platform list
id: platform
run: |
DOCKER_PLATFORM="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x"
if [ "${{ matrix.os }}" == "ubuntu" ]; then
2021-09-14 00:31:35 +02:00
DOCKER_PLATFORM="linux/amd64,linux/arm/v7,linux/arm64"
#,linux/ppc64le"
2021-09-13 19:36:12 +02:00
fi
if [ "${{ matrix.os }}" == "ol" ]; then
DOCKER_PLATFORM="linux/amd64,linux/arm64"
fi
echo ::set-output name=list::${DOCKER_PLATFORM}
- name: Prepare environment (push)
if: github.event_name == 'push'
id: prepare_push
run: |
TAGS_ARRAY=()
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
GIT_BRANCH="${{ github.ref }}"
GIT_BRANCH=${GIT_BRANCH:11}
echo "::debug::Branch - ${GIT_BRANCH}"
if [ "${GIT_BRANCH}" == "trunk" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}")
TAGS_ARRAY+=("$IMAGE_NAME:${GIT_BRANCH}-${{ matrix.os }}")
else
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}-latest")
TAGS_ARRAY+=("$IMAGE_NAME:${GIT_BRANCH}-${{ matrix.os }}-latest")
fi
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:latest")
fi
if [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-latest")
fi
TAGS=$(printf -- "%s, " "${TAGS_ARRAY[@]}")
echo "::debug::Tags - ${TAGS}"
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=image_tag_versions::$(printf -- "%s," "${TAGS_ARRAY[@]}")
echo ::set-output name=base_tag::${TAGS_ARRAY[1]#*:}
- name: Prepare environment (release)
if: github.event_name == 'release' && github.event.action == 'published'
id: prepare_release
run: |
TAGS_ARRAY=()
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
RELEASE_VERSION="${{ github.ref }}"
RELEASE_VERSION=${RELEASE_VERSION:10}
GIT_BRANCH=${RELEASE_VERSION%.*}
echo "::debug::Release version ${RELEASE_VERSION}. Branch ${GIT_BRANCH}"
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${RELEASE_VERSION}")
TAGS_ARRAY+=("$IMAGE_NAME:${RELEASE_VERSION}-${{ matrix.os }}")
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:latest")
fi
TAGS=$(printf -- "--tag %s " "${TAGS_ARRAY[@]}")
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=image_tag_versions::$(printf -- ",%s" "${TAGS_ARRAY[@]}")
echo ::set-output name=base_tag::${TAGS_ARRAY[1]#*:}
2021-09-13 21:17:54 +02:00
- uses: actions/download-artifact@v2
with:
2021-09-13 21:50:20 +02:00
name: build-base_${{ matrix.os }}
2021-09-13 21:17:54 +02:00
2021-09-13 19:36:12 +02:00
- name: Prepare tags
id: prepare_tags
run: |
if [ ! -z "${{ steps.prepare_push.outputs.image_tag_versions }}" ]; then
TAGS="${{ steps.prepare_push.outputs.image_tag_versions }}"
IMAGE_NAME="${{ steps.prepare_push.outputs.image_name }}"
BASE_TAG="${{ steps.prepare_push.outputs.base_tag }}"
elif [ ! -z "${{ steps.prepare_release.outputs.image_tag_versions }}" ]; then
TAGS="${{ steps.prepare_release.outputs.image_tag_versions }}"
IMAGE_NAME="${{ steps.prepare_release.outputs.image_name }}"
BASE_TAG="${{ steps.prepare_release.outputs.base_tag }}"
else
exit 1
fi
2021-09-13 22:01:07 +02:00
BASE_TAG=$(cat build-base_${{ matrix.os }})
2021-09-13 21:04:05 +02:00
2021-09-13 19:36:12 +02:00
echo ::set-output name=image_tag_versions::${TAGS}
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=base_tag::${BASE_TAG}
2021-09-13 21:17:54 +02:00
2021-09-13 19:36:12 +02:00
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.build }}/${{ matrix.os }}
file: ./${{ matrix.build }}/${{ matrix.os }}/Dockerfile
platforms: ${{ steps.platform.outputs.list }}
push: ${{ secrets.AUTO_PUSH_IMAGES }}
tags: ${{ steps.prepare_tags.outputs.image_tag_versions }}
2021-09-13 23:06:45 +02:00
build-args: BUILD_BASE_IMAGE=${{ env.DOCKER_REPOSITORY }}/zabbix-build-base@${{ steps.prepare_tags.outputs.base_tag }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
echo "${{ steps.docker_build.outputs.digest }}" > ${{ matrix.build }}_${{ matrix.os }}
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.build }}_${{ matrix.os }}
path: ${{ matrix.build }}_${{ matrix.os }}
if-no-files-found: error
build_images:
timeout-minutes: 70
2021-09-13 23:11:03 +02:00
needs: build_base_database
2021-09-13 23:06:45 +02:00
name: Build ${{ matrix.build }} base on ${{ matrix.os }}
env:
LATEST_BRANCH: "${{ github.event.repository.default_branch }}"
DOCKER_REPOSITORY: "zabbix"
strategy:
fail-fast: false
matrix:
build:
- agent
- agent2
- proxy-mysql
- java-gateway
os:
- alpine
- ubuntu
- ol
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Prepare platform list
id: platform
run: |
DOCKER_PLATFORM="linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x"
if [ "${{ matrix.os }}" == "ubuntu" ]; then
2021-09-14 00:31:35 +02:00
DOCKER_PLATFORM="linux/amd64,linux/arm/v7,linux/arm64"
#,linux/ppc64le"
2021-09-13 23:06:45 +02:00
fi
if [ "${{ matrix.os }}" == "ol" ]; then
DOCKER_PLATFORM="linux/amd64,linux/arm64"
fi
echo ::set-output name=list::${DOCKER_PLATFORM}
- name: Prepare environment (push)
if: github.event_name == 'push'
id: prepare_push
run: |
TAGS_ARRAY=()
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
GIT_BRANCH="${{ github.ref }}"
GIT_BRANCH=${GIT_BRANCH:11}
echo "::debug::Branch - ${GIT_BRANCH}"
if [ "${GIT_BRANCH}" == "trunk" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}")
TAGS_ARRAY+=("$IMAGE_NAME:${GIT_BRANCH}-${{ matrix.os }}")
else
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${GIT_BRANCH}-latest")
TAGS_ARRAY+=("$IMAGE_NAME:${GIT_BRANCH}-${{ matrix.os }}-latest")
fi
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:latest")
fi
if [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-latest")
fi
TAGS=$(printf -- "%s, " "${TAGS_ARRAY[@]}")
echo "::debug::Tags - ${TAGS}"
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=image_tag_versions::$(printf -- "%s," "${TAGS_ARRAY[@]}")
echo ::set-output name=base_tag::${TAGS_ARRAY[1]#*:}
- name: Prepare environment (release)
if: github.event_name == 'release' && github.event.action == 'published'
id: prepare_release
run: |
TAGS_ARRAY=()
IMAGE_NAME="${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}"
RELEASE_VERSION="${{ github.ref }}"
RELEASE_VERSION=${RELEASE_VERSION:10}
GIT_BRANCH=${RELEASE_VERSION%.*}
echo "::debug::Release version ${RELEASE_VERSION}. Branch ${GIT_BRANCH}"
TAGS_ARRAY+=("$IMAGE_NAME:${{ matrix.os }}-${RELEASE_VERSION}")
TAGS_ARRAY+=("$IMAGE_NAME:${RELEASE_VERSION}-${{ matrix.os }}")
if [ "${{ matrix.os }}" == "alpine" ] && [ "${LATEST_BRANCH}" == "${GIT_BRANCH}" ]; then
TAGS_ARRAY+=("$IMAGE_NAME:latest")
fi
TAGS=$(printf -- "--tag %s " "${TAGS_ARRAY[@]}")
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=image_tag_versions::$(printf -- ",%s" "${TAGS_ARRAY[@]}")
- name: Detect Build Base Image
id: build_base_image
run: |
BUILD_BASE="build-mysql"
if [[ "${{ matrix.build }}" == *"pgsql" ]]; then
BUILD_BASE="build-pgsql"
fi
if [[ "${{ matrix.build }}" == *"sqlite3" ]]; then
BUILD_BASE="build-mysql"
fi
echo ::set-output name=build_base::${BUILD_BASE}
- uses: actions/download-artifact@v2
with:
name: ${{ steps.build_base_image.outputs.build_base }}_${{ matrix.os }}
- name: Prepare tags
id: prepare_tags
run: |
if [ ! -z "${{ steps.prepare_push.outputs.image_tag_versions }}" ]; then
TAGS="${{ steps.prepare_push.outputs.image_tag_versions }}"
IMAGE_NAME="${{ steps.prepare_push.outputs.image_name }}"
elif [ ! -z "${{ steps.prepare_release.outputs.image_tag_versions }}" ]; then
TAGS="${{ steps.prepare_release.outputs.image_tag_versions }}"
IMAGE_NAME="${{ steps.prepare_release.outputs.image_name }}"
else
exit 1
fi
BASE_TAG=$(cat ${{ steps.build_base_image.outputs.build_base }}_${{ matrix.os }})
echo ::set-output name=image_tag_versions::${TAGS}
echo ::set-output name=image_name::${IMAGE_NAME}
echo ::set-output name=base_tag::${BASE_TAG}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.build }}/${{ matrix.os }}
file: ./${{ matrix.build }}/${{ matrix.os }}/Dockerfile
platforms: ${{ steps.platform.outputs.list }}
push: false
tags: ${{ steps.prepare_tags.outputs.image_tag_versions }}
build-args: BUILD_BASE_IMAGE=${{ env.DOCKER_REPOSITORY }}/zabbix-${{ steps.build_base_image.outputs.build_base }}@${{ steps.prepare_tags.outputs.base_tag }}
2021-09-13 19:36:12 +02:00
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}