-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: export distribution container build artifacts #2186
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ BUILD_CONTEXT_DIR=$(pwd) | |
|
||
if [ "$#" -lt 4 ]; then | ||
# This only works for templates | ||
echo "Usage: $0 <template_or_config> <image_name> <container_base> <pip_dependencies> [<run_config>] [<special_pip_deps>]" >&2 | ||
echo "Usage: $0 <template_or_config> <image_name> <container_base> <pip_dependencies> [<run_config>] [<special_pip_deps>] [<export_dir>]" >&2 | ||
exit 1 | ||
fi | ||
set -euo pipefail | ||
|
@@ -43,23 +43,26 @@ shift | |
# Handle optional arguments | ||
run_config="" | ||
special_pip_deps="" | ||
|
||
# Check if there are more arguments | ||
# The logics is becoming cumbersom, we should refactor it if we can do better | ||
if [ $# -gt 0 ]; then | ||
# Check if the argument ends with .yaml | ||
if [[ "$1" == *.yaml ]]; then | ||
run_config="$1" | ||
shift | ||
# If there's another argument after .yaml, it must be special_pip_deps | ||
if [ $# -gt 0 ]; then | ||
special_pip_deps="$1" | ||
fi | ||
else | ||
# If it's not .yaml, it must be special_pip_deps | ||
special_pip_deps="$1" | ||
fi | ||
fi | ||
export_dir="" | ||
|
||
# Process remaining arguments | ||
while [[ $# -gt 0 ]]; do | ||
case "$1" in | ||
*.yaml) | ||
run_config="$1" | ||
shift | ||
;; | ||
*) | ||
# Check if argument is a valid directory path (export_dir) or special_pip_deps | ||
if [[ "$1" == *" "* ]] || ! mkdir -p "$1" 2>/dev/null; then | ||
special_pip_deps="$1" | ||
else | ||
export_dir="$1" | ||
fi | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
# Define color codes | ||
RED='\033[0;31m' | ||
|
@@ -83,8 +86,8 @@ add_to_container() { | |
fi | ||
} | ||
|
||
# Check if container command is available | ||
if ! is_command_available $CONTAINER_BINARY; then | ||
# Check if container command is available only if not running in export mode | ||
if ! is_command_available $CONTAINER_BINARY && [ -z "$export_dir" ]; then | ||
printf "${RED}Error: ${CONTAINER_BINARY} command not found. Is ${CONTAINER_BINARY} installed and in your PATH?${NC}" >&2 | ||
exit 1 | ||
fi | ||
|
@@ -96,7 +99,7 @@ FROM $container_base | |
WORKDIR /app | ||
|
||
# We install the Python 3.11 dev headers and build tools so that any | ||
# C‑extension wheels (e.g. polyleven, faiss‑cpu) can compile successfully. | ||
# C-extension wheels (e.g. polyleven, faiss-cpu) can compile successfully. | ||
|
||
RUN dnf -y update && dnf install -y iputils git net-tools wget \ | ||
vim-minimal python3.11 python3.11-pip python3.11-wheel \ | ||
|
@@ -270,6 +273,50 @@ printf "Containerfile created successfully in %s/Containerfile\n\n" "$TEMP_DIR" | |
cat "$TEMP_DIR"/Containerfile | ||
printf "\n" | ||
|
||
# If export_dir is specified, copy all necessary files and exit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this script is getting very large. I think at the very least we can make this section into a function perhaps? |
||
if [ -n "$export_dir" ]; then | ||
mkdir -p "$export_dir" | ||
timestamp=$(date '+%Y-%m-%d_%H-%M-%S') | ||
tar_name="${image_name//[^a-zA-Z0-9]/_}_${timestamp}.tar.gz" | ||
|
||
# If a run config is provided, copy it to the export directory otherwise it's a template build and | ||
# we don't need to copy anything | ||
if [ -n "$run_config" ]; then | ||
mv "$run_config" "$TEMP_DIR"/run.yaml | ||
fi | ||
|
||
# Create the archive with all files | ||
echo "Creating tarball with the following files:" | ||
echo "- Containerfile" | ||
[ -n "$run_config" ] && echo "- run.yaml" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice one liners edit: although the conditionals get repeated. can you add the |
||
[ -n "$external_providers_dir" ] && [ -d "$external_providers_dir" ] && echo "- providers.d directory" | ||
|
||
# Capture both stdout and stderr from tar command | ||
tar_cmd="tar -czf \"$export_dir/$tar_name\" -C \"$TEMP_DIR\" Containerfile" | ||
|
||
if [ -n "$run_config" ]; then | ||
tar_cmd="$tar_cmd -C \"$BUILD_CONTEXT_DIR\" \"$(basename run.yaml)\"" | ||
fi | ||
|
||
if [ -n "$external_providers_dir" ] && [ -d "$external_providers_dir" ]; then | ||
tar_cmd="$tar_cmd -C \"$BUILD_CONTEXT_DIR\" providers.d" | ||
fi | ||
|
||
tar_output=$(eval "$tar_cmd" 2>&1) | ||
tar_status=$? | ||
|
||
if [ $tar_status -ne 0 ]; then | ||
echo "ERROR: Failed to create tarball" >&2 | ||
echo "Tar command output:" >&2 | ||
echo "$tar_output" >&2 | ||
exit 1 | ||
fi | ||
rm -rf providers.d run.yaml | ||
|
||
echo "Build artifacts tarball created: $export_dir/$tar_name" | ||
exit 0 | ||
fi | ||
|
||
# Start building the CLI arguments | ||
CLI_ARGS=() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm what is this? this looks very dangerous. why are we doing
mkdir -p
for checking?!