Skip to content
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

[3006.x] Keep extras directory when upgrading Salt on macOS #65078

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/65073.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The macOS installer no longer removes the extras directory
56 changes: 50 additions & 6 deletions pkg/macos/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,34 @@ _usage() {
echo "usage: ${0}"
echo " [-h|--help] [-v|--version]"
echo ""
echo " -h, --help this message"
echo " -v, --version version of Salt display in the package"
echo " -h, --help Display this message"
echo " -v, --version Version of Salt to display in the package"
echo " -p, --python-version Version of python to install using relenv."
echo " The python version is tied to the relenv"
echo " version"
echo " -r, --relenv-version Version of relenv to install"
echo ""
echo " Build a Salt package:"
echo " example: $0 3006.1-1"
}

function _parse_yaml {
twangboy marked this conversation as resolved.
Show resolved Hide resolved
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}

#-------------------------------------------------------------------------------
# Get Parameters
#-------------------------------------------------------------------------------
Expand All @@ -141,6 +162,16 @@ while true; do
VERSION="$*"
shift
;;
-p | --python-version )
shift
PY_VERSION="$1"
shift
;;
-r | --relenv-version )
shift
RELENV_VERSION="$1"
shift
;;
-*)
echo "Invalid Option: $1"
echo ""
Expand All @@ -159,6 +190,17 @@ if [ -z "$VERSION" ]; then
fi
VERSION=${VERSION#"v"}

# Get defaults from workflows. This defines $python_version and $relenv_version
eval "$(_parse_yaml "$SRC_DIR/cicd/shared-gh-workflows-context.yml")"

if [ -z "$PY_VERSION" ]; then
PY_VERSION=$python_version
fi

if [ -z "$RELENV_VERSION" ]; then
RELENV_VERSION=$relenv_version
fi

#-------------------------------------------------------------------------------
# Quit on error
#-------------------------------------------------------------------------------
Expand All @@ -184,12 +226,14 @@ fi
#-------------------------------------------------------------------------------
printf "#%.0s" {1..80}; printf "\n"
echo "Build Salt Package for macOS"
echo "- Python Version: $PY_VERSION"
echo "- Relenv Version: $RELENV_VERSION"
printf "v%.0s" {1..80}; printf "\n"

#-------------------------------------------------------------------------------
# Build Python
#-------------------------------------------------------------------------------
"$SCRIPT_DIR/build_python.sh"
"$SCRIPT_DIR/build_python.sh" -v $PY_VERSION -r $RELENV_VERSION

#-------------------------------------------------------------------------------
# Install Salt
Expand All @@ -210,15 +254,15 @@ printf "v%.0s" {1..80}; printf "\n"
# Build and Sign Package
#-------------------------------------------------------------------------------
if [ "$(id -un)" != "root" ]; then
sudo "$SCRIPT_DIR/package.sh" "$VERSION"
sudo "$SCRIPT_DIR/package.sh" "$VERSION" -s
else
"$SCRIPT_DIR/package.sh" "$VERSION"
"$SCRIPT_DIR/package.sh" "$VERSION" -s
fi

#-------------------------------------------------------------------------------
# Notarize Package
#-------------------------------------------------------------------------------
"$SCRIPT_DIR/notarize.sh" "salt-$VERSION-py3-$CPU_ARCH-signed.pkg"
"$SCRIPT_DIR/notarize.sh" "salt-$VERSION-py3-$CPU_ARCH.pkg"

#-------------------------------------------------------------------------------
# Script Completed
Expand Down
45 changes: 38 additions & 7 deletions pkg/macos/build_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# TODO: is building

# Locations
SRC_DIR="$(git rev-parse --show-toplevel)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SYS_PY_BIN="$(which python3)"
BUILD_DIR="$SCRIPT_DIR/build"
Expand All @@ -43,13 +44,14 @@ _usage() {
echo "usage: ${0}"
echo " [-h|--help] [-v|--version]"
echo ""
echo " -h, --help this message"
echo " -b, --build build python instead of fetching"
echo " -v, --version version of python to install, must be available with relenv"
echo " -r, --relenv-version version of python to install, must be available with relenv"
echo " -h, --help this message"
echo " -b, --build build python instead of fetching"
echo " -v, --version version of python to install, must be a"
echo " version available in relenv"
echo " -r, --relenv-version version of relenv to install"
echo ""
echo " To build python 3.10.12:"
echo " example: $0 --version 3.10.12"
echo " To build python 3.10.13 you need to use relenv 0.13.5:"
echo " example: $0 --relenv-version 0.13.5 --version 3.10.13"
}

# _msg
Expand All @@ -74,6 +76,23 @@ _failure() {
exit 1
}

function _parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}

#-------------------------------------------------------------------------------
# Get Parameters
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -112,6 +131,17 @@ while true; do
esac
done

# Get defaults from workflows. This defines $python_version and $relenv_version
eval "$(_parse_yaml "$SRC_DIR/cicd/shared-gh-workflows-context.yml")"

if [ -z "$PY_VERSION" ]; then
PY_VERSION=$python_version
fi

if [ -z "$RELENV_VERSION" ]; then
RELENV_VERSION=$relenv_version
fi

#-------------------------------------------------------------------------------
# Script Start
#-------------------------------------------------------------------------------
Expand All @@ -122,6 +152,7 @@ else
echo "Fetch Python with Relenv"
fi
echo "- Python Version: $PY_VERSION"
echo "- Relenv Version: $RELENV_VERSION"
printf -- "-%.0s" {1..80}; printf "\n"

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -207,7 +238,7 @@ export RELENV_FETCH_VERSION=$(relenv --version)
#-------------------------------------------------------------------------------
if [ $BUILD -gt 0 ]; then
echo "- Building python (relenv):"
relenv build --clean
relenv build --clean --python=$PY_VERSION
else
# We want to suppress the output here so it looks nice
# To see the output, remove the output redirection
Expand Down
35 changes: 34 additions & 1 deletion pkg/macos/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DIST_XML="$SCRIPT_DIR/distribution.xml"
BUILD_DIR="$SCRIPT_DIR/build"
CMD_OUTPUT=$(mktemp -t cmd_log.XXX)
SCRIPTS_DIR="$SCRIPT_DIR/dist_scripts"
# Get the python version from the relenv python
BLD_PY_BIN="$BUILD_DIR/opt/salt/bin/python3"
PY_VER=$($BLD_PY_BIN -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')

#-------------------------------------------------------------------------------
# Functions
Expand Down Expand Up @@ -231,6 +235,35 @@ else
_failure
fi

if [ -d "$SCRIPTS_DIR" ]; then
_msg "Removing existing scripts directory"
rm -f "$SCRIPTS_DIR"
if ! [ -d "$SCRIPTS_DIR" ]; then
_success
else
_failure
fi
fi

_msg "Creating scripts directory"
cp -r "$SCRIPT_DIR/pkg-scripts" "$SCRIPTS_DIR"
if [ -d "$SCRIPTS_DIR" ]; then
_success
else
CMD_OUTPUT="Failed to copy: $SCRIPTS_DIR"
_failure
fi

_msg "Setting python version for preinstall"
SED_STR="s/@PY_VER@/$PY_VER/g"
sed -i "" "$SED_STR" "$SCRIPTS_DIR/preinstall"
if grep -q "$PY_VER" "$SCRIPTS_DIR/preinstall"; then
_success
else
CMD_OUTPUT="Failed to set: $PY_VER"
_failure
fi

#-------------------------------------------------------------------------------
# Build and Sign the Package
#-------------------------------------------------------------------------------
Expand All @@ -239,7 +272,7 @@ _msg "Building the source package"
# Build the src package
FILE="$SCRIPT_DIR/salt-src-$VERSION-py3-$CPU_ARCH.pkg"
if pkgbuild --root="$BUILD_DIR" \
--scripts="$SCRIPT_DIR/pkg-scripts" \
--scripts="$SCRIPTS_DIR" \
--identifier=com.saltstack.salt \
--version="$VERSION" \
--ownership=recommended \
Expand Down
20 changes: 15 additions & 5 deletions pkg/macos/pkg-scripts/preinstall
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,22 @@ if [ -L "$SBIN_DIR/salt-config" ]; then
fi

#-------------------------------------------------------------------------------
# Remove the $INSTALL_DIR directory
# Remove folders and files from the INSTALL_DIR
# Don't remove extras-3.##
# The part wrapped in `@` will be replaced by the correct version of python
# during packaging using SED
#-------------------------------------------------------------------------------
if [ -d "$INSTALL_DIR" ]; then
log "Cleanup: Removing $INSTALL_DIR"
rm -rf "$INSTALL_DIR"
log "Cleanup: Removed Successfully"
for dir in "$INSTALL_DIR"/*/; do
if [[ "$dir" != *"extras-@PY_VER@"* ]]; then
log "Cleanup: Removing $dir"
rm -rf "$dir"
fi
done
log "Cleanup: Removed Directories Successfully"

if [ -f "$INSTALL_DIR/salt-minion" ]; then
find $INSTALL_DIR -maxdepth 1 -type f -delete
log "Cleanup: Removed Files Successfully"
twangboy marked this conversation as resolved.
Show resolved Hide resolved
fi

#-------------------------------------------------------------------------------
Expand Down