Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
ARG VERSION_PHP=8.3
ARG VERSION_COMPOSER=lts
ARG VERSION_GIT=2.52.0

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

# Get upstream
FROM alpine/git:${VERSION_GIT} AS upstream
ARG APP_GH_ADD_SHA=false
ARG APP_GH_REF=refs/heads/develop
ARG GIT_TREE=${APP_GH_REF##*/}
ARG UPSTREAM_URL="https://github.com/librebooking/librebooking"
WORKDIR /upstream
RUN <<EORUN
set -eux
git clone ${UPSTREAM_URL} /upstream
git checkout ${GIT_TREE}
if [ "${APP_GH_ADD_SHA}" = "true" ]; then
git describe --tags --long > config/custom-version.txt
fi
rm -rf .git
EORUN

FROM php:${VERSION_PHP}-apache
# Labels
LABEL org.opencontainers.image.title="LibreBooking"
LABEL org.opencontainers.image.description="LibreBooking as a container"
Expand All @@ -13,27 +31,24 @@ LABEL org.opencontainers.image.licenses="GPL-3.0"
LABEL org.opencontainers.image.authors="colisee@hotmail.com"

# Copy entrypoint scripts
COPY --chmod=755 bin /usr/local/bin/
COPY --chmod=0755 bin /usr/local/bin/

# Create cron jobs
COPY --chown=www-data:www-data --chmod=0755 lb-jobs-cron /config/
COPY --chown=www-data:www-data --chmod=0755 \
lb-jobs-cron /config/

# Copy composer
COPY --from=comp /usr/bin/composer /usr/bin/composer

# Copy Librebooking
COPY --from=upstream \
--chown=www-data:root --chmod=0775 \
/upstream/ /var/www/html/

# Update and install required debian packages
ENV DEBIAN_FRONTEND=noninteractive
ARG APP_GH_REF
ARG APP_GH_ADD_SHA=false
# hadolint ignore=DL3008 # 'Pin versions in apt get install'
COPY setup.sh /usr/local/bin/setup.sh
RUN <<EORUN
set -xeu
export APP_GH_REF="${APP_GH_REF}"
export APP_GH_ADD_SHA="${APP_GH_ADD_SHA}"
chmod +x /usr/local/bin/setup.sh
/usr/local/bin/setup.sh
rm /usr/local/bin/setup.sh
RUN --mount=type=bind,source=setup.sh,target=/tmp/setup.sh <<EORUN
bash /tmp/setup.sh
EORUN

# Environment
Expand Down
41 changes: 4 additions & 37 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ apt-get update
apt-get upgrade --yes
apt-get install --yes --no-install-recommends \
cron \
git \
libjpeg-dev \
libldap-dev \
libpng-dev \
Expand Down Expand Up @@ -50,36 +49,6 @@ sed \
-i /etc/apache2/sites-available/000-default.conf \
-e 's/<VirtualHost *:80>/<VirtualHost *:8080>/'

set -xeuo pipefail
LB_TARBALL_URL="https://api.github.com/repos/LibreBooking/librebooking/tarball/${APP_GH_REF}"
curl \
--fail \
--silent \
--location "${LB_TARBALL_URL}" |
tar --extract --gzip --directory=/var/www/html --strip-components=1
if [ "${APP_GH_ADD_SHA}" = "true" ]; then
LB_SHORT_SHA=""
# TARBALL_FILENAME will be like the result of a `git describe` For
# example: 'LibreBooking-librebooking-v4.1.0-126-g6cc8a4c.tar.gz' where
# 'g6cc8a4c' is the short SHA prefixed with 'g'. So the short SHA is
# '6cc8a4c'
TARBALL_FILENAME=$(
curl \
--head \
--fail \
--silent \
--show-error \
--location "${LB_TARBALL_URL}" |
sed -nE 's/.*filename="?([^";]+)"?.*/\1/p'
)
LB_SHORT_SHA=$(echo "${TARBALL_FILENAME}" | sed -E 's/.*-g([0-9a-f]+)\.tar\.gz/\1/')
if [ -n "${LB_SHORT_SHA}" ]; then
printf '%s\n' "${LB_SHORT_SHA}" >/var/www/html/config/version-suffix.txt
else
echo "ERROR determining the LB_SHORT_SHA value from TARBALL_FILENAME ${TARBALL_FILENAME}" >&2
exit 1
fi
fi
if [ -f /var/www/html/composer.json ]; then
sed \
-i /var/www/html/composer.json \
Expand All @@ -96,19 +65,17 @@ if ! [ -d /var/www/html/tpl_c ]; then
fi
mkdir /var/www/html/Web/uploads/reservation

chown www-data:root \
chown --recursive www-data:root \
/var/www/html/config \
/var/www/html/plugins \
/var/www/html/tpl_c \
/var/www/html/Web/uploads/images \
/var/www/html/Web/uploads/reservation \
/usr/local/etc/php/conf.d/librebooking.ini
chmod g+rwx \
chmod --recursive g+rwx \
/var/www/html/config \
/var/www/html/plugins \
/var/www/html/tpl_c \
/var/www/html/Web/uploads/images \
/var/www/html/Web/uploads/reservation \
/usr/local/etc/php/conf.d/librebooking.ini
chown --recursive www-data:root \
/var/www/html/plugins
chmod --recursive g+rwx \
/var/www/html/plugins