From 05363e8e8f3f9ccda0b0019ee84589dda2237cf8 Mon Sep 17 00:00:00 2001 From: Ari LiVigni Date: Wed, 30 May 2018 09:23:20 -0400 Subject: [PATCH 1/6] Load helper containers - Added ansible and linchpin containers to the sample project https://github.com/CentOS-PaaS-SIG/contra-env-sample-project/pull/14 - Always checkout sample project repo if different than project repo - Load helper templates always --- playbooks/group_vars/all/global.yml | 7 +++++++ playbooks/roles/create/tasks/clone_repos.yml | 2 +- playbooks/roles/os_temps/tasks/setup_containers.yml | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/playbooks/group_vars/all/global.yml b/playbooks/group_vars/all/global.yml index 82a5384a..a9d19f5e 100644 --- a/playbooks/group_vars/all/global.yml +++ b/playbooks/group_vars/all/global.yml @@ -134,3 +134,10 @@ sample_os_template_dir: "config/s2i" # Sample Jenkins pipelines directory sample_pipeline_dir: "config/pipelines/buildconfigs" +## Continuous-Infra helper containers + +# Helper project directory +helper_project_dir: "{{ contra_env_setup_dir }}/{{ sample_project_repo.split('/')[-1] | replace('.git', '') }}" + +# Helper OpenSift template directory +helper_os_template_dir: "{{ sample_os_template_dir }}" diff --git a/playbooks/roles/create/tasks/clone_repos.yml b/playbooks/roles/create/tasks/clone_repos.yml index bce8f44c..7a2655ef 100644 --- a/playbooks/roles/create/tasks/clone_repos.yml +++ b/playbooks/roles/create/tasks/clone_repos.yml @@ -28,4 +28,4 @@ refspec: "{{ sample_project_refspec }}" version: "{{ sample_project_branch }}" force: yes - when: (project_repo != sample_project_repo and setup_sample_project|bool == true) \ No newline at end of file + when: project_repo != sample_project_repo \ No newline at end of file diff --git a/playbooks/roles/os_temps/tasks/setup_containers.yml b/playbooks/roles/os_temps/tasks/setup_containers.yml index bf54a4a1..2cdc1849 100644 --- a/playbooks/roles/os_temps/tasks/setup_containers.yml +++ b/playbooks/roles/os_temps/tasks/setup_containers.yml @@ -13,6 +13,14 @@ recurse: yes register: os_templates +- name: "Get helper OpenShift s2i template names from {{ helper_os_template_dir }}/helper" + find: + paths: "{{ helper_project_dir }}/{{ helper_os_template_dir }}/helper" + patterns: '*.yml,*.yaml' + recurse: yes + register: helper_os_templates + when: project_repo != sample_project_repo + - name: "Get sample OpenShift s2i template names from {{ sample_os_template_dir }}/samples" find: paths: "{{ sample_project_dir }}/{{ sample_os_template_dir }}/samples" @@ -38,6 +46,10 @@ - set_fact: all_templates: "{{ os_templates.files }}" +- set_fact: + all_templates: "{{ os_templates.files }} + {{ helper_os_templates.files }}" + when: project_repo != sample_project_repo + - set_fact: all_templates: "{{ os_templates.files }} + {{ sample_os_templates.files }}" when: (project_repo != sample_project_repo and setup_sample_project|bool == true) From 266421f8e73195b8739d44efd1f4c7c9f253a08f Mon Sep 17 00:00:00 2001 From: Ari LiVigni Date: Wed, 30 May 2018 09:35:48 -0400 Subject: [PATCH 2/6] Load helper containers - Added ansible and linchpin containers to the sample project https://github.com/CentOS-PaaS-SIG/contra-env-sample-project/pull/14 - Always checkout sample project repo if different than project repo - Load helper templates always - Fixed logic on sample, helper, project containers --- playbooks/roles/os_temps/tasks/setup_containers.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playbooks/roles/os_temps/tasks/setup_containers.yml b/playbooks/roles/os_temps/tasks/setup_containers.yml index 2cdc1849..1a7c231f 100644 --- a/playbooks/roles/os_temps/tasks/setup_containers.yml +++ b/playbooks/roles/os_temps/tasks/setup_containers.yml @@ -48,10 +48,10 @@ - set_fact: all_templates: "{{ os_templates.files }} + {{ helper_os_templates.files }}" - when: project_repo != sample_project_repo + when: (project_repo != sample_project_repo and setup_sample_project|bool == false) - set_fact: - all_templates: "{{ os_templates.files }} + {{ sample_os_templates.files }}" + all_templates: "{{ os_templates.files }} + {{ sample_os_templates.files }} + {{ helper_os_templates.files }} " when: (project_repo != sample_project_repo and setup_sample_project|bool == true) - debug: From 53788e6992eda95bd585b95b94e1f2cea14f3465 Mon Sep 17 00:00:00 2001 From: Ari LiVigni Date: Wed, 30 May 2018 12:25:36 -0400 Subject: [PATCH 3/6] Load helper containers - Added ansible and linchpin containers to the sample project https://github.com/CentOS-PaaS-SIG/contra-env-sample-project/pull/14 - Always checkout sample project repo if different than project repo - Load helper templates always - Fixed logic on sample, helper, project containers - start_minishift option --- README.md | 33 +++++++++++++++++-- playbooks/group_vars/all/global.yml | 1 + playbooks/roles/os_temps/tasks/main.yml | 2 +- .../roles/os_temps/tasks/start_mcluster.yml | 2 +- playbooks/setup.yml | 2 +- test/README.md | 13 ++++++++ 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e2ef0379..aa1bb451 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,12 @@ - [Project repo options that has s2i templates and Jenkins Pipelines](#project-repo-options-that-has-s2i-templates-and-jenkins-pipelines) - [OpenShift s2i template setup options](#openshift-s2i-template-setup-options) - [Jenkins 2.0 pipeline setup options](#jenkins-20-pipeline-setup-options) + - [Templates](#templates) - [Usage examples](#usage-examples) - - [Example 1: Setup on a local server :: Setup Minishift + OS templates](#example-1-setup-on-a-local-server--setup-minishift--os-templates) - - [Example 2: Setup on a local server :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-2-setup-on-a-local-server--setup-minishift--os-templates--jenkins-20-pipelines) - - [Example 3: Setup on a local server :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-3-setup-on-a-local-server--setup-minishift--os-templates--jenkins-20-pipelines) + - [Example 1: Setup on a local machine :: Setup Minishift + OS templates](#example-1-setup-on-a-local-machine--setup-minishift--os-templates) + - [Example 2: Setup on a local machine :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-2-setup-on-a-local-machine--setup-minishift--os-templates--jenkins-20-pipelines) + - [Example 3: Setup on a local machine :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-3-setup-on-a-local-machine--setup-minishift--os-templates--jenkins-20-pipelines) + - [Example 4: Setup on a local machine :: Start Minishift w/profile mysetup + OS templates + Jenkins 2.0 pipelines](#example-4-setup-on-a-local-machine--start-minishift-wprofile-mysetup--os-templates--jenkins-20-pipelines) - [Debugging Issues](#debugging-issues) - [Issue #1: Can't push images to the Minishift cluster](#issue-1-cant-push-images-to-the-minishift-cluster) - [Solution #1:](#solution-1) @@ -182,6 +184,31 @@ _Note: The -K is used to prompt you for your password for sudo (if you require o The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same
Instead of -k you could use --private-key=_ +### Example 4: Setup on a local machine :: Start Minishift w/profile mysetup + OS templates + Jenkins 2.0 pipelines + + 1. Install on a local machine as user cloud-user. + 2. Setup pre-reqs (kvm driver and nested virtualization) + 3. Start minishift cluster with profile mysetup + 4. Setup OpenShift s2i templates from the -e project_repo=https://github.com/arilivigni/ci-pipeline + 1. Override the project_repo with another one then the default in global.yml + 2. OpenShift project -e openshift_project=ari-ci-pipeline + 5. Modify my container tags with the tag=develop + 6. Setup Jenkins 2.0 pipelines from the project_repo=https://github.com/arilivigni/ci-pipeline + 7. Setup sample project templates and pipelines + from the project_repo=https://github.com/CentOS-PaaS-SIG/contra-env-sample-project + + +``` + ansible-playbook -vv -i "localhost," contra-env-setup/playbooks/setup.yml \ + -e user=cloud-user -e project_repo=https://github.com/arilivigni/ci-pipeline \ + -e openshift_project=ari-ci-pipeline -e tag=develop -e setup_pipelines=true \ + -e setup_sample_project -e start_minishift=true -e profile=mysetup -K -k + +``` +_Note: The -K is used to prompt you for your password for sudo (if you require one)
+ The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same
+ Instead of -k you could use --private-key=_ + ## Debugging Issues ### Issue #1: Can't push images to the Minishift cluster diff --git a/playbooks/group_vars/all/global.yml b/playbooks/group_vars/all/global.yml index a9d19f5e..d4148ef8 100644 --- a/playbooks/group_vars/all/global.yml +++ b/playbooks/group_vars/all/global.yml @@ -3,6 +3,7 @@ run_cleanup: false run_prereqs: true setup_minishift: true +startup_minishift: false setup_containers: true setup_pipelines: false setup_sample_project: false diff --git a/playbooks/roles/os_temps/tasks/main.yml b/playbooks/roles/os_temps/tasks/main.yml index 9a3eb76c..f12444a8 100644 --- a/playbooks/roles/os_temps/tasks/main.yml +++ b/playbooks/roles/os_temps/tasks/main.yml @@ -4,7 +4,7 @@ # Check if the minishift cluster is started if not then start the cluster - name: "Startup the minishift cluster" import_tasks: start_mcluster.yml - when: setup_minishift|bool == true + when: (setup_minishift|bool == true or start_minishift|bool == true) # Import_tasks install_oc_bin - name: "Get OpenShift client binary(oc) version {{ oc_version }} to {{ contra_env_setup_dir }}" diff --git a/playbooks/roles/os_temps/tasks/start_mcluster.yml b/playbooks/roles/os_temps/tasks/start_mcluster.yml index 17309370..c7aa9abd 100644 --- a/playbooks/roles/os_temps/tasks/start_mcluster.yml +++ b/playbooks/roles/os_temps/tasks/start_mcluster.yml @@ -8,5 +8,5 @@ # start minishift profile - name: "Start minishift profile {{ profile }}" - shell: "{{ minishift_bin }} start --profile {{ profile }} --disk-size {{ disk_size }} --memory {{ memory }} --openshift-version {{ oc_version }} --iso-url file:///{{ minishift_dest_dir }}/minishift.iso" + shell: "{{ minishift_bin }} start --profile {{ profile }} --cpus {{ cpus }} --disk-size {{ disk_size }} --memory {{ memory }} --openshift-version {{ oc_version }} --iso-url file:///{{ minishift_dest_dir }}/minishift.iso" when: minishift_status.stdout == "Stopped" diff --git a/playbooks/setup.yml b/playbooks/setup.yml index 2ef2418e..ce725cae 100644 --- a/playbooks/setup.yml +++ b/playbooks/setup.yml @@ -8,6 +8,6 @@ - { role: cleanup, when: run_cleanup|bool == true } - role: create - { role: prereqs, when: "run_prereqs|bool == true and setup_minishift|bool == true" } - - { role: minishift, when: setup_minishift|bool == true } + - { role: minishift, when: "setup_minishift|bool == true and start_minishift == false" } - { role: os_temps, when: setup_containers|bool == true } - { role: pipeline, when: setup_pipelines|bool == true } \ No newline at end of file diff --git a/test/README.md b/test/README.md index 12f2bc9c..d4c8d714 100644 --- a/test/README.md +++ b/test/README.md @@ -1,3 +1,16 @@ + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [contra-env-setup CI](#contra-env-setup-ci) + - [Avocado](#avocado) + - [How to install](#how-to-install) + - [Tests](#tests) + - [Running the test](#running-the-test) + - [References](#references) + + + # contra-env-setup CI This document describes how works the tests in the contra-env-setup repository. From 927b19fcb13ba4c46a764a11e4363edbf8ff3183 Mon Sep 17 00:00:00 2001 From: Ari LiVigni Date: Wed, 30 May 2018 12:27:56 -0400 Subject: [PATCH 4/6] Load helper containers - Added ansible and linchpin containers to the sample project https://github.com/CentOS-PaaS-SIG/contra-env-sample-project/pull/14 - Always checkout sample project repo if different than project repo - Load helper templates always - Fixed logic on sample, helper, project containers - start_minishift option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aa1bb451..b3e59430 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ contra-env-setup/playbooks/group_vars/all/global.yml * memory: Memory size to use for the VM : default=6400mb * cpus: Number of cpus to use for minishift VM: default=2 * minishift_iso: ISO image to use : default=http://artifacts.ci.centos.org/fedora-atomic/minishift/iso/minishift.iso +* start_minishift: start an existing minishift instance: default=false ### oc setup options * openshift_project: OpenShift project name : default:contra-sample-project From dda2481de9fbfb10afe89306a02d4ddad03b6252 Mon Sep 17 00:00:00 2001 From: Ari LiVigni Date: Wed, 30 May 2018 13:01:56 -0400 Subject: [PATCH 5/6] Load helper containers - Added ansible and linchpin containers to the sample project https://github.com/CentOS-PaaS-SIG/contra-env-sample-project/pull/14 - Always checkout sample project repo if different than project repo - Load helper templates always - Fixed logic on sample, helper, project containers - start_minishift option --- playbooks/roles/playbook_hooks/tasks/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 playbooks/roles/playbook_hooks/tasks/main.yml diff --git a/playbooks/roles/playbook_hooks/tasks/main.yml b/playbooks/roles/playbook_hooks/tasks/main.yml new file mode 100644 index 00000000..618ec96d --- /dev/null +++ b/playbooks/roles/playbook_hooks/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- debug: msg="{{ hooks }}" + +- name: "Adding external playbooks" + include: "{{ item }}" + with_items: "{{ hooks }}" \ No newline at end of file From 4c836b625bd41665a8bcaf19f4ff4b40bb34cd09 Mon Sep 17 00:00:00 2001 From: Ari LiVigni Date: Wed, 30 May 2018 13:06:56 -0400 Subject: [PATCH 6/6] Merge branch 'master' of https://github.com/CentOS-PaaS-SIG/contra-env-setup # Conflicts: # README.md --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fe0dfdbc..53687c23 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,7 @@ - [Example 2: Setup on a local machine :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-2-setup-on-a-local-machine--setup-minishift--os-templates--jenkins-20-pipelines) - [Example 3: Setup on a local machine :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-3-setup-on-a-local-machine--setup-minishift--os-templates--jenkins-20-pipelines) - [Example 4: Setup on a local machine :: Start Minishift w/profile mysetup + OS templates + Jenkins 2.0 pipelines](#example-4-setup-on-a-local-machine--start-minishift-wprofile-mysetup--os-templates--jenkins-20-pipelines) - - [Example 1: Setup on a local machine :: Setup Minishift + OS templates](#example-1-setup-on-a-local-machine--setup-minishift--os-templates) - - [Example 2: Setup on a local machine :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-2-setup-on-a-local-machine--setup-minishift--os-templates--jenkins-20-pipelines) - - [Example 3: Setup on a local machine :: Setup Minishift + OS templates + Jenkins 2.0 pipelines](#example-3-setup-on-a-local-machine--setup-minishift--os-templates--jenkins-20-pipelines) - - [Example 4: Using the playbook hooks on contra-env-setup](#example-4-using-the-playbook-hooks-on-contra-env-setup) + - [Example 5: Setup on a local machine :: Using the playbook hooks on contra-env-setup](#example-5-setup-on-a-local-machine--using-the-playbook-hooks-on-contra-env-setup) - [Debugging Issues](#debugging-issues) - [Issue #1: Can't push images to the Minishift cluster](#issue-1-cant-push-images-to-the-minishift-cluster) - [Solution #1:](#solution-1) @@ -213,7 +210,7 @@ _Note: The -K is used to prompt you for your password for sudo (if you require o The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same
Instead of -k you could use --private-key=_ -### Example 4: Using the playbook hooks on contra-env-setup +### Example 5: Setup on a local machine :: Using the playbook hooks on contra-env-setup This resource permit to create your playbooks to included as the last role that will be executed on contra-env-setup.