82 lines
2 KiB
Bash
Executable file
82 lines
2 KiB
Bash
Executable file
#!/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 <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
|
|
|
|
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";
|