Skip to content

Commit 1a91d61

Browse files
authored
Merge pull request #7234 from nextcloud/enh/7223/refactor-api-version-check
mastercontainer: refactor docker api version check
2 parents be1199a + cc41c34 commit 1a91d61

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

Containers/mastercontainer/start.sh

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,15 @@ elif ! sudo -E -u www-data test -r /var/run/docker.sock; then
7575
fi
7676
fi
7777

78-
# Check if api version is supported
79-
if ! sudo -E -u www-data docker info &>/dev/null; then
80-
print_red "Cannot connect to the docker socket. Cannot proceed."
81-
echo "Did you maybe remove group read permissions for the docker socket? AIO needs them in order to access the docker socket."
82-
echo "If SELinux is enabled on your host, see https://github.com/nextcloud/all-in-one#are-there-known-problems-when-selinux-is-enabled"
83-
echo "If you are on TrueNas SCALE, see https://github.com/nextcloud/all-in-one#can-i-run-aio-on-truenas-scale"
78+
# Get default docker api version
79+
API_VERSION_FILE="$(find ./ -name DockerActionManager.php | head -1)"
80+
API_VERSION="$(grep -oP 'const string API_VERSION.*\;' "$API_VERSION_FILE" | grep -oP '[0-9]+.[0-9]+' | head -1)"
81+
if [ -z "$API_VERSION" ]; then
82+
print_red "Could not get API_VERSION. Something is wrong!"
8483
exit 1
8584
fi
8685

87-
# Docker api version check
88-
API_VERSION_FILE="$(find ./ -name DockerActionManager.php | head -1)"
89-
API_VERSION="$(grep -oP 'const string API_VERSION.*\;' "$API_VERSION_FILE" | grep -oP '[0-9]+.[0-9]+' | head -1)"
86+
# Check if DOCKER_API_VERSION is set globally
9087
if [ -n "$DOCKER_API_VERSION" ]; then
9188
if ! echo "$DOCKER_API_VERSION" | grep -q '^[0-9].[0-9]\+$'; then
9289
print_red "You've set DOCKER_API_VERSION but not to an allowed value.
@@ -98,23 +95,45 @@ It is set to '$DOCKER_API_VERSION'."
9895
print_red "Please note that only v$API_VERSION is officially supported and tested by the maintainers of Nextcloud AIO."
9996
print_red "So you run on your own risk and things might break without warning."
10097
else
101-
# shellcheck disable=SC2001
102-
API_VERSION_NUMB="$(echo "$API_VERSION" | sed 's/\.//')"
103-
LOCAL_API_VERSION_NUMB="$(sudo -E -u www-data docker version | grep -i "api version" | grep -oP '[0-9]+.[0-9]+' | head -1 | sed 's/\.//')"
104-
if [ -n "$LOCAL_API_VERSION_NUMB" ] && [ -n "$API_VERSION_NUMB" ]; then
105-
if ! [ "$LOCAL_API_VERSION_NUMB" -ge "$API_VERSION_NUMB" ]; then
106-
print_red "Docker API v$API_VERSION is not supported by your docker engine. Cannot proceed. Please upgrade your docker engine if you want to run Nextcloud AIO!"
107-
echo "Alternatively, set the DOCKER_API_VERSION environmental variable to a compatible version."
108-
echo "However please note that only v$API_VERSION is officially supported and tested by the maintainers of Nextcloud AIO."
109-
echo "See https://github.com/nextcloud/all-in-one#how-to-adjust-the-internally-used-docker-api-version"
110-
exit 1
111-
fi
112-
else
113-
echo "LOCAL_API_VERSION_NUMB or API_VERSION_NUMB are not set correctly. Cannot check if the API version is supported."
114-
sleep 10
98+
# Export docker api version to use it everywhere
99+
export DOCKER_API_VERSION="$API_VERSION"
100+
fi
101+
102+
# Set a fallback docker api version. Needed for api version check.
103+
# The check will not work otherwise on old docker versions
104+
FALLBACK_DOCKER_API_VERSION="1.41"
105+
106+
# Check if docker info can be used
107+
if ! sudo -E -u www-data docker info &>/dev/null; then
108+
if ! sudo -E -u www-data DOCKER_API_VERSION="$FALLBACK_DOCKER_API_VERSION" docker info &>/dev/null; then
109+
print_red "Cannot connect to the docker socket. Cannot proceed."
110+
echo "Did you maybe remove group read permissions for the docker socket? AIO needs them in order to access the docker socket."
111+
echo "If SELinux is enabled on your host, see https://github.com/nextcloud/all-in-one#are-there-known-problems-when-selinux-is-enabled"
112+
echo "If you are on TrueNas SCALE, see https://github.com/nextcloud/all-in-one#can-i-run-aio-on-truenas-scale"
113+
exit 1
115114
fi
116115
fi
117116

117+
# Docker api version check
118+
# shellcheck disable=SC2001
119+
API_VERSION_NUMB="$(echo "$API_VERSION" | sed 's/\.//')"
120+
LOCAL_API_VERSION_NUMB="$(sudo -E -u www-data docker version | grep -i "api version" | grep -oP '[0-9]+.[0-9]+' | head -1 | sed 's/\.//')"
121+
if [ -z "$LOCAL_API_VERSION_NUMB" ]; then
122+
LOCAL_API_VERSION_NUMB="$(sudo -E -u www-data DOCKER_API_VERSION="$FALLBACK_DOCKER_API_VERSION" docker version | grep -i "api version" | grep -oP '[0-9]+.[0-9]+' | head -1 | sed 's/\.//')"
123+
fi
124+
if [ -n "$LOCAL_API_VERSION_NUMB" ] && [ -n "$API_VERSION_NUMB" ]; then
125+
if ! [ "$LOCAL_API_VERSION_NUMB" -ge "$API_VERSION_NUMB" ]; then
126+
print_red "Docker API v$API_VERSION is not supported by your docker engine. Cannot proceed. Please upgrade your docker engine if you want to run Nextcloud AIO!"
127+
echo "Alternatively, set the DOCKER_API_VERSION environmental variable to a compatible version."
128+
echo "However please note that only v$API_VERSION is officially supported and tested by the maintainers of Nextcloud AIO."
129+
echo "See https://github.com/nextcloud/all-in-one#how-to-adjust-the-internally-used-docker-api-version"
130+
exit 1
131+
fi
132+
else
133+
echo "LOCAL_API_VERSION_NUMB or API_VERSION_NUMB are not set correctly. Cannot check if the API version is supported."
134+
sleep 10
135+
fi
136+
118137
# Check Storage drivers
119138
STORAGE_DRIVER="$(sudo -E -u www-data docker info | grep "Storage Driver")"
120139
# Check if vfs is used: https://github.com/nextcloud/all-in-one/discussions/1467

0 commit comments

Comments
 (0)