From 25181f2839687459c727608811d08404df96489d Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont (@ardumont)" <ardumont@softwareheritage.org> Date: Fri, 30 Aug 2024 09:21:43 +0200 Subject: [PATCH] Add provenance image Refs. swh/infra/sysadm-environment#5398 --- apps/swh-provenance/Dockerfile | 33 +++++++++++++++++++++++++ apps/swh-provenance/entrypoint.sh | 37 ++++++++++++++++++++++++++++ apps/swh-provenance/requirements.txt | 2 ++ 3 files changed, 72 insertions(+) create mode 100644 apps/swh-provenance/Dockerfile create mode 100755 apps/swh-provenance/entrypoint.sh create mode 100644 apps/swh-provenance/requirements.txt diff --git a/apps/swh-provenance/Dockerfile b/apps/swh-provenance/Dockerfile new file mode 100644 index 00000000..3e21876e --- /dev/null +++ b/apps/swh-provenance/Dockerfile @@ -0,0 +1,33 @@ +FROM python:3.10-bullseye +ARG UID=1000 +ARG GID=1000 +RUN apt-get -y update && \ + apt-get -y upgrade && \ + apt-get install -y libcmph-dev librdkafka-dev && \ + apt clean && \ + addgroup --gid $GID swh && \ + useradd --gid $GID --uid $UID -m -d /opt/swh swh && \ + mkdir /etc/swh + +USER swh +WORKDIR /opt/swh + +COPY --chown=swh:swh requirements-frozen.txt /opt/swh +COPY --chown=swh:swh entrypoint.sh /opt/swh + +ENV PYTHONPATH=/opt/swh +ENV PATH=/opt/swh/.local/bin:$PATH + +RUN chmod u+x /opt/swh/entrypoint.sh && \ + /usr/local/bin/python -m pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements-frozen.txt && \ + pip install gunicorn + +ENV SWH_CONFIG_FILENAME=/etc/swh/config.yml +ENV PORT 5014 +EXPOSE $PORT +ENV WORKERS 8 +ENV THREADS 2 +ENV TIMEOUT 3600 + +ENTRYPOINT ["/opt/swh/entrypoint.sh"] diff --git a/apps/swh-provenance/entrypoint.sh b/apps/swh-provenance/entrypoint.sh new file mode 100755 index 00000000..14b2a920 --- /dev/null +++ b/apps/swh-provenance/entrypoint.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -e + +case "$1" in + "shell") + shift + if (( $# == 0)); then + exec bash -i + else + "$@" + fi + ;; + "swh") + shift + echo "Running swh command $@" + exec swh $@ + ;; + *) + EXTRA_CLI_FLAGS="" + if [ ! -z "${SWH_LOG_CONFIG_JSON}" ]; then + EXTRA_CLI_FLAGS="--log-config-json ${SWH_LOG_CONFIG_JSON}" + fi + echo Starting the swh-provenance RPC server + exec gunicorn --bind 0.0.0.0:${PORT} \ + --log-level ${SWH_LOG_LEVEL:-INFO} \ + $EXTRA_CLI_FLAGS \ + --threads ${THREADS} \ + --workers ${WORKERS} \ + --timeout ${TIMEOUT} \ + --reload \ + --statsd-host=${STATSD_HOST}:${STATSD_PORT} \ + --statsd-prefix=${STATSD_SERVICE_TYPE} \ + --config 'python:swh.core.api.gunicorn_config' \ + 'swh.provenance.api.server:make_app_from_configfile()' + ;; +esac diff --git a/apps/swh-provenance/requirements.txt b/apps/swh-provenance/requirements.txt new file mode 100644 index 00000000..8318decb --- /dev/null +++ b/apps/swh-provenance/requirements.txt @@ -0,0 +1,2 @@ +swh.provenance +python-json-logger -- GitLab