-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: added support for Podman as container engine #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| # Common docker functions. | ||
| # Common container functions. | ||
|
|
||
| function get_docker_image_id() { | ||
| local IMAGE_NAME=$1 | ||
| echo "$(docker images -q $IMAGE_NAME)" | ||
| echo "$($CONTAINER_ENGINE images -q $IMAGE_NAME)" | ||
| } | ||
|
|
||
| function get_docker_container_id() { | ||
| local CONTAINER_NAME=$1 | ||
| echo "$(docker ps -a -q --filter ancestor=$CONTAINER_NAME)" | ||
| echo "$($CONTAINER_ENGINE ps -a -q --filter ancestor=$CONTAINER_NAME)" | ||
| } | ||
|
|
||
| function stop_docker_container() { | ||
|
|
@@ -16,7 +16,7 @@ function stop_docker_container() { | |
|
|
||
| local CONTAINER_ID=$(get_docker_container_id $CONTAINER_NAME) | ||
| if [ ! -z "$CONTAINER_ID" ]; then | ||
| docker container stop $CONTAINER_ID | ||
| $CONTAINER_ENGINE container stop $CONTAINER_ID | ||
| else | ||
| builder_echo "No Docker container to stop" | ||
| fi | ||
|
|
@@ -31,14 +31,14 @@ function clean_docker_container() { | |
|
|
||
| local CONTAINER_ID=$(get_docker_container_id $CONTAINER_NAME) | ||
| if [ ! -z "$CONTAINER_ID" ]; then | ||
| docker container rm $CONTAINER_ID | ||
| $CONTAINER_ENGINE container rm $CONTAINER_ID | ||
| else | ||
| echo "No Docker container to clean" | ||
| fi | ||
|
|
||
| local IMAGE_ID=$(get_docker_image_id $IMAGE_NAME) | ||
| if [ ! -z "$IMAGE_ID" ]; then | ||
| docker rmi $IMAGE_NAME | ||
| $CONTAINER_ENGINE rmi $IMAGE_NAME | ||
| else | ||
| echo "No Docker image to clean" | ||
| fi | ||
|
|
@@ -54,21 +54,25 @@ function build_docker_container() { | |
| local IMAGE_NAME=$1 | ||
| local CONTAINER_NAME=$2 | ||
| local BUILDER_CONFIGURATION="release" | ||
| local FILE= | ||
| local TARGET=. | ||
| if [[ $# -ge 3 ]]; then | ||
| BUILDER_CONFIGURATION=$3 | ||
| fi | ||
| if [[ $# -ge 4 ]]; then | ||
| TARGET="-f $4 ." | ||
| FILE="-f $4 " | ||
| elif [[ "${CONTAINER_ENGINE}" == "docker" ]]; then | ||
| FILE="-f Dockerfile " | ||
| elif [[ "${CONTAINER_ENGINE}" == "podman" ]]; then | ||
| FILE="-f Podmanfile " | ||
|
Comment on lines
+64
to
+67
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these really needed? Won't podman use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Podman uses "Dockerfile" for default to be compatible. Usually you can run Podman with the same file as Docker uses but the Dockerfile must address specific requirements of Podman e.g. full path to images. If you like you can test the build on Docker with the Podmanfile, it should work.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if we can get to the point where Podman and Docker can use the same file, that will definitely be better for maintenance. The differences seem pretty minimal at present, so can we get to a point where we can merge them?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, absolutely. But even if Docker works perfectly with the slightly modified version, I probably would stick to the current solution of the script. Just to have the ability to switch the files. For all projects where we are sure that we can use the same file, I would could create a symbolic link instead. In case of the Dockerfile for |
||
| fi | ||
|
|
||
| _verify_vendor_is_not_folder | ||
|
|
||
| builder_echo "Building using $BUILDER_CONFIGURATION configuration" | ||
|
|
||
|
|
||
| # Download docker image. --mount option requires BuildKit | ||
| DOCKER_BUILDKIT=1 docker build -t $IMAGE_NAME --build-arg BUILDER_CONFIGURATION="${BUILDER_CONFIGURATION}" $TARGET | ||
| DOCKER_BUILDKIT=1 $CONTAINER_ENGINE build -t $IMAGE_NAME --build-arg BUILDER_CONFIGURATION="${BUILDER_CONFIGURATION}" $FILE $TARGET | ||
| } | ||
|
|
||
| function start_docker_container() { | ||
|
|
@@ -122,7 +126,7 @@ function start_docker_container() { | |
| ADD_HOST="--add-host host.docker.internal:host-gateway" | ||
| fi | ||
|
|
||
| docker run --rm -d -p $PORT:80 -v "${DOCKER_BINDING}" \ | ||
| $CONTAINER_ENGINE run --rm -d -p $PORT:80 -v "${DOCKER_BINDING}" \ | ||
| -e S_KEYMAN_COM=localhost:$PORT_S_KEYMAN_COM \ | ||
| -e API_KEYMAN_COM=localhost:$PORT_API_KEYMAN_COM \ | ||
| --name $CONTAINER_DESC \ | ||
|
|
@@ -137,7 +141,7 @@ function start_docker_container() { | |
| builder_die "Docker container appears to have failed to start in order to create link to vendor/" | ||
| fi | ||
|
|
||
| docker exec -i $CONTAINER_ID sh -c "ln -s /var/www/vendor vendor && chown -R www-data:www-data vendor" | ||
| $CONTAINER_ENGINE exec -i $CONTAINER_ID sh -c "ln -s /var/www/vendor vendor && chown -R www-data:www-data vendor" | ||
| fi | ||
|
|
||
| # after starting container, we want to run an init script if it is present | ||
|
|
@@ -149,8 +153,36 @@ function start_docker_container() { | |
|
|
||
| cmd="./resources/init-container.sh ${BUILDER_CONFIGURATION}" | ||
| builder_echo green "cmd is ${cmd}" | ||
| docker exec -i $CONTAINER_ID sh -c "${cmd}" | ||
| $CONTAINER_ENGINE exec -i $CONTAINER_ID sh -c "${cmd}" | ||
| fi | ||
|
|
||
| builder_echo green "Listening on http://$HOST:$PORT" | ||
| } | ||
| } | ||
|
|
||
| # Returns 0 if the specified container engine is available, 1 otherwise | ||
| _is_container_engine() { | ||
| local engine="$1" | ||
| if command -v "$engine" >/dev/null 2>&1; then | ||
| return 0 | ||
| else | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| _get_container_engine() { | ||
| export CONTAINER_ENGINE | ||
| if _is_container_engine "docker"; then | ||
| CONTAINER_ENGINE="docker" | ||
| elif _is_container_engine "podman"; then | ||
| CONTAINER_ENGINE="podman" | ||
| else | ||
| builder_die "No supported container engine found. Please install Docker or Podman to run containerized builds." | ||
| fi | ||
| } | ||
|
|
||
| ################################################################################ | ||
| # Final initialization | ||
| ################################################################################ | ||
|
|
||
| _get_container_engine | ||
| builder_echo "Using container engine: $CONTAINER_ENGINE" | ||
Uh oh!
There was an error while loading. Please reload this page.