Skip to content

Commit

Permalink
Version 2.0 (#41)
Browse files Browse the repository at this point in the history
* Complete review of github action

* Complete review of github action

* Complete review of github action

* Better resolution of issue #25

The timezonedb php extension is installed in the docker image and no longer
through the entrypoint

* Fix issue #31

File BUILD.md updated

* Enhance github action (#36)

* Derive image tag from the workflow input

* Fix variable name mis-spelling

* Fix call to docker/build-push-action

* Specify the repository to be checked out

* Specify the repository to be checked out

* Specify the repository to be checked out

* Specify the repository to be checked out

* Enhance docker image metadata setting

* Enhance docker image metadata setting

* Enhance docker image metadata setting

* Enhance docker image metadata setting

* Drop repository variables

* Docker image v2 (#39)

* Docker image v2

* Review documentation

* Fix /var/www/html mount detection

---------

Co-authored-by: Robin Alexander <robin.alexander@netplus.ch>

* Fix issue 38 (#40)

* Fix issue 38

* Add registry name and login as non-compulsory arguments

* Fix issue 38

---------

Co-authored-by: Robin Alexander <robin.alexander@netplus.ch>

---------

Co-authored-by: Robin Alexander <robin.alexander@netplus.ch>
  • Loading branch information
colisee and Robin Alexander authored Jun 14, 2023
1 parent 4fcd76d commit e051283
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 279 deletions.
39 changes: 31 additions & 8 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,33 @@ on:
app-gh-ref:
required: true
type: string
default: 'refs/heads/develop'
reg_name:
required: true
type: string
default: 'docker.io'
reg_login:
required: true
type: string
default: 'librebooking'
workflow_dispatch:
inputs:
app-gh-ref:
required: true
description: 'Application github reference'
default: 'refs/heads/develop'
reg_name:
required: true
description: 'Registry name'
default: 'docker.io'
reg_login:
required: true
description: 'Registry login'
default: 'librebooking'

jobs:
build:
runs-on: ubuntu-latest
env:
REG_NAME: docker.io
REG_LOGIN: librebooking
steps:
-
name: Checkout github repository
Expand All @@ -35,15 +49,23 @@ jobs:
name: Log into registry
uses: docker/login-action@v2
with:
registry: ${{ env.REG_NAME }}
username: ${{ env.REG_LOGIN }}
registry: ${{ inputs.reg_name }}
username: ${{ inputs.reg_login }}
password: ${{ secrets.REGISTRY_TOKEN }}
-
name: Get the docker image metadate
name: Get the docker image metadata
id: get_meta
run: |
echo "APP_TAG=$(basename ${{ inputs.app-gh-ref }})" >> "$GITHUB_OUTPUT"
echo "ACT_TAG=$(basename ${{ github.ref }})" >> "$GITHUB_OUTPUT"
APP_TAG=$(basename ${{ inputs.app-gh-ref }})
ACT_TAG=$(basename ${{ github.ref }})
if [ "${APP_TAG}" \< "2.8.6" ]; then
PHP_VERSION="7"
else
PHP_VERSION="8"
fi
echo "APP_TAG=${APP_TAG}" >> "$GITHUB_OUTPUT"
echo "ACT_TAG=${ACT_TAG}" >> "$GITHUB_OUTPUT"
echo "PHP_VERSION=${PHP_VERSION}" >> "$GITHUB_OUTPUT"
-
name: Set the docker image metadata
id: set_meta
Expand All @@ -61,6 +83,7 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: |
PHP_VERSION=${{ steps.get_meta.outputs.PHP_VERSION }}
APP_GH_REF=${{ inputs.app-gh-ref }}
tags: ${{ steps.set_meta.outputs.tags }}
push: true
7 changes: 4 additions & 3 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ git clone https://github.com/librebooking/docker.git
| Image | On your host |
| Platform | your host architecture |

Run the following commands:
Run the following commands on your host:
```
# Stable release
LB_RELEASE=2.8.6
Expand All @@ -57,7 +57,7 @@ Run the following commands:
| Image | On hub.docker.com |
| Platform | linux/amd64,linux/arm64,linux/arm/v7 |

Run the following commands:
Run the following commands on your host:
```
# Stable release
LB_RELEASE=2.8.6
Expand Down Expand Up @@ -96,5 +96,6 @@ Run the following commands:

1. Create a github secret, called `REGISTRY_TOKEN`, to store your registry personal access token
1. Run the github action `Build and publish docker images` from the latest repository tag
1. Specify the librebooking application github reference (ex: refs/tags/2.8.6)
1. Click on `Run workflow`. Then click on `Branch: develop` and select instead the latest version tag
1. Specify the librebooking application github reference (ex: refs/tags/2.8.6 or refs/heads/develop)
1. Click on the `Run workflow` button
66 changes: 45 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
FROM php:7-apache
ARG PHP_VERSION
FROM php:${PHP_VERSION}-apache

# Copy the entrypoint program
COPY ./entrypoint.sh /usr/local/bin/
# Install composer
COPY --from=composer/composer:latest-bin /composer /usr/bin/composer

# Customize
ARG APP_GH_REF
ENV DEBIAN_FRONTEND=noninteractive

# Update debian packages
RUN set -ex; \
# Update debian packages
apt-get update; \
apt-get upgrade --yes; \
# Install composer
apt-get install --yes --no-install-recommends git unzip; \
# Install mysqli extension for php
apt-get clean; \
rm -rf /var/lib/apt/lists/*

# Customize php environment
RUN set -ex; \
cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
a2enmod rewrite; \
docker-php-ext-install -j$(nproc) mysqli; \
# Install the timezonedb php extension
pecl install timezonedb; \
# Copy librebooking source code
mkdir /usr/src/lb; \
docker-php-ext-enable timezonedb

# Get application and customize
USER www-data
RUN set -ex; \
curl \
--fail \
--silent \
--location https://github.com/LibreBooking/app/archive/${APP_GH_REF}.tar.gz \
| tar --extract --gzip --directory=/usr/src/lb --strip-components=1; \
# Make entrypoint executable
chmod ugo+x /usr/local/bin/entrypoint.sh; \
# Set a php.ini file as recommended by the authors of php:?-apache
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
# Clear apt cache
apt-get clean; \
rm -rf /var/lib/apt/lists/*
| tar --extract --gzip --directory=/var/www/html --strip-components=1; \
if [ -f /var/www/html/composer.json ]; then \
composer install --ignore-platform-req=ext-gd; \
fi; \
sed \
-i /var/www/html/database_schema/create-user.sql \
-e "s:^DROP USER ':DROP USER IF EXISTS ':g" \
-e "s:booked_user:schedule_user:g" \
-e "s:localhost:%:g"; \
if ! [ -d /var/www/html/tpl_c ]; then \
mkdir /var/www/html/tpl_c; \
fi

# Declarations
VOLUME /var/www/html
ENTRYPOINT ["entrypoint.sh"]
CMD ["apache2-foreground"]
# Final customization
USER root
RUN set -ex; \
touch /app.log; \
chown www-data:www-data /app.log; \
mkdir /config

# Labels
LABEL org.opencontainers.image.title="LibreBooking"
Expand All @@ -43,3 +58,12 @@ LABEL org.opencontainers.image.url="https://github.com/librebooking/docker"
LABEL org.opencontainers.image.source="https://github.com/librebooking/docker"
LABEL org.opencontainers.image.licenses="GPL-3.0"
LABEL org.opencontainers.image.authors="robin.alexander@netplus.ch"

# Copy the entrypoint program
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

# Declarations
VOLUME /config
ENTRYPOINT ["entrypoint.sh"]
CMD ["apache2-foreground"]
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
# What is librebooking
[Librebooking](https://github.com/librebooking/app) is a simply powerful scheduling solution for any organization, forked from [Booked](https://www.bookedscheduler.com/).
[Librebooking](https://github.com/librebooking/app) is a simple powerful scheduling solution for any organization, forked from [Booked](https://www.bookedscheduler.com/).

# Project goal
This project implements the librebooking web application as a docker image.

The image contains the apache web server and the librebooking application files. It needs to be linked to a MariaDB database container.

# Upgrade to version 2 of the docker images
Version 1 of the docker images exposed the container directory `/var/www/html`. This resulted in:
- Storing the application files in a docker volume or a local directory on the host
- A complex upgrade procedure
- Longer container startup time

From version 2, the docker images expose the container directory `/config`. This implies:
- To store the application configuration file `config.php` only
- A simple upgrade procedure
- A faster container startup time

Docker images are tagged as follows:

librebooking/librebooking:\<*application-version*\>-\<**docker-image-version**\>

Examples:
- image v1: librebooking/librebooking:2.8.6-`1.2.3`
- image v2: librebooking/librebooking:2.8.6-`2.0`

To upgrade from a version-1 docker image to a version-2 docker image, you just need to:
1. Replace the v1-docker image with the corresponding v2
1. Change the mapping from /var/www/html to `/config`

On first run, all the application files will be moved to the folder `/config/archive` on your host docker volume/host local directory and the file `config.php` will be moved to `/config` on your host docker volume/host local directory. You can delete the `config/archive` folder later on.

# Table of contents
1. [Get or build the docker image](BUILD.md)
1. [Run the docker container](RUN.md)
Expand Down
Loading

0 comments on commit e051283

Please sign in to comment.