2021-01-14 01:23:45 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
username="jonaswinkler";
|
|
|
|
reponame="paperless-ng";
|
|
|
|
|
|
|
|
output_dir="${1}";
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
log_msg() {
|
|
|
|
# echo "[github-get-releases] [${SECONDS}] $*" >&2;
|
2021-01-14 21:15:40 +00:00
|
|
|
echo -e "[docker-images/paperless-ng] $*" >&2;
|
2021-01-14 01:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -z "${output_dir}" ]]; then
|
|
|
|
echo "Error: No output directory specified.
|
|
|
|
paperless-ng build script
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
./paperless-ng.sh <path/to/preexisting_output_dir>" >&2;
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d "${output_dir}" ]]; then
|
|
|
|
echo "Error: Output directory doesn't exist." >&2;
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
2021-04-23 19:41:31 +00:00
|
|
|
|
|
|
|
# $1 - Command name to check for
|
|
|
|
check_command() {
|
|
|
|
which $1 >/dev/null 2>&1; exit_code=$?
|
|
|
|
if [[ "${exit_code}" -ne 0 ]]; then
|
|
|
|
log_msg "Error: Couldn't locate $1. Make sure it's installed and in your path.";
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_command mktemp;
|
|
|
|
check_command curl;
|
|
|
|
check_command jq;
|
|
|
|
|
|
|
|
|
2021-01-14 01:23:45 +00:00
|
|
|
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}" .;
|
2021-01-14 21:15:40 +00:00
|
|
|
if [[ "$?" -ne 0 ]]; then
|
|
|
|
log_msg "Error: docker build returned exit status $?";
|
|
|
|
fi
|
2021-01-14 01:23:45 +00:00
|
|
|
|
|
|
|
log_msg "Pushing docker image";
|
|
|
|
docker push "${docker_tag}";
|
|
|
|
|
|
|
|
log_msg "done";
|