-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer-entrypoint.sh
executable file
·65 lines (57 loc) · 2.09 KB
/
container-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash -e
if [ $# -eq 1 ] && [ "$1" == "versions" ]; then
echo "-> python env:"
python --version
pip --version
pipenv --version
echo
echo "-> kubectl:"
kubectl version --client
echo
echo "-> apptestctl:"
apptestctl version
echo "-> kind:"
kind version
echo
echo "-> go:"
go version
exit 0
fi
# add user and group 'ats' with the same UID and GID as the user running the image in the host OS
if [ "${USE_UID:-0}" -ne 0 ] && [ "${USE_GID:-0}" -ne 0 ]; then
groupadd -f -g "$USE_GID" ats
groupadd -f -g "$DOCKER_GID" docker
useradd -g "$USE_GID" -G docker -M -l -u "$USE_UID" ats -d "$ATS_DIR" -s /bin/bash || true
fi
# if the user in the host OS uses different UID/GID than default, we have to 'chown'
if [ "${USE_UID:-0}" -ne 1000 ] || [ "${USE_GID:-0}" -ne 1000 ]; then
chown -R "$USE_UID":"$USE_GID" "$ATS_DIR"
fi
# if the user in the OS uses different uid/gid for pipenv cache, we have to remember that and chown
# shellcheck disable=SC2153
PIPENV_CACHE_UID=$(stat -c '%u' "${PIPENV_CACHE_DIR}")
PIPENV_CACHE_GID=$(stat -c '%g' "${PIPENV_CACHE_DIR}")
PIPENV_PERM_CHANGED=0
if [ "${USE_UID:-0}" -ne "${PIPENV_CACHE_UID}" ] || [ "${USE_GID:-0}" -ne "${PIPENV_CACHE_GID}" ]; then
PIPENV_PERM_CHANGED=1
chown -R "$USE_UID":"$USE_GID" "$PIPENV_CACHE_DIR"
fi
# if the user in the OS uses different uid/gid for venvs, we have to remember that and chown
# shellcheck disable=SC2153
VENVS_UID=$(stat -c '%u' "${VENVS_DIR}")
VENVS_GID=$(stat -c '%g' "${VENVS_DIR}")
VENVS_PERM_CHANGED=0
if [ "${USE_UID:-0}" -ne "${VENVS_UID}" ] || [ "${USE_GID:-0}" -ne "${VENVS_GID}" ]; then
VENVS_PERM_CHANGED=1
chown -R "$USE_UID":"$USE_GID" "$VENVS_DIR"
fi
# run ats
sudo --preserve-env=PYTHONPATH,PATH,GOPATH -g "#$USE_GID" -u "#$USE_UID" -- python -m app_test_suite "$@"
# revert original permissions on pipenv cache (if changed)
if [ "${PIPENV_PERM_CHANGED}" -eq 1 ]; then
chown -R "$PIPENV_CACHE_UID":"$PIPENV_CACHE_GID" "$PIPENV_CACHE_DIR"
fi
# revert original permissions on venvs dir (if changed)
if [ "${VENVS_PERM_CHANGED}" -eq 1 ]; then
chown -R "$VENVS_UID":"$VENVS_GID" "$VENVS_DIR"
fi