From f48fd211941ed819db3b38e05c98db07b890313a Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Tue, 18 Jan 2022 16:05:34 +0100 Subject: [PATCH] Deploy OpenShift InfraRed files from Tobiko InfraRed plugin Change-Id: I2a7d09d71a815c052e8a5e8dbb481d35904df234 --- docker-compose.yml | 4 +- infrared_plugin/Dockerfile | 43 ++++---- infrared_plugin/plugin.spec | 20 ++++ .../roles/tobiko-ir-deploy/tasks/main.yaml | 98 ++++++++++--------- .../roles/tobiko-ir-run/defaults/main.yaml | 13 +++ .../roles/tobiko-ir-run/tasks/main.yaml | 18 ++++ 6 files changed, 125 insertions(+), 71 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 328f1a22f..9c3ef8cac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -86,8 +86,8 @@ services: infrared: build: context: infrared_plugin - target: tobiko-infrared - hostname: tobiko-infrared + target: run + hostname: infrared environment: IR_EXTRA_ARGS: --tobiko-src-dir /tobiko volumes: diff --git a/infrared_plugin/Dockerfile b/infrared_plugin/Dockerfile index fe4fc4d53..a9cc5d238 100644 --- a/infrared_plugin/Dockerfile +++ b/infrared_plugin/Dockerfile @@ -1,6 +1,7 @@ FROM centos:8 as base ENV TOBIKO_INFRARED_DIR /tobiko-infrared +ENV OPENSHIFT_INFRARED_URL=http://code.engineering.redhat.com/gerrit/openshift-ir-plugin.git ENV WHEEL_DIR /wheel ENV REPORT_DIR /report ENV IR_HOME /infrared @@ -10,43 +11,41 @@ ENV IR_EXTRA_ARGS "" RUN dnf install -y git python3 rsync which RUN python3 -m pip install --upgrade wheel setuptools pip - -FROM base as source - -# Populate tobiko-infrared source dir -ADD . ${TOBIKO_INFRARED_DIR} - - -FROM source as build - -# Build Infrared wheel files -RUN python3 -m pip wheel -w ${WHEEL_DIR} -r ${TOBIKO_INFRARED_DIR}/requirements.txt +# Creates directories and use infrared home dir as home +RUN mkdir -p "${IR_HOME}" "${REPORT_DIR}" +WORKDIR "${IR_HOME}" FROM base as install # Install wheels -RUN mkdir -p ${WHEEL_DIR} -COPY --from=build ${WHEEL_DIR} ${WHEEL_DIR} -RUN pip install ${WHEEL_DIR}/*.whl +ADD requirements.txt . + +RUN pip install -r requirements.txt -FROM source as tobiko-infrared - -# Creates directories -RUN mkdir -p "${IR_HOME}" "${REPORT_DIR}" +FROM base as configure # Copy python pacakges COPY --from=install /usr/local /usr/local/ -# Add tobiko plugin +# Add optional plugins +RUN infrared plugin add "${OPENSHIFT_INFRARED_URL}" || true + +# Add Tobiko plugin +ADD . "${TOBIKO_INFRARED_DIR}" RUN infrared plugin add "${TOBIKO_INFRARED_DIR}" + +FROM base as run + +# Copy python pacakges +COPY --from=install /usr/local /usr/local/ +# Copy infrared home dir +COPY --from=configure "${IR_HOME}" "${IR_HOME}" + # Create initial workspace RUN infrared workspace checkout --create default -# Use infrared home dir as home -WORKDIR ${IR_HOME} - # Run Tobiko Infrared plugin CMD infrared tobiko --collect-dir "${REPORT_DIR}" ${IR_EXTRA_ARGS} diff --git a/infrared_plugin/plugin.spec b/infrared_plugin/plugin.spec index 3910eb544..d962165ca 100644 --- a/infrared_plugin/plugin.spec +++ b/infrared_plugin/plugin.spec @@ -101,6 +101,26 @@ subparsers: required: yes ansible_variable: tobiko_src_dir default: '{{ inventory_dir }}/src/tobiko' + openshift-ir-src-dir: + type: Value + help: Local directory where OpenShift InfraRed scripts are deployed from0 + ansible_variable: openshift_infrared_src_dir + openshift-ir-dir: + type: Value + help: Remote directory where OpenShift InfraRed scripts are deployed to + ansible_variable: openshift_infrared_dir + openshift-ir-repo: + type: Value + help: Git URL from where to download OpenShift InfraRed files + ansible_variable: openshift_infrared_git_repo + openshift-ir-remote: + type: Value + help: Git remote name to be used for checking out OpenShift InfraRed files + ansible_variable: openshift_infrared_git_remote + openshift-ir-refspec: + type: Value + help: Git refspect to be used for checking out OpenShift InfraRed files + ansible_variable: openshift_infrared_git_refspec - title: Configure stage options: diff --git a/infrared_plugin/roles/tobiko-ir-deploy/tasks/main.yaml b/infrared_plugin/roles/tobiko-ir-deploy/tasks/main.yaml index 672ee3e22..cd5df0703 100644 --- a/infrared_plugin/roles/tobiko-ir-deploy/tasks/main.yaml +++ b/infrared_plugin/roles/tobiko-ir-deploy/tasks/main.yaml @@ -8,57 +8,61 @@ - (deploy_clean | bool) -- name: "ensure target directory exists: '{{ deploy_dir }}'" - file: - path: "{{ deploy_dir | realpath }}" - state: directory - register: create_dest_dir +- when: (deploy_git_refspec | length) > 0 + block: + - name: "ensure target directory exists: '{{ deploy_dir }}'" + file: + path: "{{ deploy_dir | realpath }}" + state: directory + register: create_dest_dir + + - name: "checkout files from '{{ deploy_git_repo }}[{{ deploy_git_refspec }}]' to '{{ deploy_dir }}'" + git: + dest: '{{ deploy_dir }}' + repo: '{{ deploy_git_repo }}' + refspec: '{{ deploy_git_refspec }}' + version: FETCH_HEAD + remote: '{{ deploy_git_remote or omit }}' + force: yes + register: checkout_files -- name: "checkout files from '{{ deploy_git_repo }}[{{ deploy_git_refspec }}]' to '{{ deploy_dir }}'" - git: - dest: '{{ deploy_dir }}' - repo: '{{ deploy_git_repo }}' - refspec: '{{ deploy_git_refspec }}' - version: FETCH_HEAD - remote: '{{ deploy_git_remote or omit }}' - force: yes - register: checkout_files - when: - - (deploy_git_refspec | length) > 0 - - -- name: "copy '{{ deploy_src_dir }}' to '{{ deploy_dir }}'" - synchronize: - src: "{{ deploy_src_dir | realpath }}/." - dest: "{{ deploy_dir | realpath }}" - use_ssh_args: yes - recursive: yes - rsync_opts: - - '--exclude-from={{ deploy_src_dir | realpath }}/.gitignore' - register: copy_src_dir - when: +- when: - (deploy_src_dir | length) > 0 - checkout_files is skipped + block: + - name: "check source directory exists" + stat: + path: '{{ deploy_src_dir }}' + register: deploy_src_dir_stat + + - when: deploy_src_dir_stat.stat.exists + block: + - name: "ensure target directory exists: '{{ deploy_dir }}'" + file: + path: "{{ deploy_dir | realpath }}" + state: directory + register: create_dest_dir + + - name: "copy '{{ deploy_src_dir }}' to '{{ deploy_dir }}'" + synchronize: + src: "{{ deploy_src_dir | realpath }}/." + dest: "{{ deploy_dir | realpath }}" + use_ssh_args: yes + recursive: yes + rsync_opts: + - '--exclude-from={{ deploy_src_dir | realpath }}/.gitignore' + register: copy_src_dir -- name: "get last change details for '{{ deploy_dir }}'" # noqa 303 - command: - chdir: "{{ deploy_dir }}" - cmd: git log -n 1 - changed_when: no - register: get_git_log +- when: (checkout_files is not skipped) or (copy_src_dir is not skipped) + block: + - name: "get last change details for '{{ deploy_dir }}'" # noqa 303 + command: + chdir: "{{ deploy_dir }}" + cmd: git log -n 1 + changed_when: no + register: get_git_log - -- name: "show last change details" - debug: var=get_git_log.stdout_lines - - -# we install validations-common here since it's -# packaged by rhel-osp -- name: install validations-common - ignore_errors: yes - become: true - package: - name: validations-common - state: present + - name: "show last change details" + debug: var=get_git_log.stdout_lines diff --git a/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml b/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml index 0097e663a..e8c58184a 100644 --- a/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml +++ b/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml @@ -6,3 +6,16 @@ test_git_refspec: '' tobiko_git_remote: '' test_git_remote: '' stacks_cleanup: false + + +# Local directory where OpenShift InfraRed scripts are deployed from +openshift_infrared_src_dir: '{{ playbook_dir }}/../openshift' + +# Remote directory where OpenShift InfraRed scripts are deployed to +openshift_infrared_dir: '{{ ansible_user_dir }}/src/openshift-ir-plugin' + +# Remote Git repo from where OpenShift InfraRed scripts are deployed from +openshift_infrared_git_repo: + 'http://code.engineering.redhat.com/gerrit/openshift-ir-plugin.git' +openshift_infrared_git_refspec: '' +openshift_infrared_git_remote: '' diff --git a/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml b/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml index 98d6cd188..90f4c0e05 100644 --- a/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml +++ b/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml @@ -36,6 +36,24 @@ deploy_git_remote: '{{ test_git_remote }}' when: test_dir != tobiko_dir + - name: deploy OpenShift InfraRed plugin files + include_role: name=tobiko-ir-deploy + vars: + deploy_dir: '{{ openshift_infrared_dir | realpath }}' + deploy_src_dir: '{{ openshift_infrared_src_dir | realpath }}' + + deploy_git_repo: '{{ openshift_infrared_git_repo }}' + deploy_git_refspec: '{{ openshift_infrared_git_refspec }}' + deploy_git_remote: '{{ openshift_infrared_git_remote }}' + + # validations-common here since it's packaged by rhel-osp + - name: install validations-common + ignore_errors: yes + become: true + package: + name: validations-common + state: present + - name: "initialize test execution" include_role: name=tobiko-configure