Commit 40b21a0b authored by ale's avatar ale
Browse files

Install litestream in the container image

parent ea70e62a
Pipeline #24157 passed with stages
in 5 minutes and 22 seconds
......@@ -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/
......@@ -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.
......
#!/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}"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment