Skip to content

Commit

Permalink
Extracted common portions of generic-* files into common.sh, made it …
Browse files Browse the repository at this point in the history
…docker+podman compatible
  • Loading branch information
GreyCat committed Sep 9, 2024
1 parent d7f1042 commit ac9c3f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
25 changes: 25 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
detect_docker()
{
if docker --version >/dev/null 2>/dev/null; then
DOCKER_BIN=docker
elif podman --version >/dev/null 2>/dev/null; then
DOCKER_BIN=podman
EXTRA_OPTS='--security-opt label=disable'
else
echo "ERROR: Docker or Podman binary not found."
exit 1
fi
}

# Determine image name from current working directory
derive_img_name()
{
local ALL=$(pwd | sed 's,^.*/src/,,')
local TARGET=$(echo "$ALL" | cut -d/ -f1)
local REST=$(echo "$ALL" | cut -d/ -f2)

IMG_NAME="kaitai-$TARGET-$REST"
}

detect_docker
derive_img_name
8 changes: 2 additions & 6 deletions src/generic-build
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ if [ ! -f ../../../LICENSE ]; then
exit 1
fi

ALL=$(pwd | sed 's,^.*/src/,,')
TARGET=$(echo "$ALL" | cut -d/ -f1)
REST=$(echo "$ALL" | cut -d/ -f2)

IMG_NAME="kaitai-$TARGET-$REST"
. ../../../common.sh

mkdir -p 4img
rsync -av ../../_common/ 4img
Expand All @@ -29,4 +25,4 @@ if [ -f prebuild ]; then
. ./prebuild
fi

docker build -t "$IMG_NAME" --label io.kaitai.ci=true .
"$DOCKER_BIN" $EXTRA_ARGS build -t "$IMG_NAME" --label io.kaitai.ci=true .
9 changes: 2 additions & 7 deletions src/generic-run-it
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ if [ ! -f ../../../LICENSE ]; then
exit 1
fi

ALL=$(pwd | sed 's,^.*/src/,,')
TARGET=$(echo "$ALL" | cut -d/ -f1)
REST=$(echo "$ALL" | cut -d/ -f2)
. ../../../common.sh

# Determine image name from determined location
IMG_NAME="kaitai-$TARGET-$REST"

docker run --rm -it "$IMG_NAME" /bin/sh
"$DOCKER_BIN" $EXTRA_ARGS run --rm -it "$IMG_NAME" /bin/sh

0 comments on commit ac9c3f0

Please sign in to comment.