-
Notifications
You must be signed in to change notification settings - Fork 1
feat(packaging): Add local packaging workflow with caching. #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3e01ce0
feat(packaging): Add cached local package builds
2a7d768
fix(packaging): Use POSIX cp -f instead of GNU --remove-destination
jackluo923 0881086
docs(packaging): Keep CI artifact reference alongside local build path
jackluo923 524be08
docs(packaging): Trim build-cache README
jackluo923 681a345
feat(packaging): Run local package builds as the host user with cache…
d79bb83
revert(packaging): Drop cosmetic-only reformats from the host-user port
344e37c
refactor(packaging): Move local container setup into build-artifacts.sh
8f24502
docs(packaging): Clarify env contract between build-packages.sh and b…
ad63380
fix(packaging): Use shasum fallback for build-env hash on macOS
d0b24dd
feat(packaging): Add 'task package' wrapper for build-packages.sh
43cf513
docs(packaging): Mention 'task package' in local usage, keep script a…
29c97ce
docs(packaging): Remove build-cache README
jackluo923 f28f5ef
build(packaging): Validate buildx and quote script path in 'task pack…
jackluo923 882ce7b
docs(packaging): Document .cache/build/<hash>/ and distinguish from r…
jackluo923 323378c
docs(packaging): Correct container UID/GID guidance in README
jackluo923 d4a3f42
refactor(taskfile): Use {{.VAR | default}} idiom for env-sourced buil…
jackluo923 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| .git | ||
| .task | ||
| .cache | ||
| build | ||
| **/target | ||
| packages | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /.task/ | ||
| /.cache/ | ||
| /build/ | ||
| /packages/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # User-facing entry point for packaging. Resolves the build-env image, then runs | ||
| # internal/container/build-artifacts.sh inside it. | ||
| # | ||
| # Requires: docker (with buildx), git, and sha256sum or shasum. | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| src="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &>/dev/null && pwd)" | ||
| # shellcheck source=tools/build-packages/internal/build-cache/host.sh | ||
| source "${src}/tools/build-packages/internal/build-cache/host.sh" | ||
|
|
||
| show_help() { | ||
| cat <<'EOF' | ||
| Usage: ./tools/build-packages/build-packages.sh [OPTIONS] | ||
|
|
||
| User-facing entry point for packaging. Resolves the build-env image, then runs | ||
| internal/container/build-artifacts.sh inside it. | ||
|
|
||
| Options are forwarded to internal/container/build-artifacts.sh: | ||
| --output DIR Output directory for built packages (default: ./packages) | ||
| --version VER Override package version | ||
| (default: derived from presto-connector/pom.xml) | ||
| VER must start with a digit and use [0-9A-Za-z.+~-] | ||
| --help Show this help | ||
|
|
||
| See tools/build-packages/README.md for details. | ||
| EOF | ||
| } | ||
|
|
||
| # Resolve the output directory on the host before copying completed artifacts | ||
| # into it. Other arguments are forwarded unchanged to build-artifacts.sh. | ||
| output_dir="${src}/packages" | ||
| build_args=() | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| --output) | ||
| [[ -n "${2:-}" ]] || { echo >&2 "ERROR: --output requires a value"; exit 1; } | ||
| output_dir="$2" | ||
| shift 2 | ||
| ;; | ||
| --help) | ||
| show_help | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| build_args+=("$1") | ||
| shift | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # Run the wrapper as the intended artifact owner. Using sudo would make the | ||
| # staging directories and copied artifacts root-owned. | ||
| if (( EUID == 0 )); then | ||
| echo >&2 "ERROR: build-packages.sh must run as a non-root user; do not invoke it with sudo." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "${output_dir}" != /* ]]; then | ||
| output_dir="${src}/${output_dir}" | ||
| fi | ||
| mkdir -p "${output_dir}" | ||
| output_dir="$(cd "${output_dir}" && pwd)" | ||
|
|
||
| # Initialize submodules on the host so the source tree is complete before it is | ||
| # bind-mounted into the build container. | ||
| echo "==> Initializing submodules..." | ||
| git -C "${src}" submodule update --init --recursive | ||
|
|
||
| echo "==> Resolving build-env image..." | ||
| image=$("${src}/tools/build-packages/build-dependency-image.sh") | ||
| # FetchContent build state is compatible only with the image inputs identified | ||
| # by this hash. | ||
| image_hash="${image##*:env-}" | ||
| if [[ "${image_hash}" == "${image}" ]]; then | ||
| echo >&2 "ERROR: build-env image lacks an env-<hash> tag: ${image}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Keep container output in temporary staging, then copy it to the requested | ||
| # directory after the build succeeds. | ||
| stage_dir=$(mktemp -d) | ||
| trap 'rm -rf "${stage_dir}"' EXIT | ||
| artifact_stage="${stage_dir}/artifacts" | ||
| mkdir -p "${artifact_stage}" | ||
| prepare_build_cache "${src}/.cache" "${image_hash}" | ||
| host_uid=$(id -u) | ||
| host_gid=$(id -g) | ||
|
|
||
| # Run as the host user so staged files and artifacts aren't root-owned. Bind the | ||
| # repo at a stable /repo path so cached CMake state doesn't embed the host | ||
| # checkout path. The --env flags below wire the build cache and point HOME / | ||
| # TASK_TEMP_DIR at disposable in-container scratch (the non-root user can't | ||
| # write to the image's defaults); build-artifacts.sh activates that setup only | ||
| # when BUILD_CACHE_DIR is present, so CI (which calls it directly) is unaffected. | ||
| echo "==> Running internal/container/build-artifacts.sh inside ${image}..." | ||
| docker run --rm \ | ||
| --user "${host_uid}:${host_gid}" \ | ||
| --mount "type=bind,src=${src},dst=/repo" \ | ||
| --mount "type=bind,src=${artifact_stage},dst=/output" \ | ||
| --env "BUILD_CACHE_KEY=${image_hash}" \ | ||
| --env "BUILD_CACHE_DIR=/repo/.cache" \ | ||
| --env "CLP_PLUGIN_BUILD_DIR=/repo/.cache/build/${image_hash}" \ | ||
| --env "HOME=/tmp/clp-plugin-presto-connector-home" \ | ||
| --env "TASK_TEMP_DIR=/tmp/clp-plugin-presto-connector-task" \ | ||
| -w /repo \ | ||
| "${image}" \ | ||
| bash /repo/tools/build-packages/internal/container/build-artifacts.sh \ | ||
| --output /output ${build_args[@]+"${build_args[@]}"} | ||
|
|
||
| echo "==> Copying package artifacts to ${output_dir}..." | ||
| # Fail clearly when the build produced no artifacts, instead of passing a | ||
| # literal '*' to cp (which happens when the glob has no matches). | ||
| if ! compgen -G "${artifact_stage}/*" > /dev/null; then | ||
| echo >&2 "ERROR: no package artifacts were produced under ${artifact_stage}" | ||
| exit 1 | ||
| fi | ||
| cp -f "${artifact_stage}"/* "${output_dir}/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| # Container-side configuration for consuming a prepared build cache. | ||
|
|
||
| if [ -n "${BUILD_CACHE_DIR:-}" ]; then | ||
| if [ -z "${BUILD_CACHE_KEY:-}" ]; then | ||
| echo >&2 "ERROR: BUILD_CACHE_KEY must be set when BUILD_CACHE_DIR is set" | ||
| return 1 | ||
| fi | ||
|
|
||
| export CCACHE_DIR="${CCACHE_DIR:-${BUILD_CACHE_DIR}/ccache}" | ||
| export CCACHE_MAXSIZE="${CCACHE_MAXSIZE:-1G}" | ||
| export CMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER:-ccache}" | ||
| export CMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER:-ccache}" | ||
| export FETCHCONTENT_BASE_DIR="${FETCHCONTENT_BASE_DIR:-${BUILD_CACHE_DIR}/fetchcontent/${BUILD_CACHE_KEY}}" | ||
| export MAVEN_USER_HOME="${MAVEN_USER_HOME:-${BUILD_CACHE_DIR}/maven}" | ||
|
|
||
| mkdir -p \ | ||
| "${BUILD_CACHE_DIR}/build/${BUILD_CACHE_KEY}" \ | ||
| "${CCACHE_DIR}" \ | ||
| "${FETCHCONTENT_BASE_DIR}" \ | ||
| "${MAVEN_USER_HOME}" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Host-side preparation for persistent container build caches. | ||
|
|
||
| if [[ "${_BUILD_CACHE_HOST_SH_LOADED:-}" == "1" ]]; then | ||
| return 0 | ||
| fi | ||
| readonly _BUILD_CACHE_HOST_SH_LOADED=1 | ||
|
|
||
| # Creates the shared tool caches and a namespaced FetchContent cache. | ||
| # | ||
| # Args: <cache-directory> <cache-key> | ||
| prepare_build_cache() { | ||
| if (( $# != 2 )) || [[ -z "$1" || -z "$2" ]]; then | ||
| echo >&2 "ERROR: prepare_build_cache requires a cache directory and key" | ||
| return 2 | ||
| fi | ||
|
|
||
| local cache_dir="$1" | ||
| local cache_key="$2" | ||
| mkdir -p \ | ||
| "${cache_dir}/build/${cache_key}" \ | ||
| "${cache_dir}/ccache" \ | ||
| "${cache_dir}/fetchcontent/${cache_key}" \ | ||
| "${cache_dir}/maven" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.