diff --git a/config.env b/config.env new file mode 100644 index 0000000..316672f --- /dev/null +++ b/config.env @@ -0,0 +1 @@ +TARGET_IMAGE_TEMPLATE='edge-registry.itix.fr/demo-edge-retail/${SCENARIO}:latest' diff --git a/generic/Containerfile b/generic/Containerfile index f055071..ad70ad0 100644 --- a/generic/Containerfile +++ b/generic/Containerfile @@ -7,7 +7,10 @@ RUN </dev/null; for try in $(seq 0 12); do if ! /bin/true 5<> /dev/tcp/127.0.0.1/5432; then echo "Waiting for PostgreSQL to be available..."; sleep 5; else exit 0; fi; done; exit 1' diff --git a/scenario1/root/etc/greenboot/check/required.d/odoo-check.sh b/scenario1/root/etc/greenboot/check/required.d/odoo-check.sh new file mode 100755 index 0000000..1ee8abc --- /dev/null +++ b/scenario1/root/etc/greenboot/check/required.d/odoo-check.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -Eeuo pipefail +declare -a container_state=() +MAX_ATTEMPTS=60 + +for attempt in {1..$MAX_ATTEMPTS}; do + echo "Checking Odoo deployment ($attempt/$MAX_ATTEMPTS)..." + + state=1 + for container in odoo-db odoo-app; do + container_state=( $( ( podman inspect "$container" || true ) | jq -r '.[0].State.Status // "unknown", .[0].State.Health.Status // "unknown"') ) + echo "Container $container has state ${container_state[0]} and its health is ${container_state[1]}!" + if [[ "${container_state[0]}-${container_state[1]}" != "running-healthy" ]]; then + state=0 + fi + done + + if [[ $state -eq 1 ]]; then + echo "Odoo deployment is up and running!" + exit 0 + fi + + sleep 5 +done + +echo "Odoo deployment is not running correctly after $MAX_ATTEMPTS attempts!" +exit 1 diff --git a/scripts/build.sh b/scripts/build.sh index d2b797e..79738ef 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -7,8 +7,12 @@ if [[ "$UID" -ne 0 ]]; then exit 1 fi -. "$PWD/env.sh" +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi +TARGET_IMAGE="$1" OCI_REGISTRY="${TARGET_IMAGE%%/*}" SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" @@ -39,5 +43,5 @@ if [ ! -f "$REGISTRY_AUTH_FILE" ]; then podman login registry.redhat.io fi -podman build -t "${TARGET_IMAGE}" . +podman build --no-cache -t "${TARGET_IMAGE}" . podman push --sign-by-sigstore-private-key "$PROJECT_DIR/signing-key.private" --sign-passphrase-file "$PROJECT_DIR/signing-key.pass" "${TARGET_IMAGE}" diff --git a/scripts/buildall.sh b/scripts/buildall.sh new file mode 100755 index 0000000..e09221e --- /dev/null +++ b/scripts/buildall.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -Eeuo pipefail + +if [[ "$UID" -ne 0 ]]; then + echo "This command must be run as root!" + exit 1 +fi + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" + +. "$PROJECT_DIR/config.env" + +for dir in "$PROJECT_DIR"/{generic,scenario*}; do + if [ -d "$dir" -a -f "$dir/Containerfile" ]; then + export SCENARIO="${dir##*/}" + TARGET_IMAGE="$(echo -n "$TARGET_IMAGE_TEMPLATE" | envsubst)" + echo "Building container image $TARGET_IMAGE from $SCENARIO..." + pushd "$dir" > /dev/null + "$SCRIPT_DIR/build.sh" "$TARGET_IMAGE" + popd > /dev/null + fi +done