A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Updates the utility script to allow building of other Dockerfiles for building any image locally. Adds a single point to configure non-Python versions
Trenton Holmes4517692c202c
diff --git a/.build-config.json b/.build-config.jsonnew file mode 100644index 000000000..32cf968d5--- /dev/null+++ b/.build-config.json@@ -0,0 +1,9 @@+{+ "qpdf": {+ "version": "10.6.3"+ },+ "jbig2enc": {+ "version": "0.29",+ "git_tag": "0.29"+ }+}diff --git a/build-docker-imaage.sh b/build-docker-imaage.shdeleted file mode 100755index 7d097fe06..000000000--- a/build-docker-imaage.sh+++ /dev/null@@ -1,24 +0,0 @@-#!/usr/bin/env bash--# Example Usage: ./build-docker-imaage.sh -t paperless-ngx:my-awesome-feature--set -eux--# Parse what we can from Pipfile.lock-pikepdf_version=$(jq ".default.pikepdf.version" Pipfile.lock | sed 's/=//g' | sed 's/"//g')-psycopg2_version=$(jq ".default.psycopg2.version" Pipfile.lock | sed 's/=//g' | sed 's/"//g')--# Get the branch name-frontend=$(git rev-parse --abbrev-ref HEAD)--# Directly set these-# Future enhancement: Set this in a single location-qpdf_version="10.6.3"-jbig2enc_version="0.29"--docker build . \- --build-arg JBIG2ENC_VERSION="${jbig2enc_version}" \- --build-arg QPDF_VERSION="${qpdf_version}" \- --build-arg PIKEPDF_VERSION="${pikepdf_version}" \- --build-arg PSYCOPG2_VERSION="${psycopg2_version}" \- --build-arg FRONTEND_VERSION="${frontend}" "$@"diff --git a/build-docker-image.sh b/build-docker-image.shnew file mode 100755index 000000000..41c95167c--- /dev/null+++ b/build-docker-image.sh@@ -0,0 +1,35 @@+#!/usr/bin/env bash++# Helper script for building the Docker image locally.+# Parses and provides the nessecary versions of other images to Docker+# before passing in the rest of script args++# First Argument: The Dockerfile to build+# Other Arguments: Additional arguments to docker build++# Example Usage:+# ./build-docker-image.sh Dockerfile -t paperless-ngx:my-awesome-feature+# ./build-docker-image.sh docker-builders/Dockerfile.qpdf -t paperless-ngx-build-qpdf:x.y.z++set -eux++# Parse what we can from Pipfile.lock+pikepdf_version=$(jq ".default.pikepdf.version" Pipfile.lock | sed 's/=//g' | sed 's/"//g')+psycopg2_version=$(jq ".default.psycopg2.version" Pipfile.lock | sed 's/=//g' | sed 's/"//g')+# Read this from the other config file+qpdf_version=$(jq ".qpdf.version" .build-config.json | sed 's/"//g')+jbig2enc_version=$(jq ".jbig2enc.version" .build-config.json | sed 's/"//g')+# Get the branch name+frontend=$(git rev-parse --abbrev-ref HEAD)++if [ ! -f "$1" ]; then+ echo "$1 is not a file, please provide the Dockerfile"+ exit 1+fi++docker build --file "$1" \+ --build-arg JBIG2ENC_VERSION="${jbig2enc_version}" \+ --build-arg QPDF_VERSION="${qpdf_version}" \+ --build-arg PIKEPDF_VERSION="${pikepdf_version}" \+ --build-arg PSYCOPG2_VERSION="${psycopg2_version}" \+ --build-arg FRONTEND_VERSION="${frontend}" "${@:2}" .diff --git a/docker-builders/get-build-json.py b/docker-builders/get-build-json.pyindex 07a33b4d4..4b96ac8d7 100755--- a/docker-builders/get-build-json.py+++ b/docker-builders/get-build-json.py@@ -20,28 +20,6 @@ import osfrom pathlib import Pathfrom typing import Final-CONFIG: Final = {- # All packages need to be in the dict, even if not configured further- # as it is used for the possible choices in the argument- "psycopg2": {},- "frontend": {},- # Most information about Python packages comes from the Pipfile.lock- # Exception being pikepdf, which needs a specific qpdf version- "pikepdf": {- "qpdf_version": "10.6.3",- },- # For other packages, version and Git information are directly configured- # These require manual updates to this file for version updates- "qpdf": {- "version": "10.6.3",- "git_tag": "N/A",- },- "jbig2enc": {- "version": "0.29",- "git_tag": "0.29",- },-}-def _get_image_tag(repo_name: str,@@ -58,47 +36,63 @@ def _main():parser.add_argument("package",help="The name of the package to generate JSON for",- choices=CONFIG.keys(),)- args = parser.parse_args()+ PIPFILE_LOCK_PATH: Final[Path] = Path("Pipfile.lock")+ BUILD_CONFIG_PATH: Final[Path] = Path(".build-config.json")- pip_lock = Path("Pipfile.lock")+ # Read the main config file+ build_json: Final = json.loads(BUILD_CONFIG_PATH.read_text())- repo_name = os.environ["GITHUB_REPOSITORY"]+ # Read Pipfile.lock file+ pipfile_data: Final = json.loads(PIPFILE_LOCK_PATH.read_text())- # The JSON object we'll output- output = {"name": args.package}+ args: Final = parser.parse_args()- # Read Pipfile.lock file- pipfile_data = json.loads(pip_lock.read_text())+ repo_name: Final[str] = os.environ["GITHUB_REPOSITORY"]- # Read the version from Pipfile.lock- if args.package in pipfile_data["default"]:+ # Default output values+ version = None+ git_tag = None+ extra_config = {}+ if args.package == "frontend":+ # Version is just the branch or tag name+ version = os.environ["GITHUB_REF_NAME"]+ elif args.package in pipfile_data["default"]:+ # Read the version from Pipfile.lockpkg_data = pipfile_data["default"][args.package]-pkg_version = pkg_data["version"].split("==")[-1]-- output["version"] = pkg_version+ version = pkg_version# Based on the package, generate the expected Git tag nameif args.package == "pikepdf":- git_tag_name = f"v{pkg_version}"+ git_tag = f"v{pkg_version}"elif args.package == "psycopg2":- git_tag_name = pkg_version.replace(".", "_")+ git_tag = pkg_version.replace(".", "_")- output["git_tag"] = git_tag_name+ # Any extra/special values needed+ if args.package == "pikepdf":+ extra_config["qpdf_version"] = build_json["qpdf"]["version"]- # Use the basic ref name, minus refs/heads or refs/tags for frontend builder image- elif args.package == "frontend":- output["version"] = os.environ["GITHUB_REF_NAME"]+ elif args.package in build_json:+ version = build_json[args.package]["version"]- # Add anything special from the config- output.update(CONFIG[args.package])+ if "git_tag" in build_json[args.package]:+ git_tag = build_json[args.package]["git_tag"]+ else:+ raise NotImplementedError(args.package)- # Based on the package and environment, generate the Docker image tag- output["image_tag"] = _get_image_tag(repo_name, args.package, output["version"])+ # The JSON object we'll output+ output = {+ "name": args.package,+ "version": version,+ "git_tag": git_tag,+ "image_tag": _get_image_tag(repo_name, args.package, version),+ }++ # Add anything special a package may need+ output.update(extra_config)# Output the JSON info to stdoutprint(json.dumps(output))