Skip to content

Commit 2c753aa

Browse files
SiyaoIsHidingmichaelsembwever
authored andcommitted
CI docker uses correct uid/gip with use of create-user.sh script
patch by Siyao He; reviewed by Mick Semb Wever for CASSANDRA-18971
1 parent 692a922 commit 2c753aa

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

Jenkinsfile-asf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ pipeline {
6262
}
6363

6464
def executeTests() {
65-
sh "docker run -e TEST_JAVA_VERSION=${TEST_JAVA_VERSION} -e SERVER_VERSION=${SERVER_VERSION} -v \$(pwd):/home/docker/cassandra-java-driver apache.jfrog.io/cassan-docker/apache/cassandra-java-driver-testing-ubuntu2204 cassandra-java-driver/ci/run-tests.sh"
65+
sh """
66+
container_id=\$(docker run -td -e TEST_JAVA_VERSION=${TEST_JAVA_VERSION} -e SERVER_VERSION=${SERVER_VERSION} -v \$(pwd):/home/docker/cassandra-java-driver apache.jfrog.io/cassan-docker/apache/cassandra-java-driver-testing-ubuntu2204 'sleep 2h')
67+
docker exec --user root \$container_id bash -c \"sudo bash /home/docker/cassandra-java-driver/ci/create-user.sh docker \$(id -u) \$(id -g) /home/docker/cassandra-java-driver\"
68+
docker exec --user docker \$container_id './cassandra-java-driver/ci/run-tests.sh'
69+
( nohup docker stop \$container_id >/dev/null 2>/dev/null & )
70+
"""
6671
}
6772

6873
// branch pattern for cron

ci/create-user.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
################################
19+
#
20+
# Prep
21+
#
22+
################################
23+
24+
if [ "$1" == "-h" ]; then
25+
echo "$0 [-h] <username> <uid> <gid>"
26+
echo " this script is used internally by other scripts in the same directory to create a user with the running host user's same uid and gid"
27+
exit 1
28+
fi
29+
30+
# arguments
31+
username=$1
32+
uid=$2
33+
gid=$3
34+
BUILD_HOME=$4
35+
36+
################################
37+
#
38+
# Main
39+
#
40+
################################
41+
42+
# disable git directory ownership checks
43+
su ${username} -c "git config --global safe.directory '*'"
44+
45+
if grep "^ID=" /etc/os-release | grep -q 'debian\|ubuntu' ; then
46+
deluser docker
47+
adduser --quiet --disabled-login --no-create-home --uid $uid --gecos ${username} ${username}
48+
groupmod --non-unique -g $gid $username
49+
gpasswd -a ${username} sudo >/dev/null
50+
else
51+
adduser --no-create-home --uid $uid ${username}
52+
fi
53+
54+
# sudo priviledges
55+
echo "${username} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${username}
56+
chmod 0440 /etc/sudoers.d/${username}
57+
58+
# proper permissions
59+
chown -R ${username}:${username} /home/docker
60+
chmod og+wx ${BUILD_HOME}

0 commit comments

Comments
 (0)