Skip to content

Commit 88179d4

Browse files
fix: convert from long RUN statements to a setup.sh script
Convert the multiple `RUN` statements into a `setup.sh` bash script. Add a CI job to check the shell scripts.
1 parent 6210d1d commit 88179d4

3 files changed

Lines changed: 144 additions & 113 deletions

File tree

.github/workflows/build_pull_request.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ jobs:
1818
with:
1919
dockerfile: Dockerfile
2020

21+
lint_shell_scripts:
22+
name: Lint shell scripts
23+
runs-on: ubuntu-latest
24+
steps:
25+
-
26+
name: Checkout github repository
27+
uses: actions/checkout@v6
28+
-
29+
name: Install shell lint tools
30+
run: |
31+
sudo apt-get update
32+
sudo apt-get install -y shellcheck shfmt
33+
-
34+
name: Run shellcheck
35+
run: |
36+
set -euo pipefail
37+
mapfile -t scripts < <(git ls-files '*.sh')
38+
shellcheck --severity style "${scripts[@]}"
39+
-
40+
name: Run shfmt
41+
run: |
42+
set -euo pipefail
43+
mapfile -t scripts < <(git ls-files '*.sh')
44+
shfmt -d -i 4 -ci "${scripts[@]}"
45+
2146
check_build:
2247
runs-on: ubuntu-latest
2348
env:

Dockerfile

Lines changed: 6 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -23,123 +23,16 @@ COPY --from=comp /usr/bin/composer /usr/bin/composer
2323

2424
# Update and install required debian packages
2525
ENV DEBIAN_FRONTEND=noninteractive
26-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
27-
# hadolint ignore=DL3008 # 'Pin versions in apt get install'
28-
RUN <<EORUN
29-
set -xeu
30-
apt-get update
31-
apt-get upgrade --yes
32-
apt-get install --yes --no-install-recommends \
33-
cron \
34-
git \
35-
libjpeg-dev \
36-
libldap-dev \
37-
libpng-dev \
38-
libfreetype6-dev \
39-
unzip
40-
apt-get clean
41-
rm -rf /var/lib/apt/lists/*
42-
EORUN
43-
44-
# Customize the http & php environment
45-
RUN <<EORUN
46-
set -xeu
47-
cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
48-
cat > /etc/apache2/conf-available/remoteip.conf <<EOF
49-
RemoteIPHeader X-Real-IP
50-
RemoteIPInternalProxy 10.0.0.0/8
51-
RemoteIPInternalProxy 172.16.0.0/12
52-
RemoteIPInternalProxy 192.168.0.0/16
53-
EOF
54-
a2enconf remoteip
55-
a2enmod rewrite
56-
a2enmod headers
57-
a2enmod remoteip
58-
docker-php-ext-configure gd --with-jpeg --with-freetype
59-
docker-php-ext-install mysqli gd ldap
60-
pecl install timezonedb
61-
docker-php-ext-enable timezonedb
62-
mkdir --parent /var/log/librebooking
63-
chown --recursive www-data:root /var/log/librebooking
64-
chmod --recursive g+rwx /var/log/librebooking
65-
touch /usr/local/etc/php/conf.d/librebooking.ini
66-
sed \
67-
-i /etc/apache2/ports.conf \
68-
-e 's/Listen 80/Listen 8080/' \
69-
-e 's/Listen 443/Listen 8443/'
70-
sed \
71-
-i /etc/apache2/sites-available/000-default.conf \
72-
-e 's/<VirtualHost *:80>/<VirtualHost *:8080>/'
73-
EORUN
74-
75-
# Get and customize librebooking
7626
ARG APP_GH_REF
7727
ARG APP_GH_ADD_SHA=false
28+
# hadolint ignore=DL3008 # 'Pin versions in apt get install'
29+
COPY setup.sh /usr/local/bin/setup.sh
7830
RUN <<EORUN
7931
set -xeu
80-
LB_TARBALL_URL="https://api.github.com/repos/LibreBooking/librebooking/tarball/${APP_GH_REF}"
81-
curl \
82-
--fail \
83-
--silent \
84-
--location ${LB_TARBALL_URL} \
85-
| tar --extract --gzip --directory=/var/www/html --strip-components=1
86-
if [ "${APP_GH_ADD_SHA}" = "true" ]; then
87-
LB_SHORT_SHA=""
88-
# TARBALL_FILENAME will be like the result of a `git describe` For
89-
# example: 'LibreBooking-librebooking-v4.1.0-126-g6cc8a4c.tar.gz' where
90-
# 'g6cc8a4c' is the short SHA prefixed with 'g'. So the short SHA is
91-
# '6cc8a4c'
92-
TARBALL_FILENAME=$(\
93-
curl \
94-
--head \
95-
--fail \
96-
--silent \
97-
--show-error \
98-
--location ${LB_TARBALL_URL} \
99-
| sed -nE 's/.*filename="?([^";]+)"?.*/\1/p')
100-
LB_SHORT_SHA=$(echo "${TARBALL_FILENAME}" | sed -E 's/.*-g([0-9a-f]+)\.tar\.gz/\1/')
101-
if [ -n "${LB_SHORT_SHA}" ]; then
102-
printf '%s\n' "${LB_SHORT_SHA}" > /var/www/html/config/version-suffix.txt
103-
else
104-
echo "ERROR determining the LB_SHORT_SHA value from TARBALL_FILENAME ${TARBALL_FILENAME}" >&2
105-
exit 1
106-
fi
107-
fi
108-
if [ -f /var/www/html/composer.json ]; then
109-
sed \
110-
-i /var/www/html/composer.json \
111-
-e "s:\(.*\)nickdnk/graph-sdk\(.*\)7.0\(.*\):\1joelbutcher/facebook-graph-sdk\26.1\3:"
112-
composer install
113-
fi
114-
sed \
115-
-i /var/www/html/database_schema/create-user.sql \
116-
-e "s:^DROP USER ':DROP USER IF EXISTS ':g" \
117-
-e "s:booked_user:schedule_user:g" \
118-
-e "s:localhost:%:g"
119-
if ! [ -d /var/www/html/tpl_c ]; then
120-
mkdir /var/www/html/tpl_c
121-
fi
122-
mkdir /var/www/html/Web/uploads/reservation
123-
EORUN
124-
125-
RUN <<EORUN
126-
set -xeu
127-
chown www-data:root \
128-
/var/www/html/config \
129-
/var/www/html/tpl_c \
130-
/var/www/html/Web/uploads/images \
131-
/var/www/html/Web/uploads/reservation \
132-
/usr/local/etc/php/conf.d/librebooking.ini
133-
chmod g+rwx \
134-
/var/www/html/config \
135-
/var/www/html/tpl_c \
136-
/var/www/html/Web/uploads/images \
137-
/var/www/html/Web/uploads/reservation \
138-
/usr/local/etc/php/conf.d/librebooking.ini
139-
chown --recursive www-data:root \
140-
/var/www/html/plugins
141-
chmod --recursive g+rwx \
142-
/var/www/html/plugins
32+
export APP_GH_REF=${APP_GH_REF}
33+
export APP_GH_ADD_SHA=${APP_GH_ADD_SHA}
34+
chmod +x /usr/local/bin/setup.sh
35+
/usr/local/bin/setup.sh
14336
EORUN
14437

14538
# Environment

setup.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
trap 'echo "Exit status $? at line $LINENO from: $BASH_COMMAND"' ERR
7+
8+
export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: '
9+
set -x
10+
11+
apt-get update
12+
apt-get upgrade --yes
13+
apt-get install --yes --no-install-recommends \
14+
cron \
15+
git \
16+
libjpeg-dev \
17+
libldap-dev \
18+
libpng-dev \
19+
libfreetype6-dev \
20+
unzip
21+
apt-get clean
22+
rm -rf /var/lib/apt/lists/*
23+
24+
# Customize the http & php environment
25+
cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
26+
cat >/etc/apache2/conf-available/remoteip.conf <<EOF
27+
RemoteIPHeader X-Real-IP
28+
RemoteIPInternalProxy 10.0.0.0/8
29+
RemoteIPInternalProxy 172.16.0.0/12
30+
RemoteIPInternalProxy 192.168.0.0/16
31+
EOF
32+
a2enconf remoteip
33+
a2enmod rewrite
34+
a2enmod headers
35+
a2enmod remoteip
36+
docker-php-ext-configure gd --with-jpeg --with-freetype
37+
docker-php-ext-install mysqli gd ldap
38+
pecl install timezonedb
39+
docker-php-ext-enable timezonedb
40+
mkdir --parent /var/log/librebooking
41+
chown --recursive www-data:root /var/log/librebooking
42+
chmod --recursive g+rwx /var/log/librebooking
43+
touch /usr/local/etc/php/conf.d/librebooking.ini
44+
sed \
45+
-i /etc/apache2/ports.conf \
46+
-e 's/Listen 80/Listen 8080/' \
47+
-e 's/Listen 443/Listen 8443/'
48+
sed \
49+
-i /etc/apache2/sites-available/000-default.conf \
50+
-e 's/<VirtualHost *:80>/<VirtualHost *:8080>/'
51+
52+
set -xeuo pipefail
53+
LB_TARBALL_URL="https://api.github.com/repos/LibreBooking/librebooking/tarball/${APP_GH_REF}"
54+
curl \
55+
--fail \
56+
--silent \
57+
--location "${LB_TARBALL_URL}" |
58+
tar --extract --gzip --directory=/var/www/html --strip-components=1
59+
if [ "${APP_GH_ADD_SHA}" = "true" ]; then
60+
LB_SHORT_SHA=""
61+
# TARBALL_FILENAME will be like the result of a `git describe` For
62+
# example: 'LibreBooking-librebooking-v4.1.0-126-g6cc8a4c.tar.gz' where
63+
# 'g6cc8a4c' is the short SHA prefixed with 'g'. So the short SHA is
64+
# '6cc8a4c'
65+
TARBALL_FILENAME=$(
66+
curl \
67+
--head \
68+
--fail \
69+
--silent \
70+
--show-error \
71+
--location "${LB_TARBALL_URL}" |
72+
sed -nE 's/.*filename="?([^";]+)"?.*/\1/p'
73+
)
74+
LB_SHORT_SHA=$(echo "${TARBALL_FILENAME}" | sed -E 's/.*-g([0-9a-f]+)\.tar\.gz/\1/')
75+
if [ -n "${LB_SHORT_SHA}" ]; then
76+
printf '%s\n' "${LB_SHORT_SHA}" >/var/www/html/config/version-suffix.txt
77+
else
78+
echo "ERROR determining the LB_SHORT_SHA value from TARBALL_FILENAME ${TARBALL_FILENAME}" >&2
79+
exit 1
80+
fi
81+
fi
82+
if [ -f /var/www/html/composer.json ]; then
83+
sed \
84+
-i /var/www/html/composer.json \
85+
-e "s:\(.*\)nickdnk/graph-sdk\(.*\)7.0\(.*\):\1joelbutcher/facebook-graph-sdk\26.1\3:"
86+
composer install
87+
fi
88+
sed \
89+
-i /var/www/html/database_schema/create-user.sql \
90+
-e "s:^DROP USER ':DROP USER IF EXISTS ':g" \
91+
-e "s:booked_user:schedule_user:g" \
92+
-e "s:localhost:%:g"
93+
if ! [ -d /var/www/html/tpl_c ]; then
94+
mkdir /var/www/html/tpl_c
95+
fi
96+
mkdir /var/www/html/Web/uploads/reservation
97+
98+
chown www-data:root \
99+
/var/www/html/config \
100+
/var/www/html/tpl_c \
101+
/var/www/html/Web/uploads/images \
102+
/var/www/html/Web/uploads/reservation \
103+
/usr/local/etc/php/conf.d/librebooking.ini
104+
chmod g+rwx \
105+
/var/www/html/config \
106+
/var/www/html/tpl_c \
107+
/var/www/html/Web/uploads/images \
108+
/var/www/html/Web/uploads/reservation \
109+
/usr/local/etc/php/conf.d/librebooking.ini
110+
chown --recursive www-data:root \
111+
/var/www/html/plugins
112+
chmod --recursive g+rwx \
113+
/var/www/html/plugins

0 commit comments

Comments
 (0)