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

374 lines
13 KiB
YAML
Raw Normal View History

2021-09-14 17:37:31 +02:00
name: Build images (DockerHub)
2021-09-13 19:36:12 +02:00
on:
release:
types:
- published
push:
branches:
2021-10-14 23:27:40 +02:00
- '4.0'
- '5.0'
2022-02-15 11:03:28 +01:00
- '6.0'
2021-09-13 19:36:12 +02:00
- 'trunk'
2021-10-08 00:13:22 +02:00
paths:
- 'Dockerfiles/**'
2021-10-28 02:05:53 +02:00
- 'build.json'
2021-10-16 00:11:57 +02:00
- '!**/README.md'
2021-10-08 00:13:22 +02:00
- '!Dockerfiles/*/rhel/*'
- '!Dockerfiles/*/windows/*'
- '.github/workflows/images_build.yml'
2021-09-13 19:36:12 +02:00
defaults:
run:
shell: bash
2021-09-14 11:41:09 +02:00
env:
DOCKER_REPOSITORY: "zabbix"
LATEST_BRANCH: ${{ github.event.repository.default_branch }}
2021-09-14 12:32:06 +02:00
BASE_BUILD_NAME: "build-base"
2021-09-14 11:41:09 +02:00
2021-09-13 19:36:12 +02:00
jobs:
2021-09-14 02:17:14 +02:00
init_build:
name: Initialize build
runs-on: ubuntu-latest
outputs:
2021-09-14 03:10:41 +02:00
os: ${{ steps.os.outputs.list }}
database: ${{ steps.database.outputs.list }}
components: ${{ steps.components.outputs.list }}
2021-10-18 18:12:43 +02:00
is_default_branch: ${{ steps.branch_info.outputs.is_default_branch }}
2021-09-14 02:17:14 +02:00
steps:
2021-09-14 12:32:06 +02:00
- name: Checkout repository
2021-09-14 16:14:38 +02:00
uses: actions/checkout@v2.3.4
2021-09-14 11:41:09 +02:00
with:
fetch-depth: 1
2021-09-17 01:47:46 +02:00
- name: Check build.json file
2021-09-14 12:32:06 +02:00
id: build_exists
2021-09-14 03:10:41 +02:00
run: |
2021-09-17 01:47:46 +02:00
if [[ ! -f "./build.json" ]]; then
echo "::error::File build.json is missing"
2021-09-14 12:32:06 +02:00
exit 1
2021-09-14 11:41:09 +02:00
fi
2021-09-14 12:32:06 +02:00
- name: Prepare Operating System list
id: os
run: |
2021-10-09 10:12:02 +02:00
os_list=$(jq -r '.["os-linux"] | keys | [ .[] | tostring ] | @json' "./build.json")
2021-09-14 12:32:06 +02:00
echo "::set-output name=list::$os_list"
2021-09-14 03:10:41 +02:00
2021-09-14 12:32:06 +02:00
- name: Prepare Platform list
id: platform_list
run: |
2021-10-09 10:12:02 +02:00
platform_list=$(jq -r '.["os-linux"] | tostring | @json' "./build.json")
2021-09-14 12:32:06 +02:00
echo "::set-output name=list::$platform_list"
- name: Prepare Database engine list
2021-09-14 03:10:41 +02:00
id: database
run: |
2021-09-17 01:47:46 +02:00
database_list=$(jq -r '[.components | values[] ] | sort | unique | del(.. | select ( . == "" ) ) | [ .[] | tostring ] | @json' "./build.json")
2021-09-14 12:32:06 +02:00
echo "::set-output name=list::$database_list"
2021-09-14 03:10:41 +02:00
2021-09-14 12:32:06 +02:00
- name: Prepare Zabbix component list
2021-09-14 03:10:41 +02:00
id: components
run: |
2021-09-17 01:47:46 +02:00
component_list=$(jq -r '.components | keys | [ .[] | tostring ] | @json' "./build.json")
2021-09-14 12:32:06 +02:00
2021-09-14 12:32:43 +02:00
echo "::set-output name=list::$component_list"
2021-09-14 03:10:41 +02:00
2021-10-08 00:13:22 +02:00
- name: Get branch info
id: branch_info
2021-10-18 18:12:43 +02:00
run: |
2021-10-18 18:14:55 +02:00
github_ref="${{ github.ref }}"
2021-10-18 18:12:43 +02:00
result=false
if [[ "$github_ref" == "refs/tags/"* ]]; then
github_ref=${github_ref%.*}
fi
github_ref=${github_ref##*/}
2021-10-19 01:29:17 +02:00
if [[ "$github_ref" == "${{ env.LATEST_BRANCH }}" ]]; then
2021-10-18 18:12:43 +02:00
result=true
fi
echo "::set-output name=is_default_branch::$result"
2021-10-08 00:13:22 +02:00
2021-09-13 19:36:12 +02:00
build_base:
2021-10-29 03:16:24 +02:00
timeout-minutes: 30
2021-09-14 12:32:06 +02:00
name: Build base on ${{ matrix.os }}
2021-09-14 02:18:47 +02:00
needs: init_build
2021-09-13 19:36:12 +02:00
strategy:
2021-09-14 03:10:41 +02:00
fail-fast: false
2021-09-13 19:36:12 +02:00
matrix:
2021-09-14 02:17:14 +02:00
os: ${{ fromJson(needs.init_build.outputs.os) }}
2021-09-13 19:36:12 +02:00
2021-09-14 03:10:41 +02:00
runs-on: ubuntu-latest
2021-09-13 19:36:12 +02:00
steps:
2021-09-14 12:32:06 +02:00
- name: Checkout repository
2021-09-14 16:14:38 +02:00
uses: actions/checkout@v2.3.4
2021-09-14 02:17:14 +02:00
with:
fetch-depth: 1
2021-09-13 19:36:12 +02:00
- name: Set up QEMU
2021-10-28 00:45:54 +02:00
uses: docker/setup-qemu-action@v1.2.0
with:
image: tonistiigi/binfmt:latest
platforms: all
2021-09-13 19:36:12 +02:00
- name: Set up Docker Buildx
2021-10-28 00:45:54 +02:00
uses: docker/setup-buildx-action@v1.6.0
with:
driver-opts: image=moby/buildkit:master
2021-09-13 19:36:12 +02:00
- name: Login to DockerHub
2021-10-14 23:27:40 +02:00
uses: docker/login-action@v1
2021-09-13 19:36:12 +02:00
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
2021-09-14 12:32:06 +02:00
- name: Prepare Platform list
2021-09-15 13:31:56 +02:00
id: platform
2021-09-13 19:36:12 +02:00
run: |
2021-10-09 10:12:02 +02:00
platform_list=$(jq -r '.["os-linux"].${{ matrix.os }} | join(",")' "./build.json")
2021-10-27 21:28:33 +02:00
platform_list="${platform_list%,}"
2021-09-13 19:36:12 +02:00
2021-09-14 12:35:54 +02:00
echo ::set-output name=list::$platform_list
2021-09-13 19:36:12 +02:00
2021-09-15 14:15:05 +02:00
- name: Generate tags
2021-09-14 14:36:19 +02:00
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_REPOSITORY }}/zabbix-${{ env.BASE_BUILD_NAME }}
tags: |
type=ref,event=branch,prefix=${{ matrix.os }}-
type=ref,event=branch,suffix=-${{ matrix.os }}
2021-09-14 15:22:13 +02:00
flavor: |
2021-10-08 00:13:22 +02:00
latest=false
2021-09-13 19:36:12 +02:00
2021-09-15 16:48:48 +02:00
- name: Build ${{ env.BASE_BUILD_NAME }}/${{ matrix.os }} and push
2021-09-13 19:36:12 +02:00
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./Dockerfiles/${{ env.BASE_BUILD_NAME }}/${{ matrix.os }}
file: ./Dockerfiles/${{ env.BASE_BUILD_NAME }}/${{ matrix.os }}/Dockerfile
2021-09-13 19:36:12 +02:00
platforms: ${{ steps.platform.outputs.list }}
push: ${{ secrets.AUTO_PUSH_IMAGES }}
2021-09-14 14:36:19 +02:00
tags: ${{ steps.meta.outputs.tags }}
2021-09-15 14:21:33 +02:00
labels: |
org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
2021-09-13 19:36:12 +02:00
- name: Image digest
2021-09-13 21:04:05 +02:00
run: |
echo ${{ steps.docker_build.outputs.digest }}
2021-09-14 12:33:46 +02:00
echo "${{ steps.docker_build.outputs.digest }}" > ${{ env.BASE_BUILD_NAME }}_${{ matrix.os }}
2021-09-13 21:17:54 +02:00
2021-09-15 14:15:05 +02:00
- name: Upload SHA256 tag
uses: actions/upload-artifact@v2.2.4
2021-09-13 21:17:54 +02:00
with:
2021-09-14 12:33:46 +02:00
name: ${{ env.BASE_BUILD_NAME }}_${{ matrix.os }}
path: ${{ env.BASE_BUILD_NAME }}_${{ 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:
2021-10-29 03:16:24 +02:00
timeout-minutes: 120
2021-09-14 02:18:47 +02:00
needs: [ "build_base", "init_build"]
2021-09-13 19:42:05 +02:00
name: Build ${{ matrix.build }} base on ${{ matrix.os }}
2021-09-13 19:36:12 +02:00
strategy:
fail-fast: false
matrix:
2021-09-14 03:10:41 +02:00
build: ${{ fromJson(needs.init_build.outputs.database) }}
2021-09-14 02:17:14 +02:00
os: ${{ fromJson(needs.init_build.outputs.os) }}
2021-09-13 19:36:12 +02:00
runs-on: ubuntu-20.04
steps:
2021-09-15 16:48:48 +02:00
- name: Checkout repository
uses: actions/checkout@v2.3.4
2021-09-13 19:36:12 +02:00
- name: Set up QEMU
2021-10-28 00:45:54 +02:00
uses: docker/setup-qemu-action@v1.2.0
with:
image: tonistiigi/binfmt:latest
platforms: all
2021-09-13 19:36:12 +02:00
- name: Set up Docker Buildx
2021-10-28 00:45:54 +02:00
uses: docker/setup-buildx-action@v1.6.0
with:
driver-opts: image=moby/buildkit:master
2021-09-13 19:36:12 +02:00
- name: Login to DockerHub
2021-10-14 23:27:40 +02:00
uses: docker/login-action@v1
2021-09-13 19:36:12 +02:00
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
2021-09-14 12:32:06 +02:00
- name: Prepare Platform list
2021-09-15 13:31:56 +02:00
id: platform
2021-09-13 19:36:12 +02:00
run: |
2021-10-09 10:12:02 +02:00
platform_list=$(jq -r '.["os-linux"].${{ matrix.os }} | join(",")' "./build.json")
2021-10-27 21:28:33 +02:00
platform_list="${platform_list%,}"
2021-09-13 19:36:12 +02:00
2021-09-14 12:36:08 +02:00
echo ::set-output name=list::$platform_list
2021-09-13 19:36:12 +02:00
2021-09-15 14:15:05 +02:00
- name: Generate tags
2021-09-14 14:36:19 +02:00
id: meta
uses: docker/metadata-action@v3
2021-09-13 21:17:54 +02:00
with:
2021-09-14 14:36:19 +02:00
images: ${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}
tags: |
type=ref,event=branch,prefix=${{ matrix.os }}-
type=ref,event=branch,suffix=-${{ matrix.os }}
2021-09-14 15:22:13 +02:00
flavor: |
2021-10-08 00:13:22 +02:00
latest=false
2021-09-13 21:17:54 +02:00
2021-09-15 16:48:48 +02:00
- name: Download SHA256 tag build-base:${{ matrix.os }}
2021-09-15 14:15:05 +02:00
uses: actions/download-artifact@v2.0.10
2021-09-14 14:49:54 +02:00
with:
name: build-base_${{ matrix.os }}
2021-09-15 16:48:48 +02:00
- name: Retrieve build-base:${{ matrix.os }} SHA256 tag
2021-09-14 14:36:19 +02:00
id: base_build
2021-09-13 19:36:12 +02:00
run: |
2021-09-13 22:01:07 +02:00
BASE_TAG=$(cat build-base_${{ matrix.os }})
2021-09-14 15:02:34 +02:00
BUILD_BASE_IMAGE=${{ env.DOCKER_REPOSITORY }}/zabbix-build-base@${BASE_TAG}
2021-09-13 21:04:05 +02:00
2021-09-13 19:36:12 +02:00
echo ::set-output name=base_tag::${BASE_TAG}
2021-09-14 14:36:19 +02:00
echo ::set-output name=base_build_image::${BUILD_BASE_IMAGE}
2021-09-13 21:17:54 +02:00
2021-09-15 16:48:48 +02:00
- name: Build ${{ matrix.build }}/${{ matrix.os }} and push
2021-09-13 19:36:12 +02:00
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./Dockerfiles/${{ matrix.build }}/${{ matrix.os }}
file: ./Dockerfiles/${{ matrix.build }}/${{ matrix.os }}/Dockerfile
2021-09-13 19:36:12 +02:00
platforms: ${{ steps.platform.outputs.list }}
push: ${{ secrets.AUTO_PUSH_IMAGES }}
2021-09-14 14:36:19 +02:00
tags: ${{ steps.meta.outputs.tags }}
build-args: BUILD_BASE_IMAGE=${{ steps.base_build.outputs.base_build_image }}
2021-09-15 15:29:12 +02:00
labels: |
org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
2021-09-13 23:06:45 +02:00
- name: Image digest
2021-09-14 04:55:24 +02:00
run: |
echo ${{ steps.docker_build.outputs.digest }}
echo "${{ steps.docker_build.outputs.digest }}" > ${{ matrix.build }}_${{ matrix.os }}
2021-09-13 23:06:45 +02:00
2021-09-15 14:21:33 +02:00
- name: Upload SHA256 tag
uses: actions/upload-artifact@v2.2.4
2021-09-13 23:06:45 +02:00
with:
name: ${{ matrix.build }}_${{ matrix.os }}
path: ${{ matrix.build }}_${{ matrix.os }}
if-no-files-found: error
build_images:
2021-10-29 18:11:31 +02:00
timeout-minutes: 90
2021-09-14 02:18:47 +02:00
needs: [ "build_base_database", "init_build"]
2021-10-08 12:16:50 +02:00
name: Build ${{ matrix.build }} on ${{ matrix.os }}
2021-09-13 23:06:45 +02:00
strategy:
2021-09-14 14:36:19 +02:00
fail-fast: false
2021-09-13 23:06:45 +02:00
matrix:
2021-09-14 03:10:41 +02:00
build: ${{ fromJson(needs.init_build.outputs.components) }}
2021-09-14 02:17:14 +02:00
os: ${{ fromJson(needs.init_build.outputs.os) }}
2021-09-13 23:06:45 +02:00
runs-on: ubuntu-20.04
steps:
2021-09-14 16:14:38 +02:00
- uses: actions/checkout@v2.3.4
2021-09-13 23:06:45 +02:00
- name: Set up QEMU
2021-10-28 00:45:54 +02:00
uses: docker/setup-qemu-action@v1.2.0
with:
image: tonistiigi/binfmt:latest
platforms: all
2021-09-13 23:06:45 +02:00
- name: Set up Docker Buildx
2021-10-28 00:45:54 +02:00
uses: docker/setup-buildx-action@v1.6.0
with:
driver-opts: image=moby/buildkit:master
2021-09-13 23:06:45 +02:00
- name: Login to DockerHub
2021-10-14 23:27:40 +02:00
uses: docker/login-action@v1
2021-09-13 23:06:45 +02:00
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
2021-09-15 13:31:56 +02:00
- name: Prepare Platform list
id: platform
run: |
2021-09-15 16:48:48 +02:00
# Chromium on Alpine is available only on linux/amd64, linux/arm64 platforms
2021-10-28 12:58:15 +02:00
if ([ "${{ matrix.os }}" == "alpine" ] || [ "${{ matrix.os }}" == "centos" ]) && [ "${{ matrix.build }}" == "web-service" ]; then
2021-09-15 16:48:48 +02:00
platform_list="linux/amd64,linux/arm64"
2021-10-28 12:58:15 +02:00
# Chromium on Ubuntu is not available on s390x platform
elif [ "${{ matrix.os }}" == "ubuntu" ] && [ "${{ matrix.build }}" == "web-service" ]; then
platform_list="linux/amd64,linux/arm/v7,linux/arm64"
2021-09-15 16:48:48 +02:00
else
2021-10-09 10:12:02 +02:00
platform_list=$(jq -r '.["os-linux"].${{ matrix.os }} | join(",")' "./build.json")
2021-09-15 16:48:48 +02:00
fi
2021-09-15 13:31:56 +02:00
2021-10-28 00:45:54 +02:00
# Build only Agent and Agent2 on 386
if [ "${{ matrix.build }}" != "agent"* ]; then
platform_list="${platform_list#linux/386,}"
fi
2021-10-27 21:28:33 +02:00
# Can not compile Java applications on ppc64le
if [ "${{ matrix.build }}" == "java-gateway" ]; then
platform_list="${platform_list%linux/ppc64le}"
fi
platform_list="${platform_list%,}"
2021-09-15 13:31:56 +02:00
echo ::set-output name=list::$platform_list
2021-09-13 23:06:45 +02:00
- name: Detect Build Base Image
id: build_base_image
run: |
2021-09-17 01:47:46 +02:00
BUILD_BASE=$(jq -r '.components."${{ matrix.build }}"' "./build.json")
2021-09-13 23:06:45 +02:00
echo ::set-output name=build_base::${BUILD_BASE}
2021-09-15 14:21:33 +02:00
- name: Generate tags
2021-09-14 15:22:13 +02:00
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_REPOSITORY }}/zabbix-${{ matrix.build }}
tags: |
type=ref,event=branch,prefix=${{ matrix.os }}-
type=ref,event=branch,suffix=-${{ matrix.os }}
flavor: |
2021-10-08 00:13:22 +02:00
latest=false
2021-09-14 15:22:13 +02:00
2021-09-15 16:48:48 +02:00
- name: Download SHA256 tag for ${{ steps.build_base_image.outputs.build_base }}:${{ matrix.os }}
2021-09-15 14:21:33 +02:00
uses: actions/download-artifact@v2.0.10
2021-09-14 16:15:32 +02:00
if: ${{ matrix.build != 'snmptraps' }}
2021-09-13 23:06:45 +02:00
with:
name: ${{ steps.build_base_image.outputs.build_base }}_${{ matrix.os }}
2021-09-15 16:48:48 +02:00
- name: Retrieve ${{ steps.build_base_image.outputs.build_base }}:${{ matrix.os }} SHA256 tag
2021-09-14 14:36:19 +02:00
id: base_build
2021-09-14 16:15:32 +02:00
if: ${{ matrix.build != 'snmptraps' }}
2021-09-13 23:06:45 +02:00
run: |
BASE_TAG=$(cat ${{ steps.build_base_image.outputs.build_base }}_${{ matrix.os }})
2021-09-14 14:36:19 +02:00
BUILD_BASE_IMAGE=${{ env.DOCKER_REPOSITORY }}/zabbix-${{ steps.build_base_image.outputs.build_base }}@${BASE_TAG}
2021-09-13 23:06:45 +02:00
echo ::set-output name=base_tag::${BASE_TAG}
2021-09-14 14:36:19 +02:00
echo ::set-output name=base_build_image::${BUILD_BASE_IMAGE}
2021-09-13 23:06:45 +02:00
2021-09-15 16:48:48 +02:00
- name: Build ${{ matrix.build }}/${{ matrix.os }} and push
2021-09-13 23:06:45 +02:00
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./Dockerfiles/${{ matrix.build }}/${{ matrix.os }}
file: ./Dockerfiles/${{ matrix.build }}/${{ matrix.os }}/Dockerfile
2021-09-13 23:06:45 +02:00
platforms: ${{ steps.platform.outputs.list }}
2021-09-14 07:21:16 +02:00
push: ${{ secrets.AUTO_PUSH_IMAGES }}
2021-09-14 15:22:13 +02:00
tags: ${{ steps.meta.outputs.tags }}
2021-09-14 14:36:19 +02:00
build-args: BUILD_BASE_IMAGE=${{ steps.base_build.outputs.base_build_image }}
2021-09-15 15:29:12 +02:00
labels: |
org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
2021-09-13 19:36:12 +02:00
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}