From 5a33f541ddb52e3f45db87db7c3dd40945b9a564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sat, 4 Apr 2020 08:08:48 +0700 Subject: ci: refactor docker runner script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We will support alpine check in docker later in this series. While we're at it, tell people to run as root in podman, if podman is used as drop-in replacement for docker, because podman will map host-user to container's root, therefore, mapping their permission. Signed-off-by: Đoàn Trần Công Danh Signed-off-by: Junio C Hamano diff --git a/.travis.yml b/.travis.yml index fc5730b..069aeef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ matrix: services: - docker before_install: - script: ci/run-linux32-docker.sh + script: ci/run-docker.sh - env: jobname=StaticAnalysis os: linux compiler: diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 675c3a4..11413f6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -489,14 +489,14 @@ jobs: test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || ci/mount-fileshare.sh //gitfileshare.file.core.windows.net/test-cache gitfileshare "$GITFILESHAREPWD" "$HOME/test-cache" || exit 1 res=0 - sudo AGENT_OS="$AGENT_OS" BUILD_BUILDNUMBER="$BUILD_BUILDNUMBER" BUILD_REPOSITORY_URI="$BUILD_REPOSITORY_URI" BUILD_SOURCEBRANCH="$BUILD_SOURCEBRANCH" BUILD_SOURCEVERSION="$BUILD_SOURCEVERSION" SYSTEM_PHASENAME="$SYSTEM_PHASENAME" SYSTEM_TASKDEFINITIONSURI="$SYSTEM_TASKDEFINITIONSURI" SYSTEM_TEAMPROJECT="$SYSTEM_TEAMPROJECT" CC=$CC MAKEFLAGS="$MAKEFLAGS" bash -lxc ci/run-linux32-docker.sh || res=1 + sudo AGENT_OS="$AGENT_OS" BUILD_BUILDNUMBER="$BUILD_BUILDNUMBER" BUILD_REPOSITORY_URI="$BUILD_REPOSITORY_URI" BUILD_SOURCEBRANCH="$BUILD_SOURCEBRANCH" BUILD_SOURCEVERSION="$BUILD_SOURCEVERSION" SYSTEM_PHASENAME="$SYSTEM_PHASENAME" SYSTEM_TASKDEFINITIONSURI="$SYSTEM_TASKDEFINITIONSURI" SYSTEM_TEAMPROJECT="$SYSTEM_TEAMPROJECT" CC=$CC MAKEFLAGS="$MAKEFLAGS" jobname=Linux32 bash -lxc ci/run-docker.sh || res=1 sudo chmod a+r t/out/TEST-*.xml test ! -d t/failed-test-artifacts || sudo chmod a+r t/failed-test-artifacts test "$GITFILESHAREPWD" = '$(gitfileshare.pwd)' || sudo umount "$HOME/test-cache" || res=1 exit $res - displayName: 'ci/run-linux32-docker.sh' + displayName: 'jobname=Linux32 ci/run-docker.sh' env: GITFILESHAREPWD: $(gitfileshare.pwd) - task: PublishTestResults@2 diff --git a/ci/run-docker-build.sh b/ci/run-docker-build.sh new file mode 100755 index 0000000..a05b48c --- /dev/null +++ b/ci/run-docker-build.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# +# Build and test Git inside container +# +# Usage: +# run-docker-build.sh +# + +set -ex + +if test $# -ne 1 || test -z "$1" +then + echo >&2 "usage: run-docker-build.sh " + exit 1 +fi + +case "$jobname" in +Linux32) + switch_cmd="linux32 --32bit i386" + ;; +*) + exit 1 + ;; +esac + +# Update packages to the latest available versions +command $switch_cmd sh -c ' + apt update >/dev/null && + apt install -y build-essential libcurl4-openssl-dev libssl-dev \ + libexpat-dev gettext python >/dev/null +' + +# If this script runs inside a docker container, then all commands are +# usually executed as root. Consequently, the host user might not be +# able to access the test output files. +# If a non 0 host user id is given, then create a user "ci" with that +# user id to make everything accessible to the host user. +HOST_UID=$1 +if test $HOST_UID -eq 0 +then + # Just in case someone does want to run the test suite as root. + CI_USER=root +else + CI_USER=ci + if test "$(id -u $CI_USER 2>/dev/null)" = $HOST_UID + then + echo "user '$CI_USER' already exists with the requested ID $HOST_UID" + else + useradd -u $HOST_UID $CI_USER + fi + + # Due to a bug the test suite was run as root in the past, so + # a prove state file created back then is only accessible by + # root. Now that bug is fixed, the test suite is run as a + # regular user, but the prove state file coming from Travis + # CI's cache might still be owned by root. + # Make sure that this user has rights to any cached files, + # including an existing prove state file. + test -n "$cache_dir" && chown -R $HOST_UID:$HOST_UID "$cache_dir" +fi + +# Build and test +command $switch_cmd su -m -l $CI_USER -c " + set -ex + export DEVELOPER='$DEVELOPER' + export DEFAULT_TEST_TARGET='$DEFAULT_TEST_TARGET' + export GIT_PROVE_OPTS='$GIT_PROVE_OPTS' + export GIT_TEST_OPTS='$GIT_TEST_OPTS' + export GIT_TEST_CLONE_2GB='$GIT_TEST_CLONE_2GB' + export MAKEFLAGS='$MAKEFLAGS' + export cache_dir='$cache_dir' + cd /usr/src/git + test -n '$cache_dir' && ln -s '$cache_dir/.prove' t/.prove + make + make test +" diff --git a/ci/run-docker.sh b/ci/run-docker.sh new file mode 100755 index 0000000..3881f99 --- /dev/null +++ b/ci/run-docker.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# +# Download and run Docker image to build and test Git +# + +. ${0%/*}/lib.sh + +case "$jobname" in +Linux32) + CI_CONTAINER="daald/ubuntu32:xenial" + ;; +*) + exit 1 + ;; +esac + +docker pull "$CI_CONTAINER" + +# Use the following command to debug the docker build locally: +# must be 0 if podman is used as drop-in replacement for docker +# $ docker run -itv "${PWD}:/usr/src/git" --entrypoint /bin/sh "$CI_CONTAINER" +# root@container:/# export jobname= +# root@container:/# /usr/src/git/ci/run-docker-build.sh + +container_cache_dir=/tmp/travis-cache + +docker run \ + --interactive \ + --env DEVELOPER \ + --env DEFAULT_TEST_TARGET \ + --env GIT_PROVE_OPTS \ + --env GIT_TEST_OPTS \ + --env GIT_TEST_CLONE_2GB \ + --env MAKEFLAGS \ + --env jobname \ + --env cache_dir="$container_cache_dir" \ + --volume "${PWD}:/usr/src/git" \ + --volume "$cache_dir:$container_cache_dir" \ + "$CI_CONTAINER" \ + /usr/src/git/ci/run-docker-build.sh $(id -u $USER) + +check_unignored_build_artifacts + +save_good_tree diff --git a/ci/run-linux32-build.sh b/ci/run-linux32-build.sh deleted file mode 100755 index 44bb332..0000000 --- a/ci/run-linux32-build.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -# -# Build and test Git in a 32-bit environment -# -# Usage: -# run-linux32-build.sh -# - -set -ex - -if test $# -ne 1 || test -z "$1" -then - echo >&2 "usage: run-linux32-build.sh " - exit 1 -fi - -case "$jobname" in -Linux32) - switch_cmd="linux32 --32bit i386" - ;; -*) - exit 1 - ;; -esac - -# Update packages to the latest available versions -command $switch_cmd sh -c ' - apt update >/dev/null && - apt install -y build-essential libcurl4-openssl-dev libssl-dev \ - libexpat-dev gettext python >/dev/null -' - -# If this script runs inside a docker container, then all commands are -# usually executed as root. Consequently, the host user might not be -# able to access the test output files. -# If a non 0 host user id is given, then create a user "ci" with that -# user id to make everything accessible to the host user. -HOST_UID=$1 -if test $HOST_UID -eq 0 -then - # Just in case someone does want to run the test suite as root. - CI_USER=root -else - CI_USER=ci - if test "$(id -u $CI_USER 2>/dev/null)" = $HOST_UID - then - echo "user '$CI_USER' already exists with the requested ID $HOST_UID" - else - useradd -u $HOST_UID $CI_USER - fi - - # Due to a bug the test suite was run as root in the past, so - # a prove state file created back then is only accessible by - # root. Now that bug is fixed, the test suite is run as a - # regular user, but the prove state file coming from Travis - # CI's cache might still be owned by root. - # Make sure that this user has rights to any cached files, - # including an existing prove state file. - test -n "$cache_dir" && chown -R $HOST_UID:$HOST_UID "$cache_dir" -fi - -# Build and test -command $switch_cmd su -m -l $CI_USER -c " - set -ex - export DEVELOPER='$DEVELOPER' - export DEFAULT_TEST_TARGET='$DEFAULT_TEST_TARGET' - export GIT_PROVE_OPTS='$GIT_PROVE_OPTS' - export GIT_TEST_OPTS='$GIT_TEST_OPTS' - export GIT_TEST_CLONE_2GB='$GIT_TEST_CLONE_2GB' - export MAKEFLAGS='$MAKEFLAGS' - export cache_dir='$cache_dir' - cd /usr/src/git - test -n '$cache_dir' && ln -s '$cache_dir/.prove' t/.prove - make - make test -" diff --git a/ci/run-linux32-docker.sh b/ci/run-linux32-docker.sh deleted file mode 100755 index 54186b6..0000000 --- a/ci/run-linux32-docker.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# -# Download and run Docker image to build and test 32-bit Git -# - -. ${0%/*}/lib.sh - -docker pull daald/ubuntu32:xenial - -# Use the following command to debug the docker build locally: -# $ docker run -itv "${PWD}:/usr/src/git" --entrypoint /bin/bash daald/ubuntu32:xenial -# root@container:/# export jobname= -# root@container:/# /usr/src/git/ci/run-linux32-build.sh - -container_cache_dir=/tmp/travis-cache - -docker run \ - --interactive \ - --env DEVELOPER \ - --env DEFAULT_TEST_TARGET \ - --env GIT_PROVE_OPTS \ - --env GIT_TEST_OPTS \ - --env GIT_TEST_CLONE_2GB \ - --env MAKEFLAGS \ - --env jobname \ - --env cache_dir="$container_cache_dir" \ - --volume "${PWD}:/usr/src/git" \ - --volume "$cache_dir:$container_cache_dir" \ - daald/ubuntu32:xenial \ - /usr/src/git/ci/run-linux32-build.sh $(id -u $USER) - -check_unignored_build_artifacts - -save_good_tree -- cgit v0.10.2-6-g49f6