Skip to content

Commit d358682

Browse files
ryanjbonnelljaydrogers
authored andcommitted
Accept separate arguments and line continuations in package install scripts
Previously only the first argument was used, so packages passed as separate arguments were silently skipped. Also disables globbing while splitting and skips the install when no packages are given. From #708. Resolved conflicts with the release branch and added a ShellCheck directive for the intentional word split.
1 parent acc17e2 commit d358682

3 files changed

Lines changed: 86 additions & 8 deletions

File tree

‎docs/content/docs/8.reference/2.command-reference.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ This command will detect the operating system and install packages if it is an A
2424
docker-php-serversideup-dep-install-alpine git
2525
```
2626

27+
Packages can be passed as separate arguments, as a comma-separated list, or split across multiple lines with backslash continuations:
28+
29+
```bash [Example - Installing multiple packages on Alpine]
30+
# Separate arguments
31+
docker-php-serversideup-dep-install-alpine git zip unzip
32+
33+
# Comma-separated
34+
docker-php-serversideup-dep-install-alpine "git, zip, unzip"
35+
36+
# Backslash continuations (useful in a Dockerfile)
37+
docker-php-serversideup-dep-install-alpine \
38+
git \
39+
zip \
40+
unzip
41+
```
42+
2743
## docker-php-serversideup-dep-install-debian
2844
This command will detect the operating system and install packages if it is a Debian based system. This is helpful if you're building multiple operating systems from the same Dockerfile.
2945

@@ -32,6 +48,22 @@ This command will detect the operating system and install packages if it is a De
3248
docker-php-serversideup-dep-install-debian git
3349
```
3450

51+
Packages can be passed as separate arguments, as a comma-separated list, or split across multiple lines with backslash continuations:
52+
53+
```bash [Example - Installing multiple packages on Debian]
54+
# Separate arguments
55+
docker-php-serversideup-dep-install-debian git zip unzip
56+
57+
# Comma-separated
58+
docker-php-serversideup-dep-install-debian "git, zip, unzip"
59+
60+
# Backslash continuations (useful in a Dockerfile)
61+
docker-php-serversideup-dep-install-debian \
62+
git \
63+
zip \
64+
unzip
65+
```
66+
3567
## docker-php-serversideup-download
3668
A build-time helper that downloads a file with retries. Our build matrix starts every image at the same moment, and hosts like GitHub occasionally answer that burst with a `500`. This command retries five times with a short backoff and fails the build if the file never arrives. It's useful in your own Dockerfiles for the same reason.
3769

‎src/common/usr/local/bin/docker-php-serversideup-dep-install-alpine‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ set -oe
33

44
###################################################
55
# Usage: docker-php-serversideup-dep-install-alpine [alpine-packages]
6+
#
7+
# Packages may be passed as separate arguments, comma-delimited, or both:
8+
#
9+
# docker-php-serversideup-dep-install-alpine git, zip
10+
#
11+
# docker-php-serversideup-dep-install-alpine \
12+
# git \
13+
# zip
614
###################################################
715
# This script installs alpine packages that are passed to it
816

@@ -27,20 +35,35 @@ fi
2735
############
2836
# Functions
2937
############
38+
# Accepts any mix of space-separated arguments and comma-delimited lists
39+
# (e.g. "pkg1, pkg2" or "pkg1 pkg2" or "pkg1 \ pkg2" across lines in a Dockerfile)
3040
convert_comma_delimited_to_space_separated() {
31-
echo $1 | tr ',' ' '
41+
printf '%s\n' "$*" | tr ',' ' '
3242
}
3343

3444
############
3545
# Main
3646
############
37-
DEP_PACKAGES=$(convert_comma_delimited_to_space_separated "$@")
47+
# Re-split into one argument per package. Globbing is disabled so a package
48+
# name such as "php*" is never expanded against files in the working directory.
49+
set -f
50+
# shellcheck disable=SC2046
51+
set -- $(convert_comma_delimited_to_space_separated "$@")
52+
set +f
53+
54+
if [ $# -eq 0 ]; then
55+
echo "ℹ️ INFO ($script_name): No packages were found in the arguments. Continuing..."
56+
exit 0
57+
fi
58+
59+
# "$*" joins the packages with single spaces for display
60+
DEP_PACKAGES="$*"
3861
echo "🤖 Installing: $DEP_PACKAGES"
39-
apk update
40-
apk add --no-cache $DEP_PACKAGES
62+
apk update
63+
apk add --no-cache "$@"
4164

4265

4366
echo "🧼 Cleaning up installation of: $DEP_PACKAGES"
4467
rm -rf /var/cache/apk/*
4568

46-
echo "⚡️ Completed installation of: $DEP_PACKAGES"
69+
echo "⚡️ Completed installation of: $DEP_PACKAGES"

‎src/common/usr/local/bin/docker-php-serversideup-dep-install-debian‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ set -oe
33

44
###################################################
55
# Usage: docker-php-serversideup-dep-install-debian [debian-packages]
6+
#
7+
# Packages may be passed as separate arguments, comma-delimited, or both:
8+
#
9+
# docker-php-serversideup-dep-install-debian git, zip
10+
#
11+
# docker-php-serversideup-dep-install-debian \
12+
# git \
13+
# zip
614
###################################################
715
# This script installs debian packages that are passed to it
816

@@ -28,17 +36,32 @@ fi
2836
############
2937
# Functions
3038
############
39+
# Accepts any mix of space-separated arguments and comma-delimited lists
40+
# (e.g. "pkg1, pkg2" or "pkg1 pkg2" or "pkg1 \ pkg2" across lines in a Dockerfile)
3141
convert_comma_delimited_to_space_separated() {
32-
echo $1 | tr ',' ' '
42+
printf '%s\n' "$*" | tr ',' ' '
3343
}
3444

3545
############
3646
# Main
3747
############
38-
DEP_PACKAGES=$(convert_comma_delimited_to_space_separated "$@")
48+
# Re-split into one argument per package. Globbing is disabled so a package
49+
# name such as "php*" is never expanded against files in the working directory.
50+
set -f
51+
# shellcheck disable=SC2046
52+
set -- $(convert_comma_delimited_to_space_separated "$@")
53+
set +f
54+
55+
if [ $# -eq 0 ]; then
56+
echo "ℹ️ INFO ($script_name): No packages were found in the arguments. Continuing..."
57+
exit 0
58+
fi
59+
60+
# "$*" joins the packages with single spaces for display
61+
DEP_PACKAGES="$*"
3962
echo "🤖 Installing: $DEP_PACKAGES"
4063
apt-get -o Acquire::Retries=3 update
41-
apt-get -o Acquire::Retries=3 install -y $DEP_PACKAGES
64+
apt-get -o Acquire::Retries=3 install -y "$@"
4265

4366

4467
echo "🧼 Cleaning up installation of: $DEP_PACKAGES"

0 commit comments

Comments
 (0)