Create helper OCI images for use in CI. (#899)

This commit is contained in:
Felix Fontein
2024-06-28 22:59:20 +02:00
committed by GitHub
parent ad9d362336
commit d334c2362f
6 changed files with 163 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
#!/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
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; do
rm -f "main-${ARCH}"
GOARCH="${ARCH}" go build -ldflags "-s -w" -o "main-${ARCH}" main.go
WORKING_CONTAINER="$(buildah from --arch "${ARCH}" scratch)"
buildah copy "${WORKING_CONTAINER}" "main-${ARCH}" "/runme"
buildah config --entrypoint '["/runme"]' "${WORKING_CONTAINER}"
buildah commit --manifest "${IMAGE_NAME}" "${WORKING_CONTAINER}"
rm -f "main-${ARCH}"
done
+1
View File
@@ -0,0 +1 @@
../build.sh
+34
View File
@@ -0,0 +1,34 @@
/*
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
*/
package main
import (
"fmt"
"os"
"time"
)
func main() {
var delay time.Duration
if len(os.Args) > 2 {
fmt.Fprintf(os.Stderr, "%s must have 0 or 1 argument, not %d arguments\n", os.Args[0], len(os.Args))
os.Exit(1)
} else if len(os.Args) == 2 {
var err error
delay, err = time.ParseDuration(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot parse delay duration: %s\n", err)
os.Exit(1)
}
if delay.Microseconds() < 0 {
fmt.Fprintf(os.Stderr, "Delay must not be negative!\n")
os.Exit(1)
}
}
fmt.Println("Hello!")
time.Sleep(delay)
}
+1
View File
@@ -0,0 +1 @@
../build.sh
+34
View File
@@ -0,0 +1,34 @@
/*
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
*/
package main
import (
"fmt"
"os"
"time"
)
func main() {
var delay time.Duration
if len(os.Args) > 2 {
fmt.Fprintf(os.Stderr, "%s must have 0 or 1 argument, not %d arguments\n", os.Args[0], len(os.Args))
os.Exit(1)
} else if len(os.Args) == 2 {
var err error
delay, err = time.ParseDuration(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot parse delay duration: %s\n", err)
os.Exit(1)
}
if delay.Microseconds() < 0 {
fmt.Fprintf(os.Stderr, "Delay must not be negative!\n")
os.Exit(1)
}
}
fmt.Println("World!")
time.Sleep(delay)
}