Commit ea70e62a authored by ale's avatar ale
Browse files

Add litestream to the container image

parent be9ff3c6
......@@ -4,7 +4,6 @@ RUN cd /src && \
go build -ldflags="-extldflags=-static" -tags "sqlite_omit_load_extension netgo" -o tabacco ./cmd/tabacco && \
strip tabacco
FROM scratch
COPY --from=build /src/tabacco /tabacco
ENTRYPOINT ["/tabacco", "metadb"]
FROM registry.git.autistici.org/ai3/docker/s6-base:master
COPY --from=build /src/tabacco /usr/bin/tabacco
COPY metadb/docker/etc/ /etc/
......@@ -3,6 +3,7 @@ package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
......@@ -77,6 +78,50 @@ func (c *metadbCommand) Execute(ctx context.Context, f *flag.FlagSet, args ...in
return subcommands.ExitSuccess
}
type metadbConfigCommand struct {
configPath string
}
func (c *metadbConfigCommand) Name() string { return "metadb-config" }
func (c *metadbConfigCommand) Synopsis() string { return "print metadb configuration parameters" }
func (c *metadbConfigCommand) Usage() string {
return `metadb-config [<flags>] <param>:
Print metadb configuration parameters, loaded from the configuration file.
The only supported parameter at the moment is "db-uri", the path to the
sqlite3 database.
`
}
func (c *metadbConfigCommand) SetFlags(f *flag.FlagSet) {
f.StringVar(&c.configPath, "config", "/etc/tabacco/metadb.yml", "configuration `file`")
}
func (c *metadbConfigCommand) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
if f.NArg() != 1 {
log.Printf("error: wrong number of arguments")
return subcommands.ExitUsageError
}
config, err := loadMetadbConfig(c.configPath)
if err != nil {
log.Printf("configuration error: %v", err)
return subcommands.ExitFailure
}
switch f.Arg(0) {
case "db-uri":
fmt.Println(config.DBURI)
default:
log.Printf("unknown configuration parameter '%s'", f.Arg(0))
return subcommands.ExitFailure
}
return subcommands.ExitSuccess
}
func init() {
subcommands.Register(&metadbCommand{}, "")
subcommands.Register(&metadbConfigCommand{}, "")
}
#!/bin/sh
# 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)
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
else
# Prevent the litestream service from running.
rm -fr /var/run/s6/etc/services.d/litestream
fi
exit 0
#!/bin/sh
db_path=$(tabacco metadb-config --config=${TABACCO_CONF:-/etc/tabacco/metadb.yml} db-uri)
exec litestream replicate "${db_path}" "${LITESTREAM_URL}"
#!/usr/bin/execlineb -S0
s6-svscanctl -t /var/run/s6/services
#!/bin/sh
exec /usr/bin/tabacco metadb --config=${TABACCO_CONF:-/etc/tabacco/metadb.yml}
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