build_image #1155
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: Docker Build | |
on: | |
push: | |
repository_dispatch: | |
types: build_image | |
jobs: | |
getversion: | |
runs-on: ubuntu-latest | |
name: Obtain ES Version | |
outputs: | |
zm_version: ${{ steps.set-version.outputs.zm_version }} | |
es_version: ${{ steps.set-version.outputs.es_version }} | |
steps: | |
# Only build latest tagged if release version | |
- name: Set ES Build Version | |
id: set-version | |
run: | | |
set -x | |
if [[ ${GITHUB_REF} == refs/tags/* ]]; then | |
NEW_VERSION=${GITHUB_REF##*/} | |
ZM_VERSION=$(echo "${NEW_VERSION}" | grep -Po "(?<=zm_v)(.*)(?=-)") | |
ES_VERSION=$(echo "${NEW_VERSION}" | grep -Po "(?<=es_)(.*)($)") | |
elif [[ "${{ github.event.client_payload.tagged }}" == "true" ]]; then | |
# Build tag/release version | |
ES_VERSION=$(wget \ | |
-qO - https://api.github.com/repos/ZoneMinder/zmeventnotification/releases/latest \ | |
| awk '/tag_name/{print $4;exit}' FS='[""]') | |
ZM_VERSION=${{ github.event.client_payload.zm_version }} | |
else | |
# Build from latest ES commit | |
ES_VERSION=$(wget \ | |
-qO - https://api.github.com/repos/ZoneMinder/zmeventnotification/commits/master \ | |
| awk '/sha/{print $4;exit}' FS='[""]') | |
ZM_VERSION="main" | |
fi | |
echo "::set-output name=zm_version::${ZM_VERSION}" | |
echo "::set-output name=es_version::${ES_VERSION}" | |
echo Building with ZM "${ZM_VERSION}" and ES "${ES_VERSION}" | |
build: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
needs: | |
- getversion | |
env: | |
ZM_VERSION: ${{ needs.getversion.outputs.zm_version }} | |
ES_VERSION: ${{ needs.getversion.outputs.es_version }} | |
strategy: | |
matrix: | |
include: | |
- arch: linux/386 | |
arch_friendly: i386 | |
s6_arch: x86 | |
- arch: linux/amd64 | |
arch_friendly: amd64 | |
s6_arch: amd64 | |
- arch: linux/arm/v7 | |
arch_friendly: armv7 | |
s6_arch: armhf | |
- arch: linux/arm64 | |
arch_friendly: arm64 | |
s6_arch: aarch64 | |
steps: | |
- name: Checkout | |
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 | |
with: | |
driver-opts: | | |
env.BUILDKIT_STEP_LOG_MAX_SIZE=10000000 | |
env.BUILDKIT_STEP_LOG_MAX_SPEED=100000000 | |
install: true | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
continue-on-error: true | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ matrix.arch }}-${{ env.ZM_VERSION }}-${{ env.ES_VERSION }}-${{ github.sha }} | |
restore-keys: | | |
${{ matrix.arch }}-${{ env.ZM_VERSION }}-${{ env.ES_VERSION }}- | |
${{ matrix.arch }}-${{ env.ZM_VERSION }}- | |
- name: Build ZoneMinder | |
run: | | |
set -x | |
docker build \ | |
--build-arg ZM_VERSION=${ZM_VERSION} \ | |
--build-arg ES_VERSION=${ES_VERSION} \ | |
--tag ci:${{ github.run_number }} \ | |
--platform ${{ matrix.arch }} \ | |
--progress plain \ | |
--file ./Dockerfile \ | |
--cache-from type=local,src=/tmp/.buildx-cache \ | |
--cache-to type=local,dest=/tmp/.buildx-cache-new \ | |
--load \ | |
. | |
# Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
- name: Inspect | |
run: | | |
set -x | |
docker image inspect ci:${{ github.run_number }} | |
- name: Save tarball | |
run: | | |
set -x | |
docker save ci:${{ github.run_number }} | gzip > ci-${{ matrix.arch_friendly }}-${{ github.run_number }}.tar.gz | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ci-${{ matrix.arch_friendly }}-${{ github.run_number }} | |
path: ci-${{ matrix.arch_friendly }}-${{ github.run_number }}.tar.gz | |
test: | |
needs: build | |
name: Test Image | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
arch: | |
- i386 | |
- amd64 | |
- armv7 | |
- arm64 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Download container artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: ci-${{ matrix.arch }}-${{ github.run_number }} | |
- name: Import image | |
run: | | |
set -x | |
docker load --input ci-${{ matrix.arch }}-${{ github.run_number }}.tar.gz | |
docker tag ci:${{ github.run_number }} ci:latest | |
# Fails if zoneminder is not up | |
- name: Start image twice | |
timeout-minutes: 5 | |
run: | | |
set -x | |
cd testsautomated | |
docker-compose up & | |
sleep 60 | |
if [ ! "$(docker ps -q -f name=zoneminder)" ]; then | |
exit 1 | |
fi | |
docker-compose down | |
docker-compose up & | |
sleep 60 | |
docker-compose down | |
# Fails if zoneminder fails to stop normally | |
- name: Start image and stop zoneminder | |
timeout-minutes: 5 | |
run: | | |
set -x | |
cd testsautomated | |
docker-compose up & | |
sleep 60 | |
docker stop zoneminder | |
docker-compose down | |
# Fails if zoneminder doesn't stop when db is down | |
- name: Start image and stop db | |
timeout-minutes: 5 | |
run: | | |
set -x | |
cd testsautomated | |
docker-compose up & | |
sleep 120 | |
docker stop db | |
sleep 60 | |
if [ "$(docker ps -q -f name=zoneminder)" ]; then | |
exit 1 | |
fi | |
release: | |
needs: | |
- getversion | |
- test | |
name: Upload Release Asset | |
if: ${{ github.event.client_payload.tagged == 'true' || startsWith(github.ref, 'refs/tags/') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download container artifact | |
uses: actions/download-artifact@v2 | |
- name: Upload Release Asset | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: zm_v${{ needs.getversion.outputs.zm_version }}-es_${{ needs.getversion.outputs.es_version }} | |
files: ci-*/ci-*.tar.gz | |
body: Automated release of ZoneMinder v${{ needs.getversion.outputs.zm_version }} with event server ${{ needs.getversion.outputs.es_version }} | |
draft: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
publish: | |
name: Publish Image | |
runs-on: ubuntu-latest | |
needs: | |
- getversion | |
- test | |
env: | |
ZM_VERSION: zm_v${{ needs.getversion.outputs.zm_version }} | |
ES_VERSION: es_${{ needs.getversion.outputs.es_version }} | |
strategy: | |
matrix: | |
arch: | |
- i386 | |
- amd64 | |
- armv7 | |
- arm64 | |
registry: | |
- { | |
url: "https://index.docker.io/v1/", | |
username: DOCKER_USERNAME, | |
password: DOCKER_PASSWORD, | |
repo: yaoa/eventserver-base | |
} | |
- { | |
url: ghcr.io/zoneminder-containers, | |
username: GCHR_USERNAME, | |
password: GHCR_PAT, | |
repo: ghcr.io/zoneminder-containers/eventserver-base | |
} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Download container artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: ci-${{ matrix.arch }}-${{ github.run_number }} | |
- name: Import image | |
run: | | |
docker load --input ci-${{ matrix.arch }}-${{ github.run_number }}.tar.gz | |
- name: Docker login | |
run: | | |
docker login ${{ matrix.registry.url }} -u ${{ secrets[matrix.registry.username] }} -p ${{ secrets[matrix.registry.password] }} | |
# Main gets pushed to branch name and nightly | |
# Tags get latest and ref name (aka the tag name) | |
# push to ref name | |
- name: Push image (ref) | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
./publish.py \ | |
--tag ${GITHUB_REF##*/} \ | |
--repo ${{ matrix.registry.repo }} \ | |
--image \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} \ | |
--arch ${{ matrix.arch }} \ | |
--image-name ci:${{ github.run_number }} | |
# push main branch to nightly tag | |
- name: Push image (nightly) | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
./publish.py \ | |
--tag nightly \ | |
--repo ${{ matrix.registry.repo }} \ | |
--image \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} \ | |
--arch ${{ matrix.arch }} \ | |
--image-name ci:${{ github.run_number }} | |
# if its tagged, push to tag name and latest | |
- name: Push image (tag) | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
run: | | |
./publish.py \ | |
--tag ${GITHUB_REF##*/} \ | |
--repo ${{ matrix.registry.repo }} \ | |
--image \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} \ | |
--arch ${{ matrix.arch }} \ | |
--image-name ci:${{ github.run_number }} \ | |
--latest | |
# if its tagged, push to release | |
- name: Push image (tag) | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
run: | | |
./publish.py \ | |
--tag release \ | |
--repo ${{ matrix.registry.repo }} \ | |
--image \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} \ | |
--arch ${{ matrix.arch }} \ | |
--image-name ci:${{ github.run_number }} | |
create_manifest: | |
name: Create Manifest | |
runs-on: ubuntu-latest | |
needs: | |
- getversion | |
- publish | |
env: | |
ZM_VERSION: zm_v${{ needs.getversion.outputs.zm_version }} | |
ES_VERSION: es_${{ needs.getversion.outputs.es_version }} | |
DOCKER_CLI_EXPERIMENTAL: "enabled" | |
strategy: | |
matrix: | |
registry: | |
- { | |
url: "https://index.docker.io/v1/", | |
username: DOCKER_USERNAME, | |
password: DOCKER_PASSWORD, | |
repo: yaoa/eventserver-base | |
} | |
- { | |
url: ghcr.io/zoneminder-containers, | |
username: GCHR_USERNAME, | |
password: GHCR_PAT, | |
repo: ghcr.io/zoneminder-containers/eventserver-base | |
} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Docker login | |
run: | | |
docker login ${{ matrix.registry.url }} -u ${{ secrets[matrix.registry.username] }} -p ${{ secrets[matrix.registry.password] }} | |
# Main gets pushed to branch name and nightly | |
# Tags get latest and ref name (aka the tag name) | |
# push to ref name | |
- name: Push image (ref) | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
./publish.py \ | |
--tag ${GITHUB_REF##*/} \ | |
--repo ${{ matrix.registry.repo }} \ | |
--manifest \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} | |
# push main branch to nightly tag | |
- name: Push image (nightly) | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
./publish.py \ | |
--tag nightly \ | |
--repo ${{ matrix.registry.repo }} \ | |
--manifest \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} | |
# if its tagged, push to tag name and latest | |
- name: Push image (tag) | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
run: | | |
./publish.py \ | |
--tag ${GITHUB_REF##*/} \ | |
--repo ${{ matrix.registry.repo }} \ | |
--manifest \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} \ | |
--latest | |
# if its tagged, push to release | |
- name: Push image (tag) | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
run: | | |
./publish.py \ | |
--tag release \ | |
--repo ${{ matrix.registry.repo }} \ | |
--manifest \ | |
--github-sha ${ZM_VERSION}-${ES_VERSION} \ | |
--run-number ${{ github.run_number }} |