Skip to content

Commit

Permalink
Update installer arch/arm arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec committed Oct 25, 2024
1 parent b708408 commit fddf9bb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
15 changes: 12 additions & 3 deletions deploy/scripts/install-combine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ install-kubernetes () {
# Setup Kubernetes environment and WiFi Access Point
cd ${DEPLOY_DIR}/ansible

# Set -e/--extra-vars for ansible-playbook
EXTRA_VARS="-e k8s_user=${whoami}"
if [ -d "${DEPLOY_DIR}/airgap-images" ] ; then
ansible-playbook playbook_desktop_setup.yml -K -e k8s_user=`whoami` -e install_airgap_images=true $(((DEBUG == 1)) && echo "-vv")
else
ansible-playbook playbook_desktop_setup.yml -K -e k8s_user=`whoami` $(((DEBUG == 1)) && echo "-vv")
EXTRA_VARS="${EXTRA_VARS} -e install_airgap_images=true"
fi
if [ $ARM == 1 ] ; then
EXTRA_VARS="${EXTRA_VARS} -e cpu_arch=arm64"
fi

ansible-playbook playbook_desktop_setup.yml -K ${EXTRA_VARS} $(((DEBUG == 1)) && echo "-vv")
}

# Set the KUBECONFIG environment variable so that the cluster can
Expand Down Expand Up @@ -193,6 +198,7 @@ CONFIG_DIR=${HOME}/.config/combine
mkdir -p ${CONFIG_DIR}
SINGLE_STEP=0
IS_SERVER=0
ARM=0
DEBUG=0

# See if we need to continue from a previous install
Expand All @@ -207,6 +213,9 @@ fi
while (( "$#" )) ; do
OPT=$1
case $OPT in
arm)
ARM=1
;;
clean)
next-state "Pre-reqs"
if [ -f ${CONFIG_DIR}/env ] ; then
Expand Down
41 changes: 20 additions & 21 deletions deploy/scripts/package_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
image names are extracted from the templates and then pulled from the repo and stored
in ../images as compressed tarballs; zstd compression is used.
By default, packs images for amd64 architecture; use --arm to pack for arm64 instead.
By default, packs images for amd64; use --arch for a different architecture.
"""

import argparse
Expand Down Expand Up @@ -42,10 +42,10 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("output_dir", help="Directory for the collected image files.")
# Add Optional arguments
parser.add_argument(
"--arm",
action="store_true",
help="Package for arm64 instead of the default amd64",
default=False,
"--arch",
choices=["amd64", "arm64"],
default="amd64",
help="Target cpu architecture.",
)
parser.add_argument(
"--config",
Expand All @@ -67,31 +67,30 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()


def package_k3s(dest_dir: Path, *, arm: bool = False, debug: bool = False) -> None:
def package_k3s(dest_dir: Path, *, arch: str = "arm64", debug: bool = False) -> None:
logging.info("Packaging k3s images.")
extra_vars = f"'package_dir':'{dest_dir}'"
if arm:
extra_vars += ",'cpu_arch':'arm64'"
ansible_cmd = [
"ansible-playbook",
"playbook_k3s_airgapped_files.yml",
"--extra-vars",
"{" + extra_vars + "}",
f"package_dir={dest_dir}",
"--extra-vars",
f"cpu_arch={arch}",
]
if debug:
ansible_cmd.append("-vv")
run_cmd(ansible_cmd, cwd=str(ansible_dir), print_cmd=debug, print_output=debug)


def package_images(
image_list: List[str], tar_file: Path, *, arm: bool = False, debug: bool = False
image_list: List[str], tar_file: Path, *, arch: str = "amd64", debug: bool = False
) -> None:
container_cli_cmd = [os.getenv("CONTAINER_CLI", "docker")]
if container_cli_cmd[0] == "nerdctl":
container_cli_cmd.extend(["--namespace", "k8s.io"])

# Pull each image
pull_cmd = container_cli_cmd + ["pull", f"--platform=linux/{'arm64' if arm else 'amd64'}"]
pull_cmd = container_cli_cmd + ["pull", f"--platform=linux/{arch}"]
for image in image_list:
run_cmd(pull_cmd + [image], print_cmd=debug, print_output=debug)

Expand All @@ -112,7 +111,7 @@ def package_middleware(
cluster_type: str,
image_dir: Path,
chart_dir: Path,
arm: bool = False,
arch: str = "amd64",
debug: bool = False,
) -> None:
logging.info("Packaging middleware images.")
Expand Down Expand Up @@ -168,12 +167,12 @@ def package_middleware(
middleware_images.append(match.group(1))

logging.debug(f"Middleware images: {middleware_images}")
out_file = f"middleware-airgap-images-{'arm64' if arm else 'amd64'}.tar"
package_images(middleware_images, image_dir / out_file, arm=arm, debug=debug)
out_file = f"middleware-airgap-images-{arch}.tar"
package_images(middleware_images, image_dir / out_file, arch=arch, debug=debug)


def package_thecombine(
tag: str, image_dir: Path, *, arm: bool = False, debug: bool = False
tag: str, image_dir: Path, *, arch: str = "amd64", debug: bool = False
) -> None:
logging.info(f"Packaging The Combine version {tag}.")
logging.debug("Create helm charts from templates")
Expand Down Expand Up @@ -206,8 +205,8 @@ def package_thecombine(
logging.debug(f"Combine images: {combine_images}")

# Logout of AWS to allow pulling the images
out_file = f"combine-airgap-images-{'arm64' if arm else 'amd64'}.tar"
package_images(combine_images, image_dir / out_file, arm=arm, debug=debug)
out_file = f"combine-airgap-images-{arch}.tar"
package_images(combine_images, image_dir / out_file, arch=arch, debug=debug)


def main() -> None:
Expand All @@ -228,16 +227,16 @@ def main() -> None:
os.environ["AWS_DEFAULT_REGION"] = ""

# Update helm repos
package_k3s(image_dir, arm=args.arm, debug=args.debug)
package_k3s(image_dir, arch=args.arch, debug=args.debug)
package_middleware(
args.config,
cluster_type="standard",
image_dir=image_dir,
chart_dir=chart_dir,
arm=args.arm,
arch=args.arch,
debug=args.debug,
)
package_thecombine(args.tag, image_dir, arm=args.arm, debug=args.debug)
package_thecombine(args.tag, image_dir, arch=args.arch, debug=args.debug)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions installer/make-combine-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if [[ $NET_INSTALL == 0 ]] ; then
# Package The Combine for "offline" installation
TEMP_DIR=/tmp/images-$$
pushd scripts
./package_images.py ${COMBINE_VERSION} ${TEMP_DIR} $((( ARM == 1 )) && echo "--arm") $((( DEBUG == 1 )) && echo "--debug")
./package_images.py ${COMBINE_VERSION} ${TEMP_DIR} $((( ARM == 1 )) && echo "--arch arm64") $((( DEBUG == 1 )) && echo "--debug")
INSTALLER_NAME="combine-installer.run"
popd
else
Expand All @@ -79,7 +79,7 @@ for DIR in venv scripts/__pycache__ ; do
done

cd ${SCRIPT_DIR}
makeself $((( DEBUG == 0)) && echo "--tar-quietly" ) ../deploy ${INSTALLER_NAME} "Combine Installer" scripts/install-combine.sh ${COMBINE_VERSION}
makeself $((( DEBUG == 0)) && echo "--tar-quietly" ) ../deploy ${INSTALLER_NAME} "Combine Installer" scripts/install-combine.sh ${COMBINE_VERSION} $((( ARM == 1 )) && echo "arm")
if [[ $NET_INSTALL == 0 ]] ; then
makeself --append ${TEMP_DIR} ${INSTALLER_NAME}
rm -rf ${TEMP_DIR}
Expand Down

0 comments on commit fddf9bb

Please sign in to comment.