mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Updates the utility script to allow building of other Dockerfiles for building any image locally. Adds a single point to configure non-Python versions
This commit is contained in:
		
							
								
								
									
										9
									
								
								.build-config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								.build-config.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| { | ||||
|   "qpdf": { | ||||
|       "version": "10.6.3" | ||||
|     }, | ||||
|   "jbig2enc": { | ||||
|       "version": "0.29", | ||||
|       "git_tag": "0.29" | ||||
|     } | ||||
| } | ||||
| @@ -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}" "$@" | ||||
							
								
								
									
										35
									
								
								build-docker-image.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										35
									
								
								build-docker-image.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -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}" . | ||||
| @@ -20,28 +20,6 @@ import os | ||||
| from pathlib import Path | ||||
| from 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") | ||||
|  | ||||
|     repo_name = os.environ["GITHUB_REPOSITORY"] | ||||
|  | ||||
|     # The JSON object we'll output | ||||
|     output = {"name": args.package} | ||||
|     # Read the main config file | ||||
|     build_json: Final = json.loads(BUILD_CONFIG_PATH.read_text()) | ||||
|  | ||||
|     # Read Pipfile.lock file | ||||
|     pipfile_data = json.loads(pip_lock.read_text()) | ||||
|     pipfile_data: Final = json.loads(PIPFILE_LOCK_PATH.read_text()) | ||||
|  | ||||
|     # Read the version from Pipfile.lock | ||||
|     if args.package in pipfile_data["default"]: | ||||
|     args: Final = parser.parse_args() | ||||
|  | ||||
|     repo_name: Final[str] = os.environ["GITHUB_REPOSITORY"] | ||||
|  | ||||
|     # 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.lock | ||||
|         pkg_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 name | ||||
|         if 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 stdout | ||||
|     print(json.dumps(output)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Trenton Holmes
					Trenton Holmes