init
This commit is contained in:
commit
b9f975dc03
6 files changed
+256
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# Copy this file to .env and adjust as needed.
|
||||
# docker compose automatically reads .env from this directory.
|
||||
|
||||
# Password of the taler-merchant PostgreSQL role.
|
||||
POSTGRES_PASSWORD=taler-merchant
|
||||
|
||||
# Bearer token the frontend (Kivitendo) sends as "Authorization: Bearer ...".
|
||||
# Must start with "secret-token:" (RFC 8959). This default is dev-only!
|
||||
TALER_MERCHANT_TOKEN=secret-token:kivi-dev-only
|
||||
|
||||
# Default currency of the merchant backend.
|
||||
# KUDOS: demonstration currency of https://exchange.demo.taler.net/
|
||||
# CHF: real currency, served by https://exchange.taler-ops.ch/
|
||||
TALER_MERCHANT_CURRENCY=KUDOS
|
||||
@@ -0,0 +1 @@
|
||||
.env
|
||||
@@ -0,0 +1,85 @@
|
||||
# Docker setup: GNU Taler merchant backend
|
||||
|
||||
Reproducible local instance of the [GNU Taler merchant backend](https://docs.taler.net/taler-merchant-manual.html)
|
||||
for testing the Kivitendo integration. It replaces the hand-installed VM setup
|
||||
described in `kivi-taler-integration-design-docs/01a-Setup-and-testing-of-the-merchant-backend.md`.
|
||||
|
||||
## Layout
|
||||
|
||||
```
|
||||
docker/
|
||||
├── docker-compose.yml # merchant backend + PostgreSQL database
|
||||
├── .env.example # environment variables, copy to .env to override
|
||||
└── merchant/
|
||||
├── Dockerfile # builds taler-merchant from the official Debian packages
|
||||
└── entrypoint.sh # renders config, initializes the DB, starts the daemons
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Run all `docker compose` commands from **inside this `docker/` directory** —
|
||||
from the repository root, compose would find the Kivitendo development stack's
|
||||
compose file in the parent directory instead.
|
||||
|
||||
```
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
Once the containers are healthy, the backend is reachable on
|
||||
<http://localhost:9966/> (bound to localhost only, no TLS). A quick check:
|
||||
|
||||
```
|
||||
curl http://localhost:9966/config
|
||||
```
|
||||
|
||||
The web interface (SPA) for configuring instances, bank accounts and access
|
||||
tokens is served at the same URL. On first use, open it and create the `admin`
|
||||
instance, then create an access token under *Settings → Access tokens*. That
|
||||
token (prefixed `secret-token:`) is what Kivitendo sends as
|
||||
`Authorization: Bearer ...`.
|
||||
|
||||
Alternatively, for pure API testing before any instance has been created, the
|
||||
backend accepts the token configured via `TALER_MERCHANT_TOKEN` (see
|
||||
`.env.example`).
|
||||
|
||||
## Configuration
|
||||
|
||||
All configuration is done through environment variables (see `.env.example`):
|
||||
|
||||
| Variable | Default | Purpose |
|
||||
|--------------------------|-------------------------------|------------------------------------------------------|
|
||||
| `POSTGRES_PASSWORD` | `taler-merchant` | Password of the `taler-merchant` PostgreSQL role |
|
||||
| `TALER_MERCHANT_DB` | built from `POSTGRES_PASSWORD`| PostgreSQL connection string for the backend |
|
||||
| `TALER_MERCHANT_TOKEN` | `secret-token:kivi-dev-only` | Bearer token for `/private/` endpoints (dev-only!) |
|
||||
| `TALER_MERCHANT_CURRENCY`| `KUDOS` | Default currency (`KUDOS` = demo, `CHF` = Taler-Operations exchange) |
|
||||
| `TALER_MERCHANT_PORT` | `9966` | TCP port inside the container |
|
||||
|
||||
The merchant image reads the standard Taler configuration files
|
||||
(`/etc/taler-merchant/`), so anything not covered by the variables above can be
|
||||
customized with an additional config include (e.g. mounting
|
||||
`/etc/taler-merchant/merchant-overrides.conf`, which the entrypoint generates
|
||||
from the environment at startup).
|
||||
|
||||
The PostgreSQL data is stored in the named volume `taler-merchant_db-data`.
|
||||
Delete it with `docker compose down -v` to start over with an empty backend.
|
||||
|
||||
## Notes on reproducibility
|
||||
|
||||
- The image installs the official binary packages from
|
||||
`deb.taler.net` on a `debian:trixie-slim` base, following
|
||||
[the manual's installation chapter](https://docs.taler.net/taler-merchant-manual.html#installing-the-gnu-taler-binary-packages-on-debian).
|
||||
- The Taler Systems SA signing key is downloaded from
|
||||
<https://taler.net/taler-systems.gpg> during the build. The manual suggests
|
||||
verifying it out-of-band; for stricter reproducibility the key can be
|
||||
vendored into this directory and `COPY`ed instead.
|
||||
- The base image tag and the `taler-merchant` package version are unpinned.
|
||||
To pin, replace the tag with a digest (`debian:trixie-slim@sha256:...`) and
|
||||
install a fixed version (`apt-get install taler-merchant=<version>`,
|
||||
see `apt-cache madison taler-merchant`).
|
||||
- Verified working state: taler-merchant `1.6.24` on Debian trixie. Note that
|
||||
the current `taler-merchant-dbinit` shells out to `psql`, which is why the
|
||||
image installs `postgresql-client` explicitly.
|
||||
- Orders are served over plain HTTP on localhost. Never expose this container
|
||||
directly to the internet; in production it goes behind a TLS reverse proxy
|
||||
(see the manual's "Secure setup" chapter).
|
||||
@@ -0,0 +1,50 @@
|
||||
# Reproducible GNU Taler merchant backend for local Kivitendo integration
|
||||
# testing. See README.md in this directory for usage.
|
||||
name: taler-merchant
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres:17
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: taler-merchant
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-taler-merchant}
|
||||
POSTGRES_DB: taler-merchant
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
# healthcheck:
|
||||
# test: ["CMD-SHELL", "pg_isready -U taler-merchant -d taler-merchant"]
|
||||
# interval: 5s
|
||||
# timeout: 5s
|
||||
# retries: 10
|
||||
|
||||
merchant:
|
||||
build: ./merchant
|
||||
image: taler-merchant:local
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- db
|
||||
# db:
|
||||
# condition: service_healthy
|
||||
environment:
|
||||
# PostgreSQL connection string for the merchant backend.
|
||||
TALER_MERCHANT_DB: postgres://taler-merchant:${POSTGRES_PASSWORD:-taler-merchant}@db/taler-merchant
|
||||
# Bearer token accepted by /private/ endpoints until an instance is
|
||||
# created with its own token. Must start with "secret-token:".
|
||||
TALER_MERCHANT_TOKEN: ${TALER_MERCHANT_TOKEN:-secret-token:kivi-dev-only}
|
||||
# Default currency. KUDOS works with the Taler demonstration exchange;
|
||||
# use CHF with the Taler-Operations exchange for real payments.
|
||||
TALER_MERCHANT_CURRENCY: ${TALER_MERCHANT_CURRENCY:-KUDOS}
|
||||
ports:
|
||||
# Bind to localhost only: the backend speaks plain HTTP without TLS
|
||||
# and must not be exposed to the network directly.
|
||||
- "127.0.0.1:9966:9966"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:9966/config"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 15s
|
||||
|
||||
volumes:
|
||||
db-data:
|
||||
@@ -0,0 +1,38 @@
|
||||
# GNU Taler merchant backend
|
||||
#
|
||||
# Installation follows the Merchant Backend Operator Manual:
|
||||
# https://docs.taler.net/taler-merchant-manual.html#installing-the-gnu-taler-binary-packages-on-debian
|
||||
#
|
||||
# The packages are built for Debian trixie, so that is the base image.
|
||||
FROM debian:trixie-slim
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Tools needed to import the Taler Systems SA signing key
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Import the Taler Systems SA public package signing key
|
||||
RUN mkdir -p /etc/apt/keyrings \
|
||||
&& wget -O /etc/apt/keyrings/taler-systems.gpg \
|
||||
https://taler.net/taler-systems.gpg
|
||||
|
||||
# Add the GNU Taler package repository and install the merchant backend
|
||||
RUN echo "deb [signed-by=/etc/apt/keyrings/taler-systems.gpg] https://deb.taler.net/apt/debian trixie main" \
|
||||
> /etc/apt/sources.list.d/taler.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
postgresql-client \
|
||||
taler-merchant \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN chmod 0755 /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Default TCP port of taler-merchant-httpd (see [merchant]/PORT)
|
||||
EXPOSE 9966
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
# Entrypoint for the GNU Taler merchant backend container.
|
||||
#
|
||||
# Renders the configuration from environment variables, initializes the
|
||||
# PostgreSQL database schema, and starts the backend HTTP service plus the
|
||||
# auxiliary daemons that the systemd taler-merchant.target would normally
|
||||
# run (see Merchant Backend Operator Manual, section "Launching the backend"):
|
||||
# https://docs.taler.net/taler-merchant-manual.html#launching-the-backend
|
||||
set -eu
|
||||
|
||||
MAIN_CONFIG="/etc/taler-merchant/taler-merchant.conf"
|
||||
OVERRIDES="/etc/taler-merchant/merchant-overrides.conf"
|
||||
|
||||
MERCHANT_PORT="${TALER_MERCHANT_PORT:-9966}"
|
||||
MERCHANT_CURRENCY="${TALER_MERCHANT_CURRENCY:-KUDOS}"
|
||||
DB_CONFIG="${TALER_MERCHANT_DB:-postgres:///taler-merchant}"
|
||||
|
||||
# The Debian package runs the backend as a dedicated user.
|
||||
RUN_USER="$(getent passwd | awk -F: '$1 ~ /^taler-merchant/ {print $1; exit}')"
|
||||
RUN_USER="${RUN_USER:-taler-merchant-httpd}"
|
||||
RUN_GROUP="$(id -gn "$RUN_USER")"
|
||||
|
||||
# Render the package overrides: service address, currency and database.
|
||||
cat > "$OVERRIDES" <<EOF
|
||||
# Generated by the container entrypoint - do not edit.
|
||||
# Configure via the TALER_MERCHANT_* environment variables instead.
|
||||
[merchant]
|
||||
SERVE = tcp
|
||||
PORT = ${MERCHANT_PORT}
|
||||
CURRENCY = ${MERCHANT_CURRENCY}
|
||||
DATABASE = postgres
|
||||
|
||||
[merchantdb-postgres]
|
||||
CONFIG = ${DB_CONFIG}
|
||||
EOF
|
||||
|
||||
# Make sure the shipped main configuration includes the overrides.
|
||||
if ! grep -q "merchant-overrides.conf" "$MAIN_CONFIG"; then
|
||||
printf '@INLINE@ %s\n' "$OVERRIDES" >> "$MAIN_CONFIG"
|
||||
fi
|
||||
|
||||
# Initialize the database schema. Safe to re-run: existing databases are
|
||||
# preserved unless the tool is invoked with -r (which we never do).
|
||||
# Retries because the postgres container may still be starting up.
|
||||
echo "Initializing the merchant database schema..."
|
||||
try=0
|
||||
until setpriv --reuid="$RUN_USER" --regid="$RUN_GROUP" --init-groups \
|
||||
taler-merchant-dbinit -c "$MAIN_CONFIG"; do
|
||||
try=$((try + 1))
|
||||
if [ "$try" -ge 30 ]; then
|
||||
echo "ERROR: could not initialize the merchant database" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " attempt ${try} failed, retrying in 2 s ..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Start the auxiliary daemons (background; normally systemd units).
|
||||
for daemon in webhook wirewatch depositcheck exchangekeyupdate reconciliation kyccheck; do
|
||||
if command -v "taler-merchant-${daemon}" > /dev/null 2>&1; then
|
||||
setpriv --reuid="$RUN_USER" --regid="$RUN_GROUP" --init-groups \
|
||||
"taler-merchant-${daemon}" -c "$MAIN_CONFIG" &
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Starting taler-merchant-httpd on port ${MERCHANT_PORT} ..."
|
||||
exec setpriv --reuid="$RUN_USER" --regid="$RUN_GROUP" --init-groups \
|
||||
taler-merchant-httpd -c "$MAIN_CONFIG" "$@"
|
||||
Reference in new issue
Block a user