Docker: Support optional non-default gerrit userid For some execution environments, the user with id 1000 cannot be used by the host user running docker. Meaning, that user 1000 is restricted or out of current user's control. Allow to pass the latter's own id to docker so the containers use that one instead as the gerrit user. Otherwise, docker's default id 1000 gets used as before this change. Using the proper id matters so containers are able to write to mounted volume directories and files. This is also the case for files manually handled by scripts run within containers. Bump the docker-compose version so the --build-arg option becomes usable. I.e., without having to explictly build each composed service. Replace the removed volumes_from clause accordingly with version 3's way of mounting the same volumes. Change-Id: If25f6dbfd835d9bf7fe1118aecd3945ac4ff7b65
diff --git a/src/test/docker/README.md b/src/test/docker/README.md index fd6818a..68030ae 100644 --- a/src/test/docker/README.md +++ b/src/test/docker/README.md
@@ -12,6 +12,25 @@ $ docker-compose build ``` +### Building the Docker VMs using a non-default user id + +``` + $ export GERRIT_UID=$(id -u) + $ docker-compose build --build-arg GERRIT_UID +``` + +Above, exporting that UID is optional and will be 1000 by default. +Build the gerrit images this way only if the user with id 1000 on your +host is not owned by you. For example, some corporate environments use a +restricted 1000 user (id). In that case, the containerized application +may fail to write towards the host (through volumes). + +That UID will be the one set for the containerized gerrit user. Latter's +group will remain as default (1000). This is because groups known from +the host need to be redefined for containers. Setting that user's group +in the container is not necessary for writing anyway, as opposed to its +user id. The individual gerrit user's writing permission does suffice. + ## How to run Use the 'up' target to startup the Docker Compose VMs.
diff --git a/src/test/docker/docker-compose.yaml b/src/test/docker/docker-compose.yaml index 6ea2438..b64d1ba 100644 --- a/src/test/docker/docker-compose.yaml +++ b/src/test/docker/docker-compose.yaml
@@ -1,4 +1,4 @@ -version: '2' +version: '3' services: @@ -58,7 +58,7 @@ - "29418:29418" networks: - gerrit-net - volumes_from: + volumes: - syslog-sidecar depends_on: - gerrit-01 @@ -72,3 +72,6 @@ networks: gerrit-net: driver: bridge + +volumes: + syslog-sidecar:
diff --git a/src/test/docker/gerrit/Dockerfile b/src/test/docker/gerrit/Dockerfile index 6e0bbca..fce65fb 100644 --- a/src/test/docker/gerrit/Dockerfile +++ b/src/test/docker/gerrit/Dockerfile
@@ -21,4 +21,6 @@ RUN rm -Rf /var/gerrit/{git,index,cache}/* +ARG GERRIT_UID=1000 +RUN usermod -u ${GERRIT_UID} gerrit &> /dev/null CMD /bin/start.sh
diff --git a/src/test/docker/gerrit/start.sh b/src/test/docker/gerrit/start.sh index 51bc9bc..454207d 100755 --- a/src/test/docker/gerrit/start.sh +++ b/src/test/docker/gerrit/start.sh
@@ -7,7 +7,7 @@ wait-for-it.sh $WAIT_FOR -t 600 -- echo "$WAIT_FOR is up" fi -sudo -u gerrit cp /var/gerrit/etc/gerrit.config.orig /var/gerrit/etc/gerrit.config +chown -R gerrit: /var/gerrit && sudo -u gerrit cp /var/gerrit/etc/gerrit.config.orig /var/gerrit/etc/gerrit.config if [[ ! -f /var/gerrit/git/All-Projects.git/config ]] then @@ -19,7 +19,7 @@ sudo -u gerrit java -jar /var/gerrit/bin/gerrit.war reindex -d /var/gerrit sudo -u gerrit git config -f /var/gerrit/etc/gerrit.config gerrit.canonicalWebUrl http://$HOSTNAME/ -touch /var/gerrit/logs/{gc_log,error_log,httpd_log,sshd_log,replication_log} && chown -R gerrit: /var/gerrit && tail -f /var/gerrit/logs/* | grep --line-buffered -v 'HEAD /' & +touch /var/gerrit/logs/{gc_log,error_log,httpd_log,sshd_log,replication_log} && tail -f /var/gerrit/logs/* | grep --line-buffered -v 'HEAD /' & echo "Running Gerrit ..." sudo -u gerrit /etc/init.d/gerrit run