Added code

This commit is contained in:
Foat Akhmadeev 2024-12-16 13:11:33 +03:00
parent 0f384e4e0d
commit 1951cea3c5
4 changed files with 294 additions and 1 deletions

58
scripts/run.sh Executable file
View file

@ -0,0 +1,58 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t '
### LOGIN
if [[ -n "$REGISTRY" && -n "$USERNAME" && -n "$PASSWORD" ]]; then
podman login --storage-driver=overlay $REGISTRY -u $USERNAME -p $PASSWORD
fi
generate_args() {
local input_args="$1"
local prefix="$2"
local output=""
if [ -n "$input_args" ]; then
output="$(echo "$input_args" | tr -s '+' ' ' | sed "s/[^ ]* */$prefix &/g")"
fi
echo "$output"
}
### BUILD
if [[ -n "$DOCKERFILE" ]]; then
CREATED="$(date '+%Y-%m-%dT%T')"
REVISION="$REVISION"
SOURCE="$SOURCE"
echo "Main labels: $CREATED $REVISION $SOURCE"
TAGS=$(generate_args "$ACTION_TAGS" "-t")
echo "Tags: $TAGS"
LABELS=$(generate_args "$ACTION_LABELS" "--label")
echo "Labels: $LABELS"
BUILD_ARGS=$(generate_args "$ACTION_BUILD_ARGS" "--build-arg")
echo "Build args: $BUILD_ARGS"
EXTRA_ARGS=$(generate_args "$ACTION_EXTRA_ARGS" "")
echo "Extra args: $EXTRA_ARGS"
podman build --platform="linux/amd64" \
--storage-driver=overlay \
--pull=true \
--label image.created="$CREATED" \
--label image.revision="$REVISION" \
--label image.source="$SOURCE" \
$TAGS \
$LABELS \
$BUILD_ARGS \
$EXTRA_ARGS \
-f "$DOCKERFILE" \
.
fi
if [[ -n "$PUSH" && "$PUSH" == "true" ]]; then
TAGS=$(generate_args "$ACTION_TAGS" "")
echo "Tags: $TAGS"
podman push --storage-driver=overlay $TAGS
fi