-
Notifications
You must be signed in to change notification settings - Fork 106
Add coreutils and jq pkgs #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Going by #144 - I'm wondering if the image is getting a bit bloated with extra packages as is. Might it be worthwhile just adding a new section to the entrypoint script for additional packages as a variable seeing as the Borgmatic container wouldn't be restarted all that often? Something as simple as: #!/bin/bash
# current entrypoint script
...
# /current entrypoint script
# Install extra packages if set
if [ -v EXTRA_PKGS ]
then
echo -e "\nInstalling extra packages..."
echo -e "Packages chosen: $EXTRA_PKGS\n"
apk add -v $EXTRA_PKGS
echo -e "Packages installed\n"
fi With a compose file such as: environment:
CRON: $BORG_CRON
CRON_COMMAND: $BORG_CRON_COMMAND
EXTRA_PKGS: "coreutils jq" Will give us the following during container startup if the variable is met:
Otherwise, if the variable is null (not set or empty) then we just get:
This way, any additional packages people wish to install to expand their experience using the container can be satisfied at container startup, without having to change how things are for everyone else + bloat the container for 7 million* people (* not actually 7 million, but just going by docker pulls), as well as allow for quick addition/removal of packages if people wish. We're already doing a similar thing with the proposed Cron settings in #150 - I'm happy to add it either as part of or as a separate pull request on top of it once it gets merged? |
Yes (and no). Trivial things first: I generally would be okay with this option but then the image is not fully idempotent (as long as you don't specify the exact version of the pkg). The next problem could be that often containers cant access the internet directly (only through HTTP-Proxy or even dont have any access). So in my op: Dont implement this solution. But ... we could think about init-scripts. if [ -e /init.d ]; then
for i in /init.d/*.sh ; do
/init.d/$i
done
fi With this hack ppl could do arbitrary stuff when the container starts ie apk add --no-cache jq coreutils
wget http://.../prom_exporter.sh or wget -o /etc/borgmatic.d/config.yaml http://[email protected]/.../borg_config.yaml or ... whatever? |
@psi-4ward Remember that Alpine works slightly different than other distributions such as Ubuntu where each OS release only contains a single "latest" version of a package, so it'd update whenever the base image is updated to the latest version of Alpine. E.g. If I'm on If I try to install any other version, it will not work.
In regard to specialised environments such as via VPN, air gapped etc, things get more complicated and catering to all solutions is entering a world of hurt, especially with additional file dependencies etc, and as such, I would argue those requirements really should spin off a fork for their specific requirements. There are all manners of ways of implementing highly complex customisations, waitforit scripts etc, but I would argue the scope of this project is relatively limited to Borgmatic and directly supporting packages, so a simple "if defined, then add, otherwise, don't" would probably be all that would be viable in our current scope. The other issue is support. Once we start adding additional features as part of the main package, we're also having to support different configurations if they go wrong, and we're not a large team. On another (non-Borgmatic) note, if you want a quick pre-setup Dev environment - I've got a project to spin up one quickly that you can call from something like Windows Terminal: https://github.com/modem7/docker-devenv (although if you just need basic things, then a simple |
agree, one who would use this should fork the image and very likely already has an internal registry. So how to arrange with this? Probably including the borgmatic prometheus exporter script would be a nice feature for others and we close this issue and look if we bundle the exporter?
leave as it is would be also OK for me and I'll create fork |
What about just using the existing image as base to build from an individual Dockerfile? When it comes to Prometheus, I have used grep 😉
|
Yes possible but I thought adding only some few MBs would be okay ^^ #!/bin/bash
set -eu -o pipefail
# Default values for BORGMATIC_BIN and BORGMATIC_CONF env-vars
BORGMATIC_BIN=${BORGMATIC_BIN:-/usr/local/bin/borgmatic}
BORGMATIC_CONF=${BORGMATIC_CONF:-/etc/borgmatic.d/config.yml}
# We need jq to parse borg output
if ! command -v jq &> /dev/null; then
>&2 echo "ERROR: jq executable could not be found."
exit 1
fi
if ! command -v $BORGMATIC_BIN &> /dev/null; then
>&2 echo "ERROR: $BORGMATIC_BIN executable could not be found."
exit 1
fi
BORGMATIC="$BORGMATIC_BIN -nc -c $BORGMATIC_CONF"
BORG_LIST="$($BORGMATIC list --json)"
if [ $(echo "$BORG_LIST" | jq -r '. | length') -gt 1 ]; then
# TODO: We could easily loop through all configured repos.
>&2 echo "ERROR: This borgmatic exporter supports only one repository."
exit 1
fi
REPO_ARCHIVES="$(echo "$BORG_LIST" | jq -r '.[0].archives | length')"
REPOSITORY=$(echo "$BORG_LIST" | jq -r '.[0].repository.location')
BACKUP_TARGET=$(echo ${REPOSITORY//ssh:\/\//} | cut -d/ -f1)
LABELS="{host=\"$(hostname)\",repository=\"${REPOSITORY}\",backup_target=\"${BACKUP_TARGET}\"}"
BORG_INFO=$($BORGMATIC info --last 1 --json)
REPO_SIZE=$(echo "$BORG_INFO" | jq -r '.[0].cache.stats.total_size')
REPO_COMPRESSED_SIZE=$(echo "$BORG_INFO" | jq -r '.[0].cache.stats.total_csize')
REPO_DEDUPLICATED_SIZE=$(echo "$BORG_INFO" | jq -r '.[0].cache.stats.unique_csize')
REPO_CHUNKS=$(echo "$BORG_INFO" | jq -r '.[0].cache.stats.total_chunks')
REPO_UNIQUE_CHUNKS=$(echo "$BORG_INFO" | jq -r '.[0].cache.stats.total_unique_chunks')
LAST_ARCHIVE_DATE=$(echo "$BORG_INFO" | jq -r '.[0].archives[0].end')
LAST_ARCHIVE_TIMESTAMP=$(date -u -d "$LAST_ARCHIVE_DATE" +%s)
LAST_ARCHIVE_FILES=$(echo "$BORG_INFO" | jq -r '.[0].archives[0].stats.nfiles')
LAST_ARCHIVE_ORIGINAL_SIZE=$(echo "$BORG_INFO" | jq -r '.[0].archives[0].stats.original_size')
LAST_ARCHIVE_DEDUPLICATED_SIZE=$(echo "$BORG_INFO" | jq -r '.[0].archives[0].stats.deduplicated_size')
LAST_ARCHIVE_COMPRESSED_SIZE=$(echo "$BORG_INFO" | jq -r '.[0].archives[0].stats.compressed_size')
LAST_ARCHIVE_DURATION=$(echo "$BORG_INFO" | jq -r '.[0].archives[0].duration' | cut -d. -f1)
echo "# HELP borg_repo_archives Number of archives in this repository"
echo "# TYPE borg_repo_archives gauge"
echo "borg_repo_archives${LABELS} ${REPO_ARCHIVES}"
echo "# HELP borg_repo_size_bytes Size of the repository in bytes"
echo "# TYPE borg_repo_size_bytes gauge"
echo "borg_repo_size_bytes${LABELS} ${REPO_SIZE}"
echo "# HELP borg_repo_compressed_size_bytes Compressed size of the repository in bytes"
echo "# TYPE borg_repo_compressed_size_bytes gauge"
echo "borg_repo_compressed_size_bytes${LABELS} ${REPO_COMPRESSED_SIZE}"
echo "# HELP borg_repo_deduplicated_size_bytes Deduplicated size of the repository in bytes"
echo "# TYPE borg_repo_deduplicated_size_bytes gauge"
echo "borg_repo_deduplicated_size_bytes${LABELS} ${REPO_DEDUPLICATED_SIZE}"
echo "# HELP borg_repo_chunks Total number of chunks in the repository"
echo "# TYPE borg_repo_chunks gauge"
echo "borg_repo_chunks${LABELS} ${REPO_CHUNKS}"
echo "# HELP borg_repo_unique_chunks Number of unique chunks in the repository"
echo "# TYPE borg_repo_unique_chunks gauge"
echo "borg_repo_unique_chunks${LABELS} ${REPO_UNIQUE_CHUNKS}"
echo "# HELP borg_last_archive_timestamp Timestamp of the most recent archive"
echo "# TYPE borg_last_archive_timestamp gauge"
echo "borg_last_archive_timestamp${LABELS} $LAST_ARCHIVE_TIMESTAMP"
echo "# HELP borg_last_archive_files Number of files of the most recent archive"
echo "# TYPE borg_last_archive_files gauge"
echo "borg_last_archive_files${LABELS} ${LAST_ARCHIVE_FILES}"
echo "# HELP borg_last_archive_size_bytes Original size of of the most recent archive"
echo "# TYPE borg_last_archive_size_bytes gauge"
echo "borg_last_archive_size_bytes${LABELS} ${LAST_ARCHIVE_ORIGINAL_SIZE}"
echo "# HELP borg_last_archive_deduplicated_size_bytes Deduplicated size of of the most recent archive"
echo "# TYPE borg_last_archive_deduplicated_size_bytes gauge"
echo "borg_last_archive_deduplicated_size_bytes${LABELS} ${LAST_ARCHIVE_DEDUPLICATED_SIZE}"
echo "# HELP borg_last_archive_compressed_size_bytes Compressed size of of the most recent archive"
echo "# TYPE borg_last_archive_compressed_size_bytes gauge"
echo "borg_last_archive_compressed_size_bytes${LABELS} ${LAST_ARCHIVE_COMPRESSED_SIZE}"
echo "# HELP borg_last_archive_duration_seconds Create duration of the most recent backup"
echo "# TYPE borg_last_archive_duration_seconds gauge"
echo "borg_last_archive_duration_seconds${LABELS} ${LAST_ARCHIVE_DURATION}" |
Whilst it is only a few mb extra the issue is where does it end, I'm not saying yes or no here just trying to draw the line of which additional packages are added. What specific tool from Whilst in the past I've used images where you can add $EXTRA_PKGS or run arbitrary scripts on init this opens a new can of worms. I would say |
Cut |
I think the $EXTRA_PKGS feature will be something we'd look to implement in the extended image when ready |
Request: Add coreutils and jq to the container. It adds only about 2,16 MB.
Motivation: More flexibility when executing scripts (ie hooks) inside the container.
In my case I've written simple
backup-space_exporter.sh
andborg_exporter.sh
which provide some Prometheus metrics.Could also be useful when working with docker-api.
The text was updated successfully, but these errors were encountered: