Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit e5f03c0

Browse files
committed
Merge branch 'pr-fix-failures-on-non-root' into prp-fix-failures-on-non-root
2 parents 2ebd3e7 + 654bc27 commit e5f03c0

File tree

14 files changed

+157
-82
lines changed

14 files changed

+157
-82
lines changed

dockerfiles/remote-plugin-dotnet-2.2.105/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
5454

5555
# Install typescript@2.9.2 and node-gyp
5656

57-
&& yarn global add typescript@2.9.2 node-gyp
57+
&& yarn global add typescript@2.9.2 node-gyp \
58+
&& node-gyp install
5859

5960
ENV HOME=/home/theia
6061
COPY --from=endpoint /home/theia /home/theia

dockerfiles/theia-dev/Dockerfile

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
#
1414
FROM node:10.15-alpine
1515

16+
# Add npm global bin directory to the path
17+
ENV HOME=/home/theia-dev \
18+
PATH=/home/theia-dev/.npm-global/bin:${PATH} \
19+
# Specify the directory of git (avoid to search at init of Theia)
20+
USE_LOCAL_GIT=true \
21+
LOCAL_GIT_DIRECTORY=/usr \
22+
GIT_EXEC_PATH=/usr/libexec/git-core \
23+
THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=true
24+
1625
RUN apk add --update --no-cache \
1726
# Download some files
1827
curl \
@@ -26,17 +35,15 @@ RUN apk add --update --no-cache \
2635
less \
2736
# bash shell
2837
bash \
38+
# give root privilege
39+
sudo \
40+
# for useradd command
41+
shadow \
2942
# some lib to compile 'native-keymap' npm mpdule
30-
libx11-dev libxkbfile-dev
31-
32-
# Add npm global bin directory to the path
33-
ENV HOME=/home/theia-dev \
34-
PATH=/home/theia-dev/.npm-global/bin:${PATH} \
35-
# Specify the directory of git (avoid to search at init of Theia)
36-
USE_LOCAL_GIT=true \
37-
LOCAL_GIT_DIRECTORY=/usr \
38-
GIT_EXEC_PATH=/usr/libexec/git-core \
39-
THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=true
43+
libx11-dev libxkbfile-dev && \
44+
useradd -u 1001 -U -G root -d ${HOME} -s /bin/bash theia-dev && \
45+
apk del --no-cache shadow && \
46+
echo "%root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
4047

4148
# Define package of the theia generator to use
4249
ARG THEIA_GENERATOR_PACKAGE=@eclipse-che/theia-generator@0.0.1-1559634039
@@ -49,25 +56,25 @@ EXPOSE 3000 3030
4956
# Configure npm and yarn to use home folder for global dependencies
5057
RUN npm config set prefix "${HOME}/.npm-global" && \
5158
echo "--global-folder \"${HOME}/.yarn-global\"" > ${HOME}/.yarnrc && \
59+
# Setup node-gyp. Yarn will be failed unless installing required files here.
60+
yarn global add node-gyp && node-gyp install && \
5261
# add eclipse che theia generator
5362
yarn global add yo @theia/generator-plugin@0.0.1-1540209403 ${THEIA_GENERATOR_PACKAGE} && \
5463
# Generate .passwd.template \
55-
cat /etc/passwd | \
56-
sed s#root:x.*#theia-dev:x:\${USER_ID}:\${GROUP_ID}::${HOME}:/bin/bash#g \
57-
> ${HOME}/.passwd.template && \
58-
# Generate .group.template \
59-
cat /etc/group | \
60-
sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g \
61-
> ${HOME}/.group.template && \
64+
sed -e "s#^theia-dev:x.*#theia-dev:x:\${USER_ID}:\${GROUP_ID}::${HOME}:/bin/bash#g" \
65+
/etc/passwd > ${HOME}/.passwd.template && \
66+
sed -e 's#^theia-dev:.*#theia-dev:x:${GROUP_ID}:#g' \
67+
/etc/group > ${HOME}/.group.template && \
6268
mkdir /projects && \
6369
# Define default prompt
6470
echo "export PS1='\[\033[01;33m\](\u@container)\[\033[01;36m\] (\w) \$ \[\033[00m\]'" > ${HOME}/.bashrc && \
6571
# Disable the statistics for yeoman
6672
mkdir -p ${HOME}/.config/insight-nodejs/ && \
6773
echo '{"optOut": true}' > ${HOME}/.config/insight-nodejs/insight-yo.json && \
6874
# Change permissions to let any arbitrary user
69-
for f in "${HOME}" "/etc/passwd" "/etc/group" "/projects"; do \
70-
echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && \
75+
for f in "${HOME}" /projects /etc/passwd /etc/group; do \
76+
echo "Changing permissions on ${f}" && \
77+
chgrp -R 0 ${f} && \
7178
chmod -R g+rwX ${f}; \
7279
done
7380

dockerfiles/theia-dev/e2e/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ FROM ${BUILD_ORGANIZATION}/${BUILD_PREFIX}-theia-dev:${BUILD_TAG}
1111
# define in env variable GITHUB_TOKEN
1212
ARG GITHUB_TOKEN
1313

14-
# Just try to build the latest theia with current image
15-
RUN git clone -b 'master' --single-branch --depth 1 https://github.com/theia-ide/theia theia
16-
RUN cd theia && yarn
14+
ADD src/test-entrypoint.sh /test-entrypoint.sh
15+
16+
CMD ["/test-entrypoint.sh"]
1717

dockerfiles/theia-dev/e2e/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ base_dir=$(cd "$(dirname "$0")"; pwd)
1111

1212
init --name:theia-builder-e2e "$@"
1313
build
14+
if ! skip_tests; then
15+
bash "${base_dir}"/test.sh "$@"
16+
fi
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
. /entrypoint.sh
4+
5+
cd /projects
6+
7+
# Just try to build the latest theia with current image
8+
git clone -b 'master' --single-branch --depth 1 https://github.com/theia-ide/theia theia
9+
cd theia && yarn

dockerfiles/theia-dev/e2e/test.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
# Copyright (c) 2018 Red Hat, Inc.
3+
# This program and the accompanying materials are made
4+
# available under the terms of the Eclipse Public License 2.0
5+
# which is available at https://www.eclipse.org/legal/epl-2.0/
6+
#
7+
# SPDX-License-Identifier: EPL-2.0
8+
9+
base_dir=$(cd "$(dirname "$0")"; pwd)
10+
. "${base_dir}/../../build.include"
11+
12+
init --name:theia-builder-e2e "$@"
13+
14+
DOCKER_RUN_OPTIONS=""
15+
# run bats with terminal mode (pretty print) if supported by current shell
16+
if [ -t 1 ]; then
17+
DOCKER_RUN_OPTIONS="-t"
18+
fi
19+
20+
# Runs E2E tests in a docker container.
21+
run_test_in_docker_container() {
22+
docker_exec run --rm ${DOCKER_RUN_OPTIONS} \
23+
--user $1 --group-add 0 \
24+
$IMAGE_NAME
25+
}
26+
27+
run_test_in_docker_container 0:0
28+
run_test_in_docker_container 1234:5678

dockerfiles/theia-dev/src/entrypoint.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,24 @@ if ! grep -Fq "${USER_ID}" /etc/passwd; then
1717
# current user is an arbitrary
1818
# user (its uid is not in the
1919
# container /etc/passwd). Let's fix that
20-
cat ${HOME}/.passwd.template | \
21-
sed "s/\${USER_ID}/${USER_ID}/g" | \
22-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" > /etc/passwd
20+
sed \
21+
-e "s/\${USER_ID}/${USER_ID}/g" \
22+
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
23+
-e "s/\${HOME}/\/home\/theia/g" \
24+
${HOME}/.passwd.template > /etc/passwd
25+
sed \
26+
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
27+
${HOME}/.group.template > /etc/group
2328

24-
cat ${HOME}/.group.template | \
25-
sed "s/\${USER_ID}/${USER_ID}/g" | \
26-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" > /etc/group
29+
# now the user `theia-dev` (that have uid:gid == $USER_ID,$GROUPID) can use `sudo`.
30+
fi
31+
32+
# Grant access to projects volume in case of non root user with sudo rights
33+
if [ "$USER_ID" -ne 0 ] && command -v sudo >/dev/null 2>&1 && sudo -n true > /dev/null 2>&1; then
34+
sudo chmod 644 /etc/passwd /etc/group
35+
sudo chown root:root /etc/passwd /etc/group
36+
37+
sudo chown ${USER_ID}:${GROUP_ID} /projects ${HOME}
2738
fi
2839

2940
exec "$@"

dockerfiles/theia-endpoint-runtime/Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ COPY --from=builder /home/workspace/node_modules /home/theia/node_modules
5656
RUN rm -rf /home/theia/node_modules/@eclipse-che/theia-plugin-ext /home/theia/node_modules/@eclipse-che/theia-remote
5757
COPY --from=builder /home/workspace/packages/theia-plugin-ext /home/theia/node_modules/@eclipse-che/theia-plugin-ext
5858
COPY --from=builder /home/workspace/packages/theia-remote/lib /home/theia/lib
59+
COPY --from=builder /.passwd.template /.passwd.template
60+
COPY --from=builder /.group.template /.group.template
61+
COPY --from=builder /etc/sudoers /etc/sudoers
62+
5963
RUN mkdir /projects \
6064
# Store passwd/group as template files
61-
&& cat /etc/passwd | sed s#root:x.*#root:x:\${USER_ID}:\${GROUP_ID}::\${HOME}:/bin/sh#g > ${HOME}/passwd.template \
62-
&& cat /etc/group | sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g > ${HOME}/group.template \
6365
# Change permissions to let any arbitrary user
64-
&& for f in "${HOME}" "/etc/passwd" "/etc/group" "/projects"; do \
65-
echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && \
66+
&& sed -i -e 's/theia-dev/theia/g' /.passwd.template /.group.template
67+
&& for f in "${HOME}" /etc/passwd /etc/group /projects; do \
68+
echo "Changing permissions on ${f}" && \
69+
chgrp -R 0 ${f} && \
6670
chmod -R g+rwX ${f}; \
6771
done
6872
ADD etc/entrypoint.sh /entrypoint.sh

dockerfiles/theia-endpoint-runtime/etc/entrypoint.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@ if ! grep -Fq "${USER_ID}" /etc/passwd; then
1818
# current user is an arbitrary
1919
# user (its uid is not in the
2020
# container /etc/passwd). Let's fix that
21-
cat ${HOME}/passwd.template | \
22-
sed "s/\${USER_ID}/${USER_ID}/g" | \
23-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
24-
sed "s/\${HOME}/\/home\/theia/g" > /etc/passwd
21+
sed -e "s/\${USER_ID}/${USER_ID}/g" \
22+
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
23+
-e "s/\${HOME}/\/home\/theia/g" \
24+
/.passwd.template > /etc/passwd
2525

26-
cat ${HOME}/group.template | \
27-
sed "s/\${USER_ID}/${USER_ID}/g" | \
28-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
29-
sed "s/\${HOME}/\/home\/theia/g" > /etc/group
26+
sed -e "s/\${USER_ID}/${USER_ID}/g" \
27+
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
28+
-e "s/\${HOME}/\/home\/theia/g"
29+
/.group.template > /etc/group
3030
fi
3131

3232
# Grant access to projects volume in case of non root user with sudo rights
3333
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1 && sudo -n true > /dev/null 2>&1; then
34-
sudo chown ${USER_ID}:${GROUP_ID} /projects
34+
sudo chmod 644 /etc/passwd /etc/group
35+
sudo chown root:root /etc/passwd /etc/group
36+
37+
sudo chown ${USER_ID}:${GROUP_ID} /projects "${HOME}"
3538
fi
3639

3740
# SITTERM / SIGINT

dockerfiles/theia/Dockerfile

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ RUN che:theia init -c ${HOME}/che-theia-init-sources.yml
7272
RUN che:theia cdn --theia="${CDN_PREFIX}" --monaco="${MONACO_CDN_PREFIX}"
7373

7474
# Compile Theia
75-
RUN yarn
75+
RUN yarn global add node-gyp && node-gyp install && yarn
7676

7777
# Run into production mode
7878
RUN che:theia production
@@ -112,25 +112,22 @@ COPY --from=builder /home/theia-dev/theia-source-code/production/plugins /defaul
112112
# Install curl and bash
113113
# Install ssh for cloning ssh-repositories
114114
# Install less for handling git diff properly
115-
RUN apk add --update --no-cache sudo git bzip2 which bash curl openssh openssh-keygen less
116-
RUN adduser -D -S -u 1001 -G root -h ${HOME} -s /bin/sh theia \
117-
&& echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
118-
# Create /projects for Che
119-
&& mkdir /projects \
120-
# Create root node_modules in order to not use node_modules in each project folder
121-
&& mkdir /node_modules \
115+
RUN apk add --update --no-cache sudo git bzip2 which bash curl openssh openssh-keygen less shadow \
116+
&& useradd -u 1001 -U -G root -d ${HOME} -s /bin/bash theia-dev \
117+
&& apk del --no-cache shadow \
118+
&& echo "%root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
119+
120+
RUN mkdir /projects /node_modules \
122121
# Download yeoman generator plug-in
123122
&& curl -L -o /default-theia-plugins/theia_yeoman_plugin.theia https://github.com/eclipse/theia-yeoman-plugin/releases/download/untagged-04f28ee329e479cc465b/theia_yeoman_plugin.theia \
124-
&& for f in "${HOME}" "/etc/passwd" "/etc/group /node_modules /default-theia-plugins /projects"; do\
125-
sudo chgrp -R 0 ${f} && \
126-
sudo chmod -R g+rwX ${f}; \
127-
done \
128-
&& cat /etc/passwd | sed s#root:x.*#root:x:\${USER_ID}:\${GROUP_ID}::\${HOME}:/bin/bash#g > ${HOME}/passwd.template \
129-
&& cat /etc/group | sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g > ${HOME}/group.template \
123+
# For non-root instances. File permissions will be fixed in `entrypoint.sh`.
124+
&& sed -e 's#theia:x.*#theia:x:\${USER_ID}:\${GROUP_ID}::\${HOME}:/bin/bash#g' \
125+
/etc/passwd > ${HOME}/.passwd.template \
126+
&& sed -e 's#^theia:.*#theia:x:${GROUP_ID}:#g' \
127+
/etc/group > ${HOME}/.group.template \
130128
# Add yeoman, theia plugin generator and typescript (to have tsc/typescript working)
131129
&& yarn global add yo @theia/generator-plugin@0.0.1-1540209403 typescript@2.9.2 \
132130
&& mkdir -p ${HOME}/.config/insight-nodejs/ \
133-
&& chmod -R 777 ${HOME}/.config/ \
134131
# Disable the statistics for yeoman
135132
&& echo '{"optOut": true}' > $HOME/.config/insight-nodejs/insight-yo.json \
136133
# Link yarn global modules for yeoman
@@ -140,9 +137,13 @@ RUN adduser -D -S -u 1001 -G root -h ${HOME} -s /bin/sh theia \
140137
# Cleanup yarn cache
141138
&& yarn cache clean \
142139
# Change permissions to allow editing of files for openshift user
143-
&& find ${HOME} -exec sh -c "chgrp 0 {}; chmod g+rwX {}" \;
140+
&& for f in "${HOME}" /etc/passwd /etc/group /node_modules /default-theia-plugins /projects; do\
141+
sudo chgrp -R 0 ${f} && \
142+
sudo chmod -R g+rwX ${f}; \
143+
done
144144

145145
COPY --chown=theia:root --from=builder /home/theia-dev/theia-source-code/production /home/theia
146+
146147
USER theia
147148
WORKDIR /projects
148149
ADD src/entrypoint.sh /entrypoint.sh

dockerfiles/theia/e2e/Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ FROM ${BUILD_ORGANIZATION}/${BUILD_PARENT_IMAGE}:${BUILD_TAG} as theia
1010
FROM cypress/browsers:chrome67
1111

1212
USER root
13-
ENV HOME=/root
1413
ENV NOCDN=true
1514

1615
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list
1716
RUN apt-get update && \
1817
apt-get install -y libx11-dev libxkbfile-dev sudo iproute2
19-
CMD /root/docker-run.sh
20-
RUN yarn global add typescript@2.9.2 node-gyp
18+
RUN yarn global add typescript@2.9.2 node-gyp && node-gyp install
2119

2220
# Add cypress scripts and grab dependencies
23-
COPY src /root/
24-
RUN cd /root && yarn
21+
COPY src /projects/
22+
RUN cd /projects && yarn
2523

2624
# Add tests
27-
ADD cypress /root/cypress/
25+
ADD cypress /projects/cypress/
2826

2927
COPY --from=theia /home/theia /home/theia
3028
COPY --from=theia /entrypoint.sh /entrypoint.sh
3129
RUN find /home/theia/ -name "binding.gyp" | xargs -i sh -c 'cd $(dirname {}) && node-gyp rebuild'
30+
31+
USER theia
32+
CMD /projects/docker-run.sh

dockerfiles/theia/e2e/src/docker-run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
: "${WAIT_COUNT:=30}"
1111

1212
echo "Starting Theia..."
13-
rm -rf /root/logs/*
14-
HOME=/home/theia /entrypoint.sh > /root/logs/theia.log 2>/root/logs/theia-error.log&
13+
rm -rf /projects/logs/*
14+
HOME=/home/theia /entrypoint.sh > /projects/logs/theia.log 2>/projects/logs/theia-error.log&
1515

1616
echo "Cleaning videos folder..."
1717
# Cleanup previous videos
18-
rm -rf /root/cypress/videos/*
18+
rm -rf /projects/cypress/videos/*
1919

2020
# Find TCP 0.0.0.0:3100 that will be opened by Theia.
2121
sleep 5s
@@ -35,4 +35,4 @@ fi
3535

3636
# Run tests
3737
echo "Run the tests"
38-
cd /root && unset LD_LIBRARY_PATH && /root/node_modules/.bin/cypress run -c trashAssetsBeforeRuns=false --browser chrome
38+
cd /projects && unset LD_LIBRARY_PATH && /projects/node_modules/.bin/cypress run -c trashAssetsBeforeRuns=false --browser chrome

dockerfiles/theia/e2e/test.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ fi
1919

2020
# Runs E2E tests in a docker container.
2121
run_test_in_docker_container() {
22+
mkdir -p ${base_dir}/$1
2223
docker_exec run --rm ${DOCKER_RUN_OPTIONS} \
23-
-v "${base_dir}/videos":/root/cypress/videos \
24-
-v "${base_dir}/logs":/root/logs \
24+
--user $1 \
25+
-v "${base_dir}/$1/videos":/projects/cypress/videos \
26+
-v "${base_dir}/$1/logs":/projects/logs \
2527
-v /var/run/docker.sock:/var/run/docker.sock \
2628
$IMAGE_NAME
2729
}
2830

29-
run_test_in_docker_container
31+
run_test_in_docker_container '0:0'
32+
run_test_in_docker_container '1234:5678'

0 commit comments

Comments
 (0)