Skip to content

Commit 16e0ad6

Browse files
authored
Docker build as root fixups (#194)
1 parent 01278bc commit 16e0ad6

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.github/workflows/maven.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ jobs:
386386
DOCKER_BUILDKIT: 1
387387
BENCHBASE_PROFILES: 'cockroachdb mariadb mysql postgres spanner phoenix sqlserver'
388388
run: |
389-
docker build --build-arg "BENCHBASE_PROFILES=$BENCHBASE_PROFILES" --build-arg TEST_TARGET=test --build-arg UID=$UID --build-arg GID=$UID \
389+
docker build --build-arg "BENCHBASE_PROFILES=$BENCHBASE_PROFILES" --build-arg TEST_TARGET=test \
390+
--build-arg CONTAINERUSER_UID=$UID --build-arg CONTAINERUSER_GID=$UID \
390391
-t benchbase:latest -f ./docker/benchbase/Dockerfile --target fullimage .
391392
- name: Run basic benchbase test from the docker image against postgres test DB
392393
env:

docker/benchbase/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ FROM --platform=linux maven:3.8.5-eclipse-temurin-17 AS devcontainer
2828

2929
# Add a containeruser that allows vscode/codespaces to map the local host user
3030
# (often uid 1000) to some non-root user inside the container.
31-
ARG UID=1000
32-
ARG GID=1000
33-
RUN addgroup --gid ${GID} containergroup \
34-
&& adduser --disabled-password --gecos 'Container User' --uid ${UID} --gid ${GID} containeruser
31+
ARG CONTAINERUSER_UID=1000
32+
ARG CONTAINERUSER_GID=1000
33+
RUN groupadd --non-unique --gid ${CONTAINERUSER_GID} containergroup \
34+
&& useradd --non-unique --create-home --no-user-group --comment 'Container User' \
35+
--uid ${CONTAINERUSER_UID} --gid ${CONTAINERUSER_GID} containeruser
3536
RUN mkdir -p /benchbase/results && chown -R containeruser:containergroup /benchbase/
3637
USER containeruser
3738
ENV MAVEN_CONFIG=/home/containeruser/.m2

docker/benchbase/build-full-image.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ http_proxy_port=''
1313
https_proxy_host=''
1414
https_proxy_port=''
1515

16-
if echo "$http_proxy" | egrep -q 'http[s]?://[^:]+:[0-9]+[/]?$'; then
16+
if echo "${http_proxy:-}" | egrep -q 'http[s]?://[^:]+:[0-9]+[/]?$'; then
1717
http_proxy_host=$(echo "$http_proxy" | sed -r -e 's|^http[s]?://([^:]+):([0-9]+)[/]?$|\1|')
1818
http_proxy_port=$(echo "$http_proxy" | sed -r -e 's|^http[s]?://([^:]+):([0-9]+)[/]?$|\2|')
1919
fi
2020

21-
if echo "$https_proxy" | egrep -q 'http[s]?://[^:]+:[0-9]+[/]?$'; then
21+
if echo "${https_proxy:-}" | egrep -q 'http[s]?://[^:]+:[0-9]+[/]?$'; then
2222
https_proxy_host=$(echo "$https_proxy" | sed -r -e 's|^http[s]?://([^:]+):([0-9]+)[/]?$|\1|')
2323
https_proxy_port=$(echo "$https_proxy" | sed -r -e 's|^http[s]?://([^:]+):([0-9]+)[/]?$|\2|')
2424
fi
@@ -37,11 +37,18 @@ else
3737
exit 1
3838
fi
3939

40-
GID=$(getent passwd $UID | cut -d: -f4)
40+
CONTAINERUSER_UID="${CONTAINERUSER_UID:-$UID}"
41+
if [ "$CONTAINERUSER_UID" -eq 0 ] && [ -n "${SUDO_UID:-}" ]; then
42+
CONTAINERUSER_UID="$SUDO_UID"
43+
fi
44+
CONTAINERUSER_GID=${CONTAINERUSER_GID:-$(getent passwd "$CONTAINERUSER_UID" | cut -d: -f4)}
45+
if [ -z "$CONTAINERUSER_GID" ]; then
46+
echo "WARNING: missing CONTAINERUSER_GID." >&2
47+
fi
4148

4249
set -x
4350
docker build --progress=plain --build-arg=http_proxy=${http_proxy:-} --build-arg=https_proxy=${https_proxy:-} \
4451
--build-arg MAVEN_OPTS="-Dhttp.proxyHost=${http_proxy_host} -Dhttp.proxyPort=${http_proxy_port} -Dhttps.proxyHost=${https_proxy_host} -Dhttps.proxyPort=${https_proxy_port}" \
4552
--build-arg BENCHBASE_PROFILES="${BENCHBASE_PROFILES}" \
46-
--build-arg UID=$UID --build-arg GID=$GID \
53+
--build-arg CONTAINERUSER_UID="$CONTAINERUSER_UID" --build-arg CONTAINERUSER_GID="$CONTAINERUSER_GID" \
4754
-t $tag -f ./docker/benchbase/Dockerfile --target $target .

0 commit comments

Comments
 (0)