Skip to content

Commit f96c573

Browse files
coliseeRobin Alexander
andauthored
Fix issue 169 (#184)
* Do not install git * No need to copy script setup.sh inside the image * Review image build process: * Dockerfile: in charge of retrieving librebooking files and SHA * setup.sh: in charge of customizing librebooking * Implement "config/custom-version.txt" * Implement hadolint reccomendations * Make Dockerfile more robust --------- Co-authored-by: Robin Alexander <colisee@hotmail>
1 parent e3f875d commit f96c573

2 files changed

Lines changed: 33 additions & 51 deletions

File tree

Dockerfile

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
ARG VERSION_PHP=8.3
22
ARG VERSION_COMPOSER=lts
3+
ARG VERSION_GIT=2.52.0
34

45
FROM composer:${VERSION_COMPOSER} AS comp
5-
FROM php:${VERSION_PHP}-apache
66

7+
# Get upstream
8+
FROM alpine/git:${VERSION_GIT} AS upstream
9+
ARG APP_GH_ADD_SHA=false
10+
ARG APP_GH_REF=refs/heads/develop
11+
ARG GIT_TREE=${APP_GH_REF##*/}
12+
ARG UPSTREAM_URL="https://github.com/librebooking/librebooking"
13+
WORKDIR /upstream
14+
RUN <<EORUN
15+
set -eux
16+
git clone ${UPSTREAM_URL} /upstream
17+
git checkout ${GIT_TREE}
18+
if [ "${APP_GH_ADD_SHA}" = "true" ]; then
19+
git describe --tags --long > config/custom-version.txt
20+
fi
21+
rm -rf .git
22+
EORUN
23+
24+
FROM php:${VERSION_PHP}-apache
725
# Labels
826
LABEL org.opencontainers.image.title="LibreBooking"
927
LABEL org.opencontainers.image.description="LibreBooking as a container"
@@ -13,27 +31,24 @@ LABEL org.opencontainers.image.licenses="GPL-3.0"
1331
LABEL org.opencontainers.image.authors="colisee@hotmail.com"
1432

1533
# Copy entrypoint scripts
16-
COPY --chmod=755 bin /usr/local/bin/
34+
COPY --chmod=0755 bin /usr/local/bin/
1735

1836
# Create cron jobs
19-
COPY --chown=www-data:www-data --chmod=0755 lb-jobs-cron /config/
37+
COPY --chown=www-data:www-data --chmod=0755 \
38+
lb-jobs-cron /config/
2039

2140
# Copy composer
2241
COPY --from=comp /usr/bin/composer /usr/bin/composer
2342

43+
# Copy Librebooking
44+
COPY --from=upstream \
45+
--chown=www-data:root --chmod=0775 \
46+
/upstream/ /var/www/html/
47+
2448
# Update and install required debian packages
2549
ENV DEBIAN_FRONTEND=noninteractive
26-
ARG APP_GH_REF
27-
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
30-
RUN <<EORUN
31-
set -xeu
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
36-
rm /usr/local/bin/setup.sh
50+
RUN --mount=type=bind,source=setup.sh,target=/tmp/setup.sh <<EORUN
51+
bash /tmp/setup.sh
3752
EORUN
3853

3954
# Environment

setup.sh

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ apt-get update
1313
apt-get upgrade --yes
1414
apt-get install --yes --no-install-recommends \
1515
cron \
16-
git \
1716
libjpeg-dev \
1817
libldap-dev \
1918
libpng-dev \
@@ -50,36 +49,6 @@ sed \
5049
-i /etc/apache2/sites-available/000-default.conf \
5150
-e 's/<VirtualHost *:80>/<VirtualHost *:8080>/'
5251

53-
set -xeuo pipefail
54-
LB_TARBALL_URL="https://api.github.com/repos/LibreBooking/librebooking/tarball/${APP_GH_REF}"
55-
curl \
56-
--fail \
57-
--silent \
58-
--location "${LB_TARBALL_URL}" |
59-
tar --extract --gzip --directory=/var/www/html --strip-components=1
60-
if [ "${APP_GH_ADD_SHA}" = "true" ]; then
61-
LB_SHORT_SHA=""
62-
# TARBALL_FILENAME will be like the result of a `git describe` For
63-
# example: 'LibreBooking-librebooking-v4.1.0-126-g6cc8a4c.tar.gz' where
64-
# 'g6cc8a4c' is the short SHA prefixed with 'g'. So the short SHA is
65-
# '6cc8a4c'
66-
TARBALL_FILENAME=$(
67-
curl \
68-
--head \
69-
--fail \
70-
--silent \
71-
--show-error \
72-
--location "${LB_TARBALL_URL}" |
73-
sed -nE 's/.*filename="?([^";]+)"?.*/\1/p'
74-
)
75-
LB_SHORT_SHA=$(echo "${TARBALL_FILENAME}" | sed -E 's/.*-g([0-9a-f]+)\.tar\.gz/\1/')
76-
if [ -n "${LB_SHORT_SHA}" ]; then
77-
printf '%s\n' "${LB_SHORT_SHA}" >/var/www/html/config/version-suffix.txt
78-
else
79-
echo "ERROR determining the LB_SHORT_SHA value from TARBALL_FILENAME ${TARBALL_FILENAME}" >&2
80-
exit 1
81-
fi
82-
fi
8352
if [ -f /var/www/html/composer.json ]; then
8453
sed \
8554
-i /var/www/html/composer.json \
@@ -96,19 +65,17 @@ if ! [ -d /var/www/html/tpl_c ]; then
9665
fi
9766
mkdir /var/www/html/Web/uploads/reservation
9867

99-
chown www-data:root \
68+
chown --recursive www-data:root \
10069
/var/www/html/config \
70+
/var/www/html/plugins \
10171
/var/www/html/tpl_c \
10272
/var/www/html/Web/uploads/images \
10373
/var/www/html/Web/uploads/reservation \
10474
/usr/local/etc/php/conf.d/librebooking.ini
105-
chmod g+rwx \
75+
chmod --recursive g+rwx \
10676
/var/www/html/config \
77+
/var/www/html/plugins \
10778
/var/www/html/tpl_c \
10879
/var/www/html/Web/uploads/images \
10980
/var/www/html/Web/uploads/reservation \
11081
/usr/local/etc/php/conf.d/librebooking.ini
111-
chown --recursive www-data:root \
112-
/var/www/html/plugins
113-
chmod --recursive g+rwx \
114-
/var/www/html/plugins

0 commit comments

Comments
 (0)