Skip to content

Commit 807c0e6

Browse files
committed
prefer parsing ls vs. stat when looking up docker group id
1 parent 850bfd5 commit 807c0e6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ RELEASE_TAG ?= $(shell git rev-parse --abbrev-ref HEAD)
4747
RELEASE_SHA ?= $(shell git rev-parse --short HEAD)
4848

4949
DOCKER_SOCKET ?= /var/run/docker.sock
50-
DOCKER_GROUP_ID ?= $(shell if [[ "$$OSTYPE" == darwin* ]] || [[ "$$OSTYPE" == macos* ]]; then stat -f '%Dg' $(DOCKER_SOCKET) ; else stat -c '%g' $(DOCKER_SOCKET) ; fi)
50+
DOCKER_GROUP_ID ?= $(shell ls -ln $(DOCKER_SOCKET) | awk '{print $$4}')
5151

5252
# for docker-for-mac, we also add group-id of 50 ("authedusers") as moby seems to auto bind-mount /var/run/docker.sock w/ this ownership
5353
# @TODO investigate and remove this docker-for-mac kludge

lib.d/v1-runtime.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ v1-runtime(){
7676
DEX_WINDOW_FLAGS=${DEX_WINDOW_FLAGS:-"-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY"}
7777

7878
[ -z "$__api" ] && \
79-
{ "$__image did not specify an org.dockerland.dex.api label!" ; exit 1 ; }
79+
{ echo "$__image did not specify an org.dockerland.dex.api label!" ; exit 1 ; }
8080

8181
# if home is not an absolute path, make relative to $DEX_HOME/homes/
8282
[ "${DEX_DOCKER_HOME:0:1}" != '/' ] && \
@@ -159,10 +159,13 @@ v1-runtime(){
159159

160160
# map host docker socket and passthru docker vars
161161
case $(echo "$__host_docker" | awk '{print tolower($0)}') in rw|ro)
162-
docker_socket=/var/run/docker.sock
163-
docker_group=$(if [[ "$OSTYPE" == darwin* ]] || [[ "$OSTYPE" == macos* ]]; then stat -f '%Dg' $docker_socket ; else stat -c '%g' $docker_socket ; fi)
164-
__docker_volumes+=" $docker_socket:/var/run/docker.sock:$__host_docker $DOCKER_CERT_PATH $MACHINE_STORAGE_PATH"
165-
__docker_flags+=" --group-add=$docker_group"
162+
__docker_socket=${DOCKER_SOCKET:-/var/run/docker.sock}
163+
[ -S $__docker_socket ] || {
164+
echo "image requests docker, but $__docker_socket is not a valid socket"
165+
exit 1
166+
}
167+
__docker_volumes+=" $__docker_socket:/var/run/docker.sock:$__host_docker $DOCKER_CERT_PATH $MACHINE_STORAGE_PATH"
168+
__docker_flags+=" --group-add=$(ls -ln $__docker_socket | awk '{print $4}')"
166169
__docker_envars+=" DOCKER_* MACHINE_STORAGE_PATH"
167170
esac
168171

0 commit comments

Comments
 (0)