Debian Codegraph @

ansible_collections/community/docker/tests/images/simple-2/build.sh

raw
1 #!/usr/bin/env bash
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 if [ ! -e main.go ]; then
7 echo "Must be run in a directory that contains main.go."
8 exit 1
9 fi
10
11 set -eux
12 IMAGE_NAME="${1:-localhost/$(basename "$(pwd)"):latest}"
13 podman manifest rm "${IMAGE_NAME}" || true
14 podman image rm "${IMAGE_NAME}" || true
15 buildah manifest create "${IMAGE_NAME}"
16 for ARCH in amd64 arm64 386; do
17 rm -f "main-${ARCH}"
18 GOARCH="${ARCH}" go build -ldflags "-s -w" -o "main-${ARCH}" main.go
19
20 WORKING_CONTAINER="$(buildah from --arch "${ARCH}" scratch)"
21 buildah copy "${WORKING_CONTAINER}" "main-${ARCH}" "/runme"
22 buildah config --entrypoint '["/runme"]' "${WORKING_CONTAINER}"
23 buildah commit --manifest "${IMAGE_NAME}" "${WORKING_CONTAINER}"
24
25 rm -f "main-${ARCH}"
26 done