diff --git a/Dockerfile b/Dockerfile index 750e14c..3eb5d8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.12.5-slim@sha256:59c7332a4a24373861c4a5f0eec2c92b87e3efeb8ddef011744ef9a751b1d11c LABEL maintainer="SBB Polarion Team " -ARG APP_IMAGE_VERSION +ARG APP_IMAGE_VERSION=0.0.0-dev RUN apt-get update && \ apt-get --yes --no-install-recommends install chromium dbus fonts-dejavu fonts-liberation libpango-1.0-0 libpangoft2-1.0-0 python3-brotli python3-cffi vim && \ @@ -9,12 +9,15 @@ RUN apt-get update && \ apt-get --yes autoremove && \ rm -rf /var/lib/apt/lists/* -ENV WORKING_DIR=/opt/weasyprint -ENV CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium -ENV WEASYPRINT_SERVICE_VERSION=$APP_IMAGE_VERSION +ENV WORKING_DIR="/opt/weasyprint" +ENV CHROMIUM_EXECUTABLE_PATH="/usr/bin/chromium" +ENV WEASYPRINT_SERVICE_VERSION=${APP_IMAGE_VERSION} WORKDIR ${WORKING_DIR} +RUN BUILD_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") && \ + echo ${BUILD_TIMESTAMP} > "${WORKING_DIR}/.build_timestamp" + COPY requirements.txt ${WORKING_DIR}/requirements.txt RUN pip install --no-cache-dir -r ${WORKING_DIR}/requirements.txt diff --git a/README.md b/README.md index 7c3a991..0503fd6 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ To build the Docker image from the source with a custom version, use: ```bash docker build \ - --build-arg APP_IMAGE_VERSION=0.0.0 \ + --build-arg APP_IMAGE_VERSION=0.0.0-dev \ --file Dockerfile \ - --tag weasyprint-service:0.0.0-test . + --tag weasyprint-service:0.0.0-dev . ``` Replace 0.0.0 with the desired version number. @@ -63,7 +63,7 @@ To start the Docker container with your custom-built image: docker run --detach \ --publish 9080:9080 \ --name weasyprint-service \ - weasyprint-service:0.0.0-test + weasyprint-service:0.0.0-dev ``` ### Stopping the Container @@ -89,9 +89,9 @@ Weasyprint Service provides the following endpoints: ##### Responses -> | HTTP code | Content-Type | Response | -> |-----------|--------------------|-------------------------------------------| -> | `200` | `application/json` | `{"python":"3.12.3","weasyprint":"61.2"}` | +> | HTTP code | Content-Type | Response | +> |-----------|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------| +> | `200` | `application/json` | `{ "chromium": "129.0.6668.58", "python": "3.12.5", "timestamp": "2024-09-23T12:23:09Z", "weasyprint": "62.3", "weasyprintService": "0.0.0-dev" }` | ##### Example cURL diff --git a/app/WeasyprintController.py b/app/WeasyprintController.py index 40d072d..9477c55 100644 --- a/app/WeasyprintController.py +++ b/app/WeasyprintController.py @@ -17,7 +17,9 @@ def version(): return { "python": platform.python_version(), "weasyprint": weasyprint.__version__, - "weasyprintService": os.environ.get('WEASYPRINT_SERVICE_VERSION') + "weasyprintService": os.environ.get('WEASYPRINT_SERVICE_VERSION'), + "timestamp": os.environ.get('WEASYPRINT_SERVICE_BUILD_TIMESTAMP'), + "chromium": os.environ.get('WEASYPRINT_SERVICE_CHROMIUM_VERSION'), } diff --git a/entrypoint.sh b/entrypoint.sh index cc5247c..d6c137e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,12 +1,18 @@ #!/bin/bash +BUILD_TIMESTAMP="$(cat /opt/weasyprint/.build_timestamp)" +export WEASYPRINT_SERVICE_BUILD_TIMESTAMP=${BUILD_TIMESTAMP} +CHROMIUM_VERSION="$(${CHROMIUM_EXECUTABLE_PATH} --version | awk '{print $2}')" +export WEASYPRINT_SERVICE_CHROMIUM_VERSION=${CHROMIUM_VERSION} + if ! pgrep -x 'dbus-daemon' > /dev/null; then if [ -f /run/dbus/pid ]; then rm /run/dbus/pid fi dbus_session_bus_address_filename="/tmp/dbus_session_bus_address"; dbus-daemon --system --fork --print-address > ${dbus_session_bus_address_filename}; - export DBUS_SESSION_BUS_ADDRESS=$(cat ${dbus_session_bus_address_filename}) + BUS_ADDRESS=$(cat ${dbus_session_bus_address_filename}); + export DBUS_SESSION_BUS_ADDRESS=${BUS_ADDRESS}; fi python app/WeasyprintServiceApplication.py &