Skip to content

Commit

Permalink
Docker build as root fixups (cmu-db#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpkroth authored Jun 23, 2022
1 parent 01278bc commit 16e0ad6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ jobs:
DOCKER_BUILDKIT: 1
BENCHBASE_PROFILES: 'cockroachdb mariadb mysql postgres spanner phoenix sqlserver'
run: |
docker build --build-arg "BENCHBASE_PROFILES=$BENCHBASE_PROFILES" --build-arg TEST_TARGET=test --build-arg UID=$UID --build-arg GID=$UID \
docker build --build-arg "BENCHBASE_PROFILES=$BENCHBASE_PROFILES" --build-arg TEST_TARGET=test \
--build-arg CONTAINERUSER_UID=$UID --build-arg CONTAINERUSER_GID=$UID \
-t benchbase:latest -f ./docker/benchbase/Dockerfile --target fullimage .
- name: Run basic benchbase test from the docker image against postgres test DB
env:
Expand Down
9 changes: 5 additions & 4 deletions docker/benchbase/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ FROM --platform=linux maven:3.8.5-eclipse-temurin-17 AS devcontainer

# Add a containeruser that allows vscode/codespaces to map the local host user
# (often uid 1000) to some non-root user inside the container.
ARG UID=1000
ARG GID=1000
RUN addgroup --gid ${GID} containergroup \
&& adduser --disabled-password --gecos 'Container User' --uid ${UID} --gid ${GID} containeruser
ARG CONTAINERUSER_UID=1000
ARG CONTAINERUSER_GID=1000
RUN groupadd --non-unique --gid ${CONTAINERUSER_GID} containergroup \
&& useradd --non-unique --create-home --no-user-group --comment 'Container User' \
--uid ${CONTAINERUSER_UID} --gid ${CONTAINERUSER_GID} containeruser
RUN mkdir -p /benchbase/results && chown -R containeruser:containergroup /benchbase/
USER containeruser
ENV MAVEN_CONFIG=/home/containeruser/.m2
Expand Down
15 changes: 11 additions & 4 deletions docker/benchbase/build-full-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ http_proxy_port=''
https_proxy_host=''
https_proxy_port=''

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

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

GID=$(getent passwd $UID | cut -d: -f4)
CONTAINERUSER_UID="${CONTAINERUSER_UID:-$UID}"
if [ "$CONTAINERUSER_UID" -eq 0 ] && [ -n "${SUDO_UID:-}" ]; then
CONTAINERUSER_UID="$SUDO_UID"
fi
CONTAINERUSER_GID=${CONTAINERUSER_GID:-$(getent passwd "$CONTAINERUSER_UID" | cut -d: -f4)}
if [ -z "$CONTAINERUSER_GID" ]; then
echo "WARNING: missing CONTAINERUSER_GID." >&2
fi

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

0 comments on commit 16e0ad6

Please sign in to comment.