diff --git a/agent/05_agent_create_cluster.sh b/agent/05_agent_create_cluster.sh index 10ffb54eb..be26d6a93 100755 --- a/agent/05_agent_create_cluster.sh +++ b/agent/05_agent_create_cluster.sh @@ -20,6 +20,16 @@ function create_image() { "${openshift_install}" --dir="${asset_dir}" --log-level=debug agent create image } +function get_agent_iso() { + declare agent_iso + + agent_iso="${OCP_DIR}/agent.$(uname -p).iso" + if [ ! -f "$agent_iso" -a -f "${OCP_DIR}/agent.iso" ]; then + agent_iso="${OCP_DIR}/agent.iso" + fi + echo "$agent_iso" +} + function attach_agent_iso() { # This is required to allow qemu opening the disk image @@ -27,10 +37,7 @@ function attach_agent_iso() { setfacl -m u:qemu:rx /root fi - local agent_iso="${OCP_DIR}/agent.$(uname -p).iso" - if [ ! -f "${agent_iso}" -a -f "${OCP_DIR}/agent.iso" ]; then - agent_iso="${OCP_DIR}/agent.iso" - fi + local agent_iso=$(get_agent_iso) for (( n=0; n<${2}; n++ )) do @@ -149,6 +156,10 @@ function mce_complete_deployment() { create_image +if [ ! -z "${AGENT_EMBED_GUI:-}" ]; then + ansible-playbook "${SCRIPTDIR}/agent/assets/webui/webui-playbook.yaml" +fi + attach_agent_iso master $NUM_MASTERS attach_agent_iso worker $NUM_WORKERS diff --git a/agent/assets/webui/ui.bu.j2 b/agent/assets/webui/ui.bu.j2 new file mode 100644 index 000000000..bd62f78bc --- /dev/null +++ b/agent/assets/webui/ui.bu.j2 @@ -0,0 +1,30 @@ +variant: openshift +version: 4.12 +systemd: + units: + - name: assisted-web-ui.service + enabled: true + contents: | + [Unit] + Description=Assisted Service web-ui + Wants=network.target + RequiresMountsFor=%t/containers + Requires=assisted-service.service + BindsTo=assisted-service-pod.service + After=network-online.target assisted-service-pod.service + ConditionPathExists=/etc/assisted-service/node0 + + [Service] + Environment=PODMAN_SYSTEMD_UNIT=%n + Restart=on-failure + TimeoutStartSec=500 + TimeoutStopSec=300 + ExecStartPre=/bin/rm -f %t/%n.ctr-id + ExecStart=/usr/bin/podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --sdnotify=conmon --replace -d --name=webui {{ webui_image }} + ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id + ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id + Type=notify + NotifyAccess=all + + [Install] + WantedBy=multi-user.target diff --git a/agent/assets/webui/webui-playbook.yaml b/agent/assets/webui/webui-playbook.yaml new file mode 100644 index 000000000..37a4cb60a --- /dev/null +++ b/agent/assets/webui/webui-playbook.yaml @@ -0,0 +1,87 @@ +- name: Create webui content for Agent ISO + hosts: localhost + collections: + - community.general + gather_facts: no + vars: + - webui_image: "{{ lookup('env', 'WEBUI_IMAGE') }}" + - ocp_dir: "{{ loopkup('env', 'OCP_DIR') }}" + + tasks: + - name: Check agent iso + ansible.builtin.file: + state: file + path: "{{ ocp_dir }}/agent.{{ ansible_architecture }}.iso" + register: agent_iso + + - name: Create webui temp dir + ansible.builtin.tempfile: + state: directory + suffix: webui + register: ui_tempdir + + - name: write UI butane + template: + src: "ui.bu.j2" + dest: "{{ ui_tempdir.path }}/ui.bu" + + - name: Generate UI ignition + containers.podman.podman_container: + name: butane + state: started + detach: no + rm: yes + volume: + - "{{ ui_tempdir.path }}:/data" + image: quay.io/coreos/butane:release + command: "--pretty --strict /data/ui.bu -o /data/ui.ign" + + + - name: Extract Agent ISO ignition + containers.podman.podman_container: + name: coreos-installer + state: started + detach: no + rm: yes + volume: + - "{{ agent_iso.path }}:/data/agent.iso" + image: quay.io/coreos/coreos-installer:release + command: "iso ignition show /data/agent.iso" + register: iso_ignition + + - name: save ISO ignition + ansible.builtin.copy: + content: "{{ iso_ignition.stdout }}" + dest: "{{ ui_tempdir.path }}/iso.ign" + + - name: Get kcli ignition merger tool + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/karmab/kcli/master/extras/ignitionmerger.py + dest: "{{ ui_tempdir.path }}/ignitionmerger.py" + mode: "0755" + + - name: Merge ignition + ansible.builtin.command: + argv: + - python + - "{{ ui_tempdir.path }}/ignitionmerger.py" + - "{{ ui_tempdir.path }}/iso.ign" + - "{{ ui_tempdir.path }}/ui.ign" + register: ignitionmerger + + - name: save merged ignition + ansible.builtin.copy: + content: "{{ ignitionmerger.stdout }}" + dest: "{{ ui_tempdir.path }}/merged.ign" + + - name: Embedding merged ignition + containers.podman.podman_container: + name: coreos-installer + state: started + detach: no + rm: yes + volume: + - "{{ ui_tempdir.path }}/merged.ign:/data/merged.ign" + - "{{ agent_iso.path }}:/data/agent.iso" + image: quay.io/coreos/coreos-installer:release + command: "iso ignition embed -f -i /data/merged.ign /data/agent.iso" diff --git a/config_example.sh b/config_example.sh index e37674848..cebb9efa3 100755 --- a/config_example.sh +++ b/config_example.sh @@ -667,3 +667,8 @@ set -x # Uncomment the following line to deploy the MCE operator, and to automatically import the current cluster as the hub cluster # export AGENT_DEPLOY_MCE=true + +# If you want to run the assisted service UI, you must set the following environment variables: +# AGENT_EMBED_GUI=true +# WEBUI_IMAGE="quay.io/edge-infrastructure/assisted-installer-ui:latest" +# Note that if you can put a different WEBUI_IMAGE