diff --git a/ansible/README.md b/ansible/README.md index 3dfc9de035..38d3bfb19d 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -137,7 +137,7 @@ There are a few configuration files that can be configured before execution of t ### Variables -Most of the following variables are defined in `vars/all.yml`. `rhel_target_version` is provided by the `setup-microshift-host` role defaults and can be set in `vars/all.yml` or passed directly with `-e`. +Most of the following variables are defined in `vars/all.yml`. The source-build variables and `rhel_target_version` are provided by role defaults and can be set in `vars/all.yml` or passed directly with `-e`. | Variable Name | Description | Default | | -------------- | ----------- | ------- | @@ -151,6 +151,9 @@ Most of the following variables are defined in `vars/all.yml`. `rhel_target_vers | `prometheus_logging` | Set up logging and exporters on the nodes | `true` | | `install_microshift` | Install MicroShift (from packages or source) | `false` | | `build_microshift` | Build MicroShift from source instead of installing packages | `false` | +| `microshift_source_dir` | Existing MicroShift Git worktree on the managed host to build instead of updating the default checkout | `""` | +| `microshift_git_revision` | Git revision to check out when building MicroShift from source | `"release-"` | +| `microshift_git_refspec` | Additional Git refspec to fetch when building MicroShift from source (e.g. `+refs/pull/123/head:refs/remotes/origin/pr-123`) | `""` | | `build_etcd_binary` | Build and deploy a separate etcd process | `false` | | `microshift_version` | MicroShift version to install (supports EC/RC prereleases) | `"4.20"` | | `enable_gpu` | Install NVIDIA GPU drivers and container toolkit for GPU workloads | `false` | @@ -158,6 +161,14 @@ Most of the following variables are defined in `vars/all.yml`. `rhel_target_vers | `run_workloads` | Run kube-burner performance workloads | `false` | | `rhel_target_version` | Pin RHEL to a specific version during upgrades (e.g., "9.8") | `undefined` | +Source builds update the existing checkout in `microshift_dir` to `microshift_git_revision`. By default, the revision is the release branch derived from +`microshift_version`; for example, both `4.21.0` and `latest-4.21` select `release-4.21`. Set it explicitly to build another branch, tag, or commit. +A commit SHA may require `microshift_git_refspec` when the commit is not reachable from a branch or tag fetched by default. Checking out a SHA leaves the +repository in detached HEAD state until a later branch-based run updates it. + +Set `microshift_source_dir` to build a complete Git worktree that is already present on the managed host. The caller is responsible for staging and +updating the worktree, including its `.git` metadata. When set, the Git checkout task is skipped and the Git revision and refspec variables are ignored. + ### Inventory Configuration The inventory configuration file is located at `inventory/inventory`. diff --git a/ansible/roles/install-microshift/defaults/main.yml b/ansible/roles/install-microshift/defaults/main.yml index 4c5e08bf0a..e0a337d20c 100644 --- a/ansible/roles/install-microshift/defaults/main.yml +++ b/ansible/roles/install-microshift/defaults/main.yml @@ -10,6 +10,16 @@ microshift_dir: "{{ ansible_facts.env.HOME }}/microshift" microshift_repo: https://github.com/openshift/microshift.git microshift_rpms: [] microshift_version: 4.22.0 +# Optional existing MicroShift Git worktree to build instead of updating +# microshift_dir from microshift_repo. +microshift_source_dir: "" +# Directory used by the source build tasks. +microshift_build_dir: "{{ microshift_source_dir | default(microshift_dir, true) }}" +# Git revision to check out when building MicroShift from source. +microshift_git_revision: "release-{{ (microshift_version | regex_replace('^latest-', '')).split('.')[:2] | join('.') }}" +# Optional additional Git refspec to fetch when building from source, +# e.g. "+refs/pull/123/head:refs/remotes/origin/pr-123" +microshift_git_refspec: "" du_dirs: - / diff --git a/ansible/roles/install-microshift/tasks/main.yml b/ansible/roles/install-microshift/tasks/main.yml index 7ff70a7799..eb2ac3cd0d 100644 --- a/ansible/roles/install-microshift/tasks/main.yml +++ b/ansible/roles/install-microshift/tasks/main.yml @@ -55,31 +55,27 @@ - cri-tools state: present - - name: check if microshift dir exists - ansible.builtin.stat: - path: "{{ microshift_dir }}" - register: ms_dir - - - name: clone microshift git repo + - name: ensure microshift git checkout ansible.builtin.git: repo: "{{ microshift_repo }}" dest: "{{ microshift_dir }}" - version: "{{ microshift_version }}" - when: not ms_dir.stat.exists + version: "{{ microshift_git_revision }}" + refspec: "{{ microshift_git_refspec | default(omit, true) }}" + when: not microshift_source_dir - name: make clean ansible.builtin.command: make clean args: - chdir: "{{ microshift_dir }}" + chdir: "{{ microshift_build_dir }}" - name: make rpm ansible.builtin.command: make rpm args: - chdir: "{{ microshift_dir }}" + chdir: "{{ microshift_build_dir }}" - name: find built RPMs ansible.builtin.find: - paths: "{{ microshift_dir }}" + paths: "{{ microshift_build_dir }}" patterns: '*.rpm' recurse: yes register: microshift_find