From a7adc643b643137a7a341421af44746d1bde1ba3 Mon Sep 17 00:00:00 2001 From: cirolosapio Date: Tue, 26 Sep 2023 01:49:32 +0200 Subject: [PATCH] update --- src/alpine-docker/devcontainer-feature.json | 6 +++++- src/alpine-docker/install.sh | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/alpine-docker/devcontainer-feature.json b/src/alpine-docker/devcontainer-feature.json index 676ae81..cd9d98b 100644 --- a/src/alpine-docker/devcontainer-feature.json +++ b/src/alpine-docker/devcontainer-feature.json @@ -1,10 +1,14 @@ { "name": "alpine-docker", "id": "alpine-docker", - "version": "0.0.4", + "version": "0.0.5", "description": "Installs docker and docker-compose on alpine", "documentationURL": "https://github.com/cirolosapio/devcontainers-features/tree/main/src/alpine-docker", "options": { + "hostDockerGid": { + "type": "string", + "description": "Docker group id on the host machine (retrieve with \"getent group docker | cut -d: -f3\"" + }, "installDockerCompose": { "type": "boolean", "default": false, diff --git a/src/alpine-docker/install.sh b/src/alpine-docker/install.sh index 74c1eba..2bbaccf 100644 --- a/src/alpine-docker/install.sh +++ b/src/alpine-docker/install.sh @@ -6,6 +6,22 @@ echo "Activating feature 'alpine-docker'" apk add --no-cache docker +CURRENT_USER=$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd) +echo "CURRENT_USER is $CURRENT_USER" +echo "HOST_DOCKER_GID is $HOSTDOCKERGID" + +HOST_DOCKER_GROUP=$(getent group $HOSTDOCKERGID | cut -d: -f1) + +if [[ -z $HOST_DOCKER_GROUP ]]; then + echo "HOST_DOCKER_GROUP is empty, creating new group 'host-docker'" + addgroup -g $HOSTDOCKERGID host-docker + HOST_DOCKER_GROUP=host-docker +else + echo "HOST_DOCKER_GROUP is already used, using existing group '$HOST_DOCKER_GROUP'" +fi + +addgroup $CURRENT_USER $HOST_DOCKER_GROUP + if [[ $INSTALLDOCKERCOMPOSE == "true" ]]; then apk add --no-cache docker-compose fi