Skip to content

Commit 80f7f2f

Browse files
committed
run dev-env with root inside container
Change-Id: Ib474b10d42081fa9a3b3975cc427749541f68f56
1 parent f8bb549 commit 80f7f2f

13 files changed

+42
-72
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,16 @@ sudo docker exec -it tf-dev-sandbox bash
131131
``` bash
132132
cd ~/tf-dev-env
133133
make sync # get latest code
134-
sudo make setup dep # set up docker container and install build dependencies
134+
make setup dep # set up docker container and install build dependencies
135135
make fetch_packages # pull third_party dependencies
136136
```
137137

138138
The descriptions of targets:
139139

140140
- `make sync` - sync code in `./contrail` directory using `repo` tool
141141
- `make fetch_packages` - pull `./third_party` dependencies (after code checkout)
142-
- `sudo make setup` - initial configuration of image (required to run once)
143-
- `sudo make dep` - installs all build dependencies
142+
- `make setup` - initial configuration of image (required to run once)
143+
- `make dep` - installs all build dependencies
144144
- `make dep-<pkg_name>` - installs build dependencies for <pkg_name>
145145

146146
### 4. Building artifacts

Vagrantfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
VAGRANTFILE_API_VERSION = "2"
55
USER = "root"
66
GROUP = "root"
7-
DEVENV_USER="root"
8-
HOME_DIR = "/#{DEVENV_USER}"
7+
HOME_DIR = "/root"
98
DEV_ENV_DIR = "#{HOME_DIR}/tf-dev-env"
109
REPOS_DIR = "#{HOME_DIR}/src/review.opencontrail.org/Juniper/"
1110

common/common.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set -o errexit
88
export DEBUGINFO=${DEBUGINFO:-FALSE}
99

1010
# working environment
11+
# WORKSPACE and two next vars are appcable only outside of sandbox container - on host.
1112
export WORKSPACE=${WORKSPACE:-$(pwd)}
1213
export TF_CONFIG_DIR=${TF_CONFIG_DIR:-"${HOME}/.tf"}
1314
export TF_DEVENV_PROFILE="${TF_CONFIG_DIR}/dev.env"
@@ -25,16 +26,16 @@ else
2526
fi
2627

2728
# working build directories
29+
# CONTRAIL_DIR is useful only outside of sandbox container
2830
if [ -z "${CONTRAIL_DIR+x}" ] ; then
2931
# not defined => use default
30-
CONTRAIL_DIR=${WORKSPACE}/contrail
32+
CONTRAIL_DIR=${WORKSPACE}/contrail
3133
elif [ -z "$CONTRAIL_DIR" ] ; then
3234
# defined empty => dont bind contrail dir to host: tf jenkins
33-
CONTRAIL_DIR=${WORKSPACE}/contrail
35+
CONTRAIL_DIR=${WORKSPACE}/contrail
3436
BIND_CONTRAIL_DIR=false
3537
fi
3638
export CONTRAIL_DIR
37-
export DEVENV_USER=${DEVENV_USER:-$(id -nu)}
3839

3940
# build environment preparation options
4041
export CONTAINER_REGISTRY=${CONTAINER_REGISTRY:-"localhost:5000"}

common/tf_functions.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export DEBUG=${DEBUG}
1616
export DEBUGINFO=${DEBUGINFO}
1717
export LINUX_DISTR=${LINUX_DISTR}
1818
export LINUX_DISTR_VER=${LINUX_DISTR_VER}
19-
export DEV_ENV_ROOT=/${DEVENV_USER}/tf-dev-env
19+
export DEV_ENV_ROOT=/root/tf-dev-env
2020
export DEVENV_TAG=$DEVENV_TAG
2121
export CONTRAIL_BUILD_FROM_SOURCE=${CONTRAIL_BUILD_FROM_SOURCE}
2222
export OPENSTACK_VERSIONS=${OPENSTACK_VERSIONS}
@@ -62,13 +62,14 @@ EOF
6262
function prepare_infra()
6363
{
6464
echo "INFO: create symlinks to work directories with artifacts $(date)"
65-
mkdir -p $HOME/work
65+
mkdir -p $HOME/work /root/contrail
66+
# /root/contrail will be defined later as REPODIR
6667
for folder in ${work_folders[@]} ; do
6768
[[ -e $WORK_DIR/$folder ]] || mkdir $WORK_DIR/$folder
68-
[[ -e $CONTRAIL_DIR/$folder ]] || ln -s $WORK_DIR/$folder $CONTRAIL_DIR/$folder
69+
[[ -e /root/contrail/$folder ]] || ln -s $WORK_DIR/$folder /root/contrail/$folder
6970
done
7071
for file in ${work_files[@]} ; do
7172
touch $WORK_DIR/$file
72-
[[ -e $CONTRAIL_DIR/$file ]] || ln -s $WORK_DIR/$file $CONTRAIL_DIR/$file
73+
[[ -e /root/contrail/$file ]] || ln -s $WORK_DIR/$file /root/contrail/$file
7374
done
7475
}

container/Dockerfile.centos

+3-17
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ ARG LC_ALL=en_US.UTF-8
44
ARG LANG=en_US.UTF-8
55
ARG LANGUAGE=en_US.UTF-8
66

7-
ARG DEVENV_USER=root
8-
ARG DEVENV_UID=0
9-
ARG DEVENV_GROUP=""
10-
ARG DEVENV_GID=""
11-
12-
ENV USER $DEVENV_USER
13-
ENV HOME /$DEVENV_USER
7+
ENV USER root
8+
ENV HOME /root
149
ENV CONTRAIL $HOME/contrail
1510
ENV LC_ALL=$LC_ALL
1611
ENV LANG=$LANG
@@ -36,19 +31,10 @@ RUN if ! yum info jq ; then yum -y install epel-release ; fi && \
3631
yum clean all && \
3732
rm -rf /var/cache/yum && \
3833
pip3 install --retries=10 --timeout 200 --upgrade tox setuptools lxml jinja2 && \
39-
rm -f /usr/local/bin/virtualenv && \
40-
if [[ "$DEVENV_USER" != 'root' ]] ; then \
41-
groupadd --gid $DEVENV_GID $DEVENV_GROUP && \
42-
useradd -md $HOME --uid $DEVENV_UID --gid $DEVENV_GID $DEVENV_USER && \
43-
echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \
44-
usermod -aG wheel $DEVENV_USER && \
45-
chown -R $DEVENV_UID:$DEVENV_GID $HOME || exit 1; \
46-
fi
34+
rm -f /usr/local/bin/virtualenv
4735

4836
ADD entrypoint.sh /
4937

50-
USER $DEVENV_USER
51-
5238
RUN echo export CONTRAIL=$CONTRAIL >> $HOME/.bashrc && \
5339
echo export LD_LIBRARY_PATH=$CONTRAIL/build/lib >> $HOME/.bashrc
5440

container/Dockerfile.rhel7

+3-16
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ ARG LANG=en_US.UTF-8
55
ARG LANGUAGE=en_US.UTF-8
66

77
ARG ENABLE_RHSM_REPOS=false
8-
ARG DEVENV_USER=root
9-
ARG DEVENV_UID=0
10-
ARG DEVENV_GROUP=""
11-
ARG DEVENV_GID=""
128

13-
ENV USER $DEVENV_USER
14-
ENV HOME /$DEVENV_USER
9+
ENV USER root
10+
ENV HOME /root
1511
ENV CONTRAIL $HOME/contrail
1612
ENV LC_ALL=$LC_ALL
1713
ENV LANG=$LANG
@@ -43,19 +39,10 @@ RUN if [[ "$ENABLE_RHSM_REPOS" == 'true' ]] ; then \
4339
yum clean all && \
4440
rm -rf /var/cache/yum && \
4541
pip3 install --retries=10 --timeout 200 --upgrade tox setuptools lxml jinja2 && \
46-
rm -f /usr/local/bin/virtualenv && \
47-
if [[ "$DEVENV_USER" != 'root' ]] ; then \
48-
groupadd --gid $DEVENV_GID $DEVENV_GROUP && \
49-
useradd -md $HOME --uid $DEVENV_UID --gid $DEVENV_GID $DEVENV_USER && \
50-
echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \
51-
usermod -aG wheel $DEVENV_USER && \
52-
chown -R $DEVENV_UID:$DEVENV_GID $HOME || exit 1; \
53-
fi
42+
rm -f /usr/local/bin/virtualenv
5443

5544
ADD entrypoint.sh /
5645

57-
USER $DEVENV_USER
58-
5946
RUN echo export CONTRAIL=$CONTRAIL >> $HOME/.bashrc && \
6047
echo export LD_LIBRARY_PATH=$CONTRAIL/build/lib >> $HOME/.bashrc
6148

container/build.sh

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ echo "Building tf-dev-env image: ${DEVENV_IMAGE}" | tee $logfile
2222

2323
build_opts="--build-arg LC_ALL=en_US.UTF-8 --build-arg LANG=en_US.UTF-8 --build-arg LANGUAGE=en_US.UTF-8"
2424
build_opts+=" --network host --no-cache --tag ${DEVENV_IMAGE} --tag ${CONTAINER_REGISTRY}/${DEVENV_IMAGE} -f Dockerfile.${LINUX_DISTR} ."
25-
if [[ -n "$DEVENV_USER" && "$DEVENV_USER" != 'root' ]] ; then
26-
build_opts+=" --build-arg DEVENV_USER=$DEVENV_USER --build-arg DEVENV_UID=$(id -u)"
27-
build_opts+=" --build-arg DEVENV_GROUP=$(id -ng) --build-arg DEVENV_GID=$(id -g)"
28-
fi
2925

3026
if [[ "$ENABLE_RHSM_REPOS" == 'true' ]] ; then
3127
build_opts+=" --build-arg ENABLE_RHSM_REPOS=$ENABLE_RHSM_REPOS"

container/run.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ function fetch() {
3131

3232
function configure() {
3333
echo "INFO: make setup $(date)"
34-
sudo make setup
34+
make setup
3535

3636
echo "INFO: make dep fetch_packages $(date)"
3737
# targets can use yum and will block each other. don't run them in parallel
38-
sudo make dep
38+
make dep
3939
make fetch_packages
4040

4141
# disable byte compiling
4242
if [[ ! -f /usr/lib/rpm/brp-python-bytecompile.org ]] ; then
4343
echo "INFO: disable byte compiling for python"
44-
sudo mv /usr/lib/rpm/brp-python-bytecompile /usr/lib/rpm/brp-python-bytecompile.org
45-
cat <<EOF | sudo tee /usr/lib/rpm/brp-python-bytecompile
44+
mv /usr/lib/rpm/brp-python-bytecompile /usr/lib/rpm/brp-python-bytecompile.org
45+
cat <<EOF | tee /usr/lib/rpm/brp-python-bytecompile
4646
#!/bin/bash
4747
# disabled byte compiling
4848
exit 0
4949
EOF
50-
sudo chmod +x /usr/lib/rpm/brp-python-bytecompile
50+
chmod +x /usr/lib/rpm/brp-python-bytecompile
5151
fi
5252
}
5353

run.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ SITE_MIRROR=${SITE_MIRROR:-}
2626
if [[ "$stage" == 'upload' ]]; then
2727
# Pushes devenv (or potentially other containers) to external registry
2828
echo "INFO: pushing devenv to container registry"
29-
sudo docker stop ${DEVENV_CONTAINER_NAME}
30-
sudo docker commit ${DEVENV_CONTAINER_NAME} ${CONTAINER_REGISTRY}/${DEVENV_IMAGE_NAME}:${DEVENV_PUSH_TAG}
31-
sudo docker push ${CONTAINER_REGISTRY}/${DEVENV_IMAGE_NAME}:${DEVENV_PUSH_TAG}
29+
mysudo docker stop ${DEVENV_CONTAINER_NAME}
30+
mysudo docker commit ${DEVENV_CONTAINER_NAME} ${CONTAINER_REGISTRY}/${DEVENV_IMAGE_NAME}:${DEVENV_PUSH_TAG}
31+
mysudo docker push ${CONTAINER_REGISTRY}/${DEVENV_IMAGE_NAME}:${DEVENV_PUSH_TAG}
3232
exit 0
3333
fi
3434

@@ -89,13 +89,13 @@ if ! is_container_created "$DEVENV_CONTAINER_NAME"; then
8989
if [[ $DISTRO != "macosx" ]]; then
9090
volumes+=" -v /etc/localtime:/etc/localtime"
9191
fi
92-
volumes+=" -v ${scriptdir}:/$DEVENV_USER/tf-dev-env:${DOCKER_VOLUME_OPTIONS}"
92+
volumes+=" -v ${scriptdir}:/root/tf-dev-env:${DOCKER_VOLUME_OPTIONS}"
9393
if [[ "$BIND_CONTRAIL_DIR" != 'false' ]] ; then
9494
# make dir to create them under current user
9595
mkdir -p ${CONTRAIL_DIR}
96-
volumes+=" -v ${CONTRAIL_DIR}:/$DEVENV_USER/contrail:${DOCKER_VOLUME_OPTIONS}"
96+
volumes+=" -v ${CONTRAIL_DIR}:/root/contrail:${DOCKER_VOLUME_OPTIONS}"
9797
elif [[ -n "$CONTRAIL_BUILD_FROM_SOURCE" && -n "${src_volume_name}" ]] ; then
98-
volumes+=" -v ${src_volume_name}:/$DEVENV_USER/contrail:${DOCKER_VOLUME_OPTIONS}"
98+
volumes+=" -v ${src_volume_name}:/root/contrail:${DOCKER_VOLUME_OPTIONS}"
9999
fi
100100
# make dir to create them under current user
101101
mkdir -p ${WORKSPACE}/output
@@ -108,7 +108,7 @@ if ! is_container_created "$DEVENV_CONTAINER_NAME"; then
108108
# - TF Jenkins CI use non-bind folder for sources
109109
start_sandbox_cmd="mysudo docker run --network host --privileged --detach \
110110
--name $DEVENV_CONTAINER_NAME \
111-
-w /$DEVENV_USER ${options} \
111+
-w /root ${options} \
112112
$volumes -it \
113113
${CONTAINER_REGISTRY}/${DEVENV_IMAGE}"
114114

@@ -135,7 +135,7 @@ if [[ "$stage" == 'none' ]] ; then
135135
fi
136136

137137
echo "run stage $stage with target $target"
138-
mysudo docker exec -i $DEVENV_CONTAINER_NAME /$DEVENV_USER/tf-dev-env/container/run.sh $stage $target | tee -a ${log_path}
138+
mysudo docker exec -i $DEVENV_CONTAINER_NAME /root/tf-dev-env/container/run.sh $stage $target | tee -a ${log_path}
139139
result=${PIPESTATUS[0]}
140140

141141
if [[ $result == 0 ]] ; then

scripts/build-tpp.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ pushd ${tpp_dir}/upstream/rpm
3535
echo "INFO: tpp: make list"
3636
make list
3737
echo "INFO: tpp: make prep"
38-
sudo make prep
38+
make prep
3939
echo "INFO: tpp: make all"
40-
sudo make all
40+
make all
4141
popd
4242

4343
if [[ ! -e /etc/yum.repos.d/contrail.repo ]] ; then
4444
echo "INFO: enable contrail repo for next compilation steps"
4545
# enable contrail repo for dev-env if not created
4646
# (it is for tpp to be available during compile stage)
47-
cat <<EOF | sudo tee /etc/yum.repos.d/contrail.repo
47+
cat <<EOF | tee /etc/yum.repos.d/contrail.repo
4848
[contrail]
4949
name = Contrail repo
5050
baseurl = ${CONTRAIL_REPOSITORY}

scripts/controller_ut/run-tests.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def _parse_junit_xml(self, xml_path):
119119
soup = etree.fromstring(xml_doc)
120120

121121
status = TestResult.SUCCESS
122-
test_suites = []
123122
suite_objs = []
124123

125124
# check if the root tag is testsuite, and if not, find
@@ -237,7 +236,7 @@ def generate_test_report(self, scons_rc, final_result):
237236
238237
SCons targets executed:
239238
{% for target in scons_targets %}
240-
{{ target }}
239+
{{ target }}
241240
{% endfor %}
242241
SCons Result: {{ scons_rc }}
243242
Analyzer Result: {{ final_result }}
@@ -292,6 +291,7 @@ def generate_test_report(self, scons_rc, final_result):
292291
print(e)
293292
print(text)
294293

294+
295295
def main():
296296
runner = TungstenTestRunner()
297297
runner.parse_arguments()
@@ -320,8 +320,8 @@ def main():
320320
if result == TestResult.SUCCESS:
321321
break
322322

323-
logging.warning("Test Failure, {} targets failed:\n".format(len(failed_targets))
324-
+ "\n\t".join(failed_targets))
323+
logging.warning("Test Failure, {} targets failed:\n".format(len(failed_targets)) +
324+
"\n\t".join(failed_targets))
325325
logging.info("Retrying, %d attempts remaining.", counter)
326326

327327
runner.generate_test_report(rc, "SUCCESS" if result == TestResult.SUCCESS else "FAILURE")

scripts/controller_ut/run-tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ mkdir -p "$logs_path"
1313
# contrail code assumes this in tests, since it uses socket.fqdn(..) but expects the result
1414
# to be 'localhost' when for CentOS it would return 'localhost.localdomain'
1515
# see e.g.: https://github.com/Juniper/contrail-analytics/blob/b488e3cd608643ae5dd1e0dcbc03c9e8768178ce/contrail-opserver/alarmgen.py#L872
16-
sudo bash -c 'echo "127.0.0.1 localhost" > /etc/hosts'
17-
sudo bash -c 'echo "::1 localhost" >> /etc/hosts'
16+
bash -c 'echo "127.0.0.1 localhost" > /etc/hosts'
17+
bash -c 'echo "::1 localhost" >> /etc/hosts'
1818

1919
unset BUILD_ONLY
2020

scripts/run-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export JOBS=${JOBS:-$(nproc)}
1010
scriptdir=$(realpath $(dirname "$0"))
1111

1212
if [[ -n "$CONTRAIL_CONFIG_DIR" && -d "$CONTRAIL_CONFIG_DIR" ]]; then
13-
sudo cp -rf ${CONTRAIL_CONFIG_DIR}/* /
13+
cp -rf ${CONTRAIL_CONFIG_DIR}/* /
1414
fi
1515

1616
if [[ "$TARGET" == 'ui' ]]; then

0 commit comments

Comments
 (0)