ansible-infra/ansible_collections/community/docker/tests/images/healthcheck/build.sh
Stefan Bethke 2aed20393f
Some checks failed
/ Ansible Lint (push) Failing after 5m45s
/ Ansible Lint (pull_request) Failing after 4m59s
Vendor Galaxy Roles and Collections
2026-02-06 22:07:16 +01:00

39 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
if [ ! -e main.go ]; then
echo "Must be run in a directory that contains main.go."
exit 1
fi
PROGRAMS="main is-healthy make-healthy"
set -eux
IMAGE_NAME="${1:-localhost/$(basename "$(pwd)"):latest}"
podman manifest rm "${IMAGE_NAME}" || true
podman image rm "${IMAGE_NAME}" || true
buildah manifest create "${IMAGE_NAME}"
for ARCH in amd64 arm64 386; do
for PROGRAM in ${PROGRAMS}; do
rm -f "${PROGRAM}-${ARCH}"
GOARCH="${ARCH}" go build -ldflags "-s -w" -o "${PROGRAM}-${ARCH}" "${PROGRAM}.go"
done
# Need format=docker for health checks to work
WORKING_CONTAINER="$(buildah from --arch "${ARCH}" --format docker scratch)"
for PROGRAM in ${PROGRAMS}; do
buildah copy "${WORKING_CONTAINER}" "${PROGRAM}-${ARCH}" "/${PROGRAM}"
done
buildah config --entrypoint '["/main"]' "${WORKING_CONTAINER}"
buildah config --healthcheck 'CMD /is-healthy' "${WORKING_CONTAINER}"
buildah config --healthcheck-interval 1s "${WORKING_CONTAINER}"
buildah config --healthcheck-retries 1 "${WORKING_CONTAINER}"
buildah config --healthcheck-start-period 10s "${WORKING_CONTAINER}"
buildah commit --format docker --manifest "${IMAGE_NAME}" "${WORKING_CONTAINER}"
for PROGRAM in ${PROGRAMS}; do
rm -f "${PROGRAM}-${ARCH}"
done
done