Skip to content

Commit

Permalink
chore: extend version endpoint with build timestamp and chromium version
Browse files Browse the repository at this point in the history
Refs: #74
  • Loading branch information
grigoriev committed Sep 23, 2024
1 parent c850eb0 commit 5d59d25
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
FROM python:3.12.5-slim@sha256:59c7332a4a24373861c4a5f0eec2c92b87e3efeb8ddef011744ef9a751b1d11c
LABEL maintainer="SBB Polarion Team <[email protected]>"

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 && \
apt-get clean autoclean && \
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
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion app/WeasyprintController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}


Expand Down
8 changes: 7 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 &
Expand Down

0 comments on commit 5d59d25

Please sign in to comment.