From d31f56dd755c946af3b643a0a017f0d6c09fb0fe Mon Sep 17 00:00:00 2001 From: slittle1 Date: Tue, 24 Nov 2020 17:17:35 +0000 Subject: [PATCH] Update git and git-review in Dockerfile Opendev recently upgraded to a newer version of gerrit. That gerrit demands that we run a newer version of git than is available from Centos 7. This will prevent users from posting code for review from within this build container. This update compiles a newer version (2.29.2) of git from downloaded source code, and adds it to the build image. A newer version of git-review is downloaded from pypi, and added to the build image. A mechanism is provided to feed in a valid email address to the idocker image's ~/.gitconfig by defining MY_EMAIL=you@your-email-host in your 'localrc' prior to 'tb.sh create' Closes-bug: 1905789 Change-Id: I28ed185ea477ba3a8e47e1dd11fd384816f72717 Signed-off-by: slittle1 --- Dockerfile | 18 +++++++++++++++++- tb.sh | 12 +++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d6608ad6..8042541f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,7 @@ ARG MYUID=1000 # Override these with --build-arg if you have a mirror ARG CENTOS_7_8_URL=http://vault.centos.org/centos/7.8.2003 ARG EPEL_7_8_URL=https://archives.fedoraproject.org/pub/archive/epel/7.2020-04-20 +ARG MY_EMAIL= ENV container=docker @@ -230,6 +231,20 @@ RUN echo "$MYUNAME ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers && \ sed -i "s/dir-listing.activate/#dir-listing.activate/g" /etc/lighttpd/conf.d/dirlisting.conf && \ echo "dir-listing.activate = \"enable\"" >> /etc/lighttpd/conf.d/dirlisting.conf +# Uprev git, git-review, repo +RUN yum install -y dh-autoreconf curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel asciidoc xmlto docbook2X && \ + cd /tmp && \ + wget https://github.com/git/git/archive/v2.29.2.tar.gz -O git-2.29.2.tar.gz && \ + tar xzvf git-2.29.2.tar.gz && \ + cd git-2.29.2 && \ + make configure && \ + ./configure --prefix=/usr/local && \ + make all doc && \ + make install install-doc && \ + cd /tmp && \ + rm -rf git-2.29.2.tar.gz git-2.29.2 && \ + pip install git-review --upgrade + # Systemd Enablement RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ rm -f /lib/systemd/system/multi-user.target.wants/*;\ @@ -253,7 +268,8 @@ RUN echo "bash -C /usr/local/bin/finishSetup.sh" >> /home/$MYUNAME/.bashrc && \ # Genrate a git configuration file in order to save an extra step # for end users, this file is required by "repo" tool. RUN chown $MYUNAME /home/$MYUNAME && \ - runuser -u $MYUNAME -- git config --global user.email $MYUNAME@starlingx.com && \ + if [ -z $MY_EMAIL ]; then MY_EMAIL=$MYUNAME@opendev.org; fi && \ + runuser -u $MYUNAME -- git config --global user.email $MY_EMAIL && \ runuser -u $MYUNAME -- git config --global user.name $MYUNAME && \ runuser -u $MYUNAME -- git config --global color.ui false diff --git a/tb.sh b/tb.sh index 2d54beaf..82b10cc7 100755 --- a/tb.sh +++ b/tb.sh @@ -26,9 +26,16 @@ TC_CONTAINER_TAG=local/${MYUNAME}-stx-builder:7.8 TC_DOCKERFILE=Dockerfile function create_container { + local EXTRA_ARGS="" + + if [ ! -z ${MY_EMAIL} ]; then + EXTRA_ARGS="--build-arg MY_EMAIL=${MY_EMAIL}" + fi + docker build \ --build-arg MYUID=$(id -u) \ --build-arg MYUNAME=${USER} \ + ${EXTRA_ARGS} \ --ulimit core=0 \ --network host \ -t ${TC_CONTAINER_TAG} \ @@ -37,6 +44,7 @@ function create_container { } function exec_container { + echo "docker cp ${WORK_DIR}/buildrc ${TC_CONTAINER_NAME}:/home/${MYUNAME}" docker cp ${WORK_DIR}/buildrc ${TC_CONTAINER_NAME}:/home/${MYUNAME} docker cp ${WORK_DIR}/localrc ${TC_CONTAINER_NAME}:/home/${MYUNAME} docker exec -it --user=${MYUNAME} -e MYUNAME=${MYUNAME} ${TC_CONTAINER_NAME} script -q -c "/bin/bash" /dev/null @@ -52,7 +60,7 @@ function run_container { --name ${TC_CONTAINER_NAME} \ --detach \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v ${LOCALDISK}:/${GUEST_LOCALDISK} \ + -v $(readlink -f ${LOCALDISK}):/${GUEST_LOCALDISK} \ -v ${HOST_MIRROR_DIR}:/import/mirrors:ro \ -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ -v ~/.ssh:/mySSH:ro \ @@ -93,6 +101,8 @@ case $CMD in echo "MY_RELEASE=${MY_RELEASE}" echo "MY_REPO_ROOT_DIR=${MY_REPO_ROOT_DIR}" echo "LAYER=${LAYER}" + echo "MYUNAME=${MYUNAME}" + echo "MY_EMAIL=${MY_EMAIL}" ;; create) create_container