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

Clean up build/deploy scripts and docs #3390

Merged
merged 6 commits into from
Oct 7, 2024
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ When _Rancher Desktop_ is first run, you will be prompted to select a few initia
1. Verify that _Enable Kubernetes_ is checked.
2. Select the Kubernetes version marked as _stable, latest_.
3. Select your container runtime, either _containerd_ or _dockerd (moby)_:
- _containerd_ matches what is used on the NUC and uses the `k3s` Kubernetes engine. It requires that you run the
`build.py` script with the `--nerdctl` option.
- _containerd_ matches what is used on the NUC and uses the `k3s` Kubernetes engine. It requires that you set the
`CONTAINER_CLI` environment variable to `nerdctl` before running the `build.py` script.
- _dockerd_ uses the `k3d` (`k3s` in docker).
4. Select _Automatic_ or _Manual_ path setup.
5. Click _Accept_.
Expand Down Expand Up @@ -678,7 +678,7 @@ Notes:
export CONTAINER_CLI="nerdctl"
```

If you are using _Docker Desktop_ or _Rancher Desktop_ with the `dockerd` container runtime, clear this variable or
If you are using _Rancher Desktop_ with the `dockerd` container runtime or _Docker Desktop_, clear this variable or
set its value to `docker`.

- Run with the `--help` option to see all available options.
Expand Down
49 changes: 14 additions & 35 deletions deploy/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""
Build the containerd images for The Combine.

This script currently supports using 'docker' or 'nerdctl' to build the container
images. 'nerdctl' is recommended when using Rancher Desktop for the development
environment and 'docker' is recommended when using Docker Desktop with the 'containerd'
container engine.
This script currently supports using 'docker' or 'nerdctl' to build the container images.
The default is 'docker' unless the CONTAINER_CLI env var is set to 'nerdctl'.
'docker' is for Rancher Desktop with the 'dockerd' container runtime or Docker Desktop.
'nerdctl' is for Rancher Desktop with the 'containerd' container runtime.

When 'docker' is used for the build, the BuildKit backend will be enabled.
"""
Expand Down Expand Up @@ -190,11 +190,6 @@ def parse_args() -> Namespace:
"""Parse user command line arguments."""
parser = ArgumentParser(
description="Build containerd container images for project.",
epilog="""
NOTE:
The '--nerdctl' option is DEPRECATED and will be removed in future versions.
Set the environment variable CONTAINER_CLI to 'nerdctl' or 'docker' instead.
""",
formatter_class=RawFormatter,
)
parser.add_argument(
Expand All @@ -214,11 +209,6 @@ def parse_args() -> Namespace:
parser.add_argument(
"--repo", "-r", help="Push images to the specified Docker image repository."
)
parser.add_argument(
"--nerdctl",
action="store_true",
help="Use 'nerdctl' instead of 'docker' to build images.",
)
parser.add_argument(
"--namespace",
"-n",
Expand Down Expand Up @@ -264,7 +254,7 @@ def main() -> None:
logging.basicConfig(format="%(levelname)s:%(message)s", level=log_level)

# Setup required build engine - docker or nerdctl
container_cli = os.getenv("CONTAINER_CLI", "nerdctl" if args.nerdctl else "docker")
container_cli = os.getenv("CONTAINER_CLI", "docker")
match container_cli:
case "nerdctl":
build_cmd = [container_cli, "-n", args.namespace, "build"]
Expand All @@ -277,18 +267,18 @@ def main() -> None:
sys.exit(1)

# Setup build options
build_opts: List[str] = []
if args.quiet:
build_opts = ["--quiet"]
build_cmd += ["--quiet"]
else:
build_opts = ["--progress", "plain"]
build_cmd += ["--progress", "plain"]
if args.no_cache:
build_opts += ["--no-cache"]
build_cmd += ["--no-cache"]
if args.pull:
build_opts += ["--pull"]
build_cmd += ["--pull"]
if args.build_args is not None:
for build_arg in args.build_args:
build_opts += ["--build-arg", build_arg]
build_cmd += ["--build-arg", build_arg]
logging.debug(f"build_cmd: {build_cmd}")

if args.components is not None:
to_do = args.components
Expand All @@ -301,21 +291,10 @@ def main() -> None:
spec = build_specs[component]
spec.pre_build()
image_name = get_image_name(args.repo, spec.name, args.tag)
job_opts = ["-t", image_name, "-f", "Dockerfile", "."]
job_set[component] = JobQueue(component)
job_set[component].add_job(
Job(
build_cmd
+ build_opts
+ [
"-t",
image_name,
"-f",
"Dockerfile",
".",
],
spec.dir,
)
)
logging.debug(f"Adding job {build_cmd + job_opts}")
job_set[component].add_job(Job(build_cmd + job_opts, spec.dir))
if args.repo is not None:
if args.quiet:
push_args = ["--quiet"]
Expand Down
4 changes: 2 additions & 2 deletions deploy/scripts/install-combine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ install-kubernetes () {
cd ${DEPLOY_DIR}/ansible

if [ -d "${DEPLOY_DIR}/airgap-images" ] ; then
ansible-playbook playbook_desktop_setup.yaml -K -e k8s_user=`whoami` -e install_airgap_images=true
ansible-playbook playbook_desktop_setup.yml -K -e k8s_user=`whoami` -e install_airgap_images=true
else
ansible-playbook playbook_desktop_setup.yaml -K -e k8s_user=`whoami`
ansible-playbook playbook_desktop_setup.yml -K -e k8s_user=`whoami`
fi
}

Expand Down
10 changes: 5 additions & 5 deletions deploy/scripts/package_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ def package_k3s(dest_dir: Path) -> None:


def package_images(image_list: List[str], tar_file: Path) -> None:
container_cli = [os.getenv("CONTAINER_CLI", "docker")]
if container_cli[0] == "nerdctl":
container_cli.extend(["--namespace", "k8s.io"])
container_cli_cmd = [os.getenv("CONTAINER_CLI", "docker")]
if container_cli_cmd[0] == "nerdctl":
container_cli_cmd.extend(["--namespace", "k8s.io"])
# Pull each image
for image in image_list:
pull_cmd = container_cli + ["pull", image]
pull_cmd = container_cli_cmd + ["pull", image]
logging.debug(f"Running {pull_cmd}")
run_cmd(pull_cmd)
# Save pulled images into a .tar archive
run_cmd(container_cli + ["save"] + image_list + ["-o", str(tar_file)])
run_cmd(container_cli_cmd + ["save"] + image_list + ["-o", str(tar_file)])
# Compress the tarball
run_cmd(["zstd", "--rm", "--force", "--quiet", str(tar_file)])

Expand Down
1 change: 1 addition & 0 deletions deploy/scripts/setup_target.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
"""Setup ssh connection between host and target."""

import argparse
import os
Expand Down
Loading
Loading