diff --git a/Dockerfile b/Dockerfile index 6960fb1d740605872dd384e118533744a48d232e..f31b9ddff7fdf7351c27bf8d0e7c8c4ff78c2b1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,12 @@ RUN cd /src && \ go build -ldflags="-extldflags=-static" -tags "sqlite_omit_load_extension netgo" -o tabacco ./cmd/tabacco && \ strip tabacco +FROM debian:stable-slim AS litestream-dl +ENV LITESTREAM_VERSION=0.3.6 +ADD https://github.com/benbjohnson/litestream/releases/download/v${LITESTREAM_VERSION}/litestream-v${LITESTREAM_VERSION}-linux-amd64-static.tar.gz /tmp/ +RUN tar -C /usr/bin -xzv -f /tmp/litestream-v${LITESTREAM_VERSION}-linux-amd64-static.tar.gz && chmod 755 /usr/bin/litestream + FROM registry.git.autistici.org/ai3/docker/s6-base:master COPY --from=build /src/tabacco /usr/bin/tabacco +COPY --from=litestream-dl /usr/bin/litestream /usr/bin/litestream COPY metadb/docker/etc/ /etc/ diff --git a/metadb/docker/etc/cont-init.d/10litestream b/metadb/docker/etc/cont-init.d/10litestream index b62f958bad57e3d6933a1562ac2bdb37e406e4fb..6c18933e4fe4098c4801f78236b92bf7dd66e8e7 100755 --- a/metadb/docker/etc/cont-init.d/10litestream +++ b/metadb/docker/etc/cont-init.d/10litestream @@ -3,18 +3,22 @@ # Should we even run litestream? if [ -n "${LITESTREAM_URL}" ]; then - # Query the tabacco configuration to obtain the database path. - db_path=$(tabacco metadb-config --config=${TABACCO_CONF:-/etc/tabacco/metadb.yml} db-uri) + # Query the tabacco configuration to obtain the database path. + db_path=$(tabacco metadb-config --config=${TABACCO_CONF:-/etc/tabacco/metadb.yml} db-uri) + if [ -z "${db_path}" ]; then + echo "Error reading db-uri from tabacco" >&2 + exit 1 + fi - if [ ! -e "${db_path}" ]; then - echo "Database is missing, attempting restore..." >&2 + if [ ! -e "${db_path}" ]; then + echo "Database is missing, attempting restore..." >&2 - litestream restore --if-replica-exists -o "${db_path}" "${LITESTREAM_URL}" - if [ $? -gt 0 ]; then - echo "Restore failed!" >&2 - exit 1 - fi - fi + litestream restore --if-replica-exists -o "${db_path}" "${LITESTREAM_URL}" + if [ $? -gt 0 ]; then + echo "Restore failed!" >&2 + exit 1 + fi + fi else # Prevent the litestream service from running. diff --git a/metadb/docker/etc/services.d/litestream/run b/metadb/docker/etc/services.d/litestream/run index 885840e00548fb6965ec390d3677456aa883a9e1..5d19f05bd88c4d5198b00bb133179befd8a7eb98 100755 --- a/metadb/docker/etc/services.d/litestream/run +++ b/metadb/docker/etc/services.d/litestream/run @@ -1,5 +1,10 @@ #!/bin/sh db_path=$(tabacco metadb-config --config=${TABACCO_CONF:-/etc/tabacco/metadb.yml} db-uri) +if [ -z "${db_path}" ]; then + echo "Error reading db-uri from tabacco" >&2 + sleep 3 + exit 1 +fi exec litestream replicate "${db_path}" "${LITESTREAM_URL}"