From 2ad89e4183e80a542f2fe47d7137263b7b6543ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Sun, 22 May 2022 21:05:09 +0100 Subject: [PATCH] chore: make contribute/start_docker work on Fedora MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docker-podman wrapper created volume mounts are owned by the root user inside the container, and the doom user wouldn't have write access. Need to specify --user-ns=keep-id flag to map $UID from the host to $UID from the container without using subuids: that way user inside container can modify. SELinux is on by default on Fedora36, thus volume mounts need to specify the 'Z' flag to relabel the directory being mounted. podman needs '--userns=keep-id' for permissions of mounted volumes to work inside the container. However docker doesn't recognize that flag (and doesn't need it, since it is running as root). Detect which of `docker` or `podman` is installed, and if it is podman add the extra flag. We need to check for podman first, because 'docker' might just be a wrapper that calls podman. Signed-off-by: Edwin Török --- tools/start_docker.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/start_docker.sh b/tools/start_docker.sh index 4e77d4d6c..22f809c33 100755 --- a/tools/start_docker.sh +++ b/tools/start_docker.sh @@ -1,10 +1,16 @@ #!/usr/bin/env bash - -if ! docker info > /dev/null 2>&1; then +DOCKER=$(command -v podman docker | head -n 1) +if ! "${DOCKER}" info > /dev/null 2>&1; then echo "This script uses docker, and it isn't running - please start docker and try again!" exit 1 fi +if [ $(basename "${DOCKER}") = "podman" ]; then + DOCKER_RUN_FLAGS="--userns=keep-id" +else + DOCKER_RUN_FLAGS= +fi + ############################################################ # Help # ############################################################ @@ -40,6 +46,7 @@ while getopts "b:h" option; do exit;; esac done +shift $((OPTIND-1)) cd "$SCRIPT_DIR" || exit @@ -87,30 +94,30 @@ echo "" echo "2. Setting up docker environment" # Ensure docker image exists -if [[ ! "$(docker images -q doom-nvim-contrib)" ]]; then +if [[ ! "$("${DOCKER}" images -q doom-nvim-contrib)" ]]; then echo " - Docker image does not exist. Building docker image..." - docker build -t doom-nvim-contrib . + "${DOCKER}" build -t doom-nvim-contrib . fi -if [ "$(docker ps -aq -f status=exited -f name=doom-nvim-contrib-container)" ]; then +if [ "$("${DOCKER}" ps -aq -f status=exited -f name=doom-nvim-contrib-container)" ]; then echo " - Cleaning up old container..." # cleanup - docker rm doom-nvim-contrib-container >> /dev/null + "${DOCKER}" rm doom-nvim-contrib-container >> /dev/null fi # Create docker container if haven't already echo " - Success! Running docker container doom-nvim-contrib-container..." mkdir -p "${SCRIPT_DIR}/local-share-nvim" "${SCRIPT_DIR}/workspace" echo "" -docker run \ +${DOCKER} run \ + ${DOCKER_RUN_FLAGS} \ -it \ -e UID="1000" \ -e GID="1000" \ - -v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim \ - -v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim \ - -v "$SCRIPT_DIR"/workspace:/home/doom/workspace \ + -v "$SCRIPT_DIR"/doom-nvim-contrib:/home/doom/.config/nvim:Z \ + -v "$SCRIPT_DIR"/local-share-nvim:/home/doom/.local/share/nvim:Z \ + -v "$SCRIPT_DIR"/workspace:/home/doom/workspace:Z \ --name doom-nvim-contrib-container \ --user doom \ - doom-nvim-contrib - - + doom-nvim-contrib \ + "$@"