From 0aac8436a5dcd0dd8e1fc3cf26e48fb6a4206541 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 14 Jan 2021 01:23:45 +0000 Subject: [PATCH] paperless-ng: rewrite as base-nopush, using the official GH release assets --- imagebuilder.sh | 1 + images/paperless-ng/paperless-ng.sh | 82 +++++++++++++++++++++++++++++ images/paperless-ng/type.txt | 1 + 3 files changed, 84 insertions(+) create mode 100755 images/paperless-ng/paperless-ng.sh create mode 100644 images/paperless-ng/type.txt diff --git a/imagebuilder.sh b/imagebuilder.sh index 34d8bac..b8c5c4a 100755 --- a/imagebuilder.sh +++ b/imagebuilder.sh @@ -9,6 +9,7 @@ fi lantern_path="${repo_root}/lantern-build-engine"; IMAGEBUILDER_REGISTRY="${IMAGEBUILDER_REGISTRY:-registry.service.mooncarrot.space:5000}"; +export IMAGEBUILDER_REGISTRY; ############################################################################### diff --git a/images/paperless-ng/paperless-ng.sh b/images/paperless-ng/paperless-ng.sh new file mode 100755 index 0000000..c46af68 --- /dev/null +++ b/images/paperless-ng/paperless-ng.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +username="jonaswinkler"; +reponame="paperless-ng"; + +output_dir="${1}"; + +############################################################################### + +log_msg() { + # echo "[github-get-releases] [${SECONDS}] $*" >&2; + echo "[docker-images/paperless-ng] $*" >&2; +} + +if [[ -z "${output_dir}" ]]; then + echo "Error: No output directory specified. +paperless-ng build script + +Usage: + ./paperless-ng.sh " >&2; + exit 0; +fi + +if [[ ! -d "${output_dir}" ]]; then + echo "Error: Output directory doesn't exist." >&2; + exit 1; +fi + +temp_dir="$(mktemp --tmpdir -d "docker-images-paperless-ng-XXXXXXX")"; +on_exit() { + log_msg "Cleaning up"; + rm -rf "${temp_dir}"; + log_msg "Cleanup complete"; +} +trap on_exit EXIT; + +cd "${temp_dir}" || { echo "Failed to cd to temp dir"; exit 1; }; + +############################################################################### + +### +# Step 1: Download and extract GitHub asset +### + +release_json_url="https://api.github.com/repos/${username}/${reponame}/releases?per_page=1"; +asset_urls="$(curl -sSL "${release_json_url}" | jq --raw-output '.[0].assets[] | [.name, .browser_download_url] | @tsv')"; + +while read -r filename url; do + if [[ "${filename}" == *"docker"* ]]; then + log_msg "Skipping docker compose definitions"; + continue; + fi + + download_loc="paperless.tar.xz"; + curl -sSL -o "${download_loc}" "${url}"; + + tar -xf "${download_loc}"; + rm "${download_loc}"; + + cd "paperless-ng" || { echo "Failed to cd into extracted paperless-ng directory"; exit 1; }; + + break; +done < <(echo "${asset_urls}"); + +############################################################################### + +### +# Step 2: Build and push the docker image +### + +# Note to self: All settings are environment variables, which are specified in +# the Nomad jobspec file + +docker_tag="${IMAGEBUILDER_REGISTRY}/paperless-ng"; + +log_msg "Building docker image"; +docker build --no-cache --pull --tag "${docker_tag}" .; + +log_msg "Pushing docker image"; +docker push "${docker_tag}"; + +log_msg "done"; diff --git a/images/paperless-ng/type.txt b/images/paperless-ng/type.txt new file mode 100644 index 0000000..ac9c52f --- /dev/null +++ b/images/paperless-ng/type.txt @@ -0,0 +1 @@ +base-nopush