Skip to content

Commit

Permalink
Merge pull request #81 from werne2j/master
Browse files Browse the repository at this point in the history
Make changes to allow for mac users
  • Loading branch information
arilivigni authored Sep 5, 2018
2 parents 1fca9c8 + 8e28dec commit ff9fc37
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 52 deletions.
71 changes: 41 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
- [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 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)
- [Mac Setup](#mac-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)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
![CI-Pipeline](continuous-infra-logo.png "continuous-infra")
# Contra Environment Setup
# Contra Environment Setup
# minishift or OpenShift + OpenShift s2i templates + Jenkins pipelines


Expand Down Expand Up @@ -60,12 +61,12 @@ This will setup the minishift + pipeline development environment. It can setup
or only certain components. ex. minishift, jenkins infra, pipeline containers, and fed-msg relay

### default variables
```
contra-env-setup/playbooks/group_vars/all/global.yml
`contra-env-setup/playbooks/group_vars/all/global.yml`

```
## Pre-Setup options

* host_os: Set the OS of the machine you are running the setup on : default=linux
* shell_rc: Set your shell configuration file : default=.bashrc
* run_cleanup: Run clean up of previous setup : default=false
* run_prereqs: Run setting up virtualization and kvm-driver : default=true
* contra_env_setup_dir: Directory to store the contra-env-setup : default "{{ ansible_env.HOME }}/.contra-env-setup
Expand All @@ -86,7 +87,7 @@ contra-env-setup/playbooks/group_vars/all/global.yml
* disk_size: Disk size to use for minishift : default=40gb
* memory: Recommended memory size to use for the VM : default=8092mb
* 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
* minishift_iso: ISO image to use : default=http://artifacts.ci.centos.org/fedora-atomic/minishift/iso/minishift.iso
* minishift_insecure_registry: Additional insecure registries : default="" (not used)

### oc setup options
Expand All @@ -100,10 +101,10 @@ contra-env-setup/playbooks/group_vars/all/global.yml

## Project repo options that has s2i templates and Jenkins Pipelines
* project_repo: Project repo to import templates and pipelines from : default=https://github.com/CentOS-PaaS-SIG/contra-env-sample-project
* project_refspec: Project refspec : default=+refs/pull/*:refs/heads/*
* project_refspec: Project refspec : default=+refs/pull/*:refs/heads/*
* project_branch: Project branch : default=master
* project_dir: Project directory where repo is stored locally : default={{ contra_env_setup_dir }}/{{ project_repo.split('/')[-1] }}
* setup_sample_project: Sample profect to setup
* setup_sample_project: Sample profect to setup

### OpenShift s2i template setup options
* setup_containers: Setup OpenShift s2i templates : default=true
Expand All @@ -121,7 +122,7 @@ Note that it is possible to use {{ ansible_vars }} in your Openshift Templates.

## Usage examples

### Example 1: Setup on a local machine :: Setup Minishift + OS templates
### Example 1: Setup on a local machine :: Setup Minishift + OS templates

1. Install on a local machine as user cloud-user.
2. Setup pre-reqs (kvm driver and nested virtualization)
Expand All @@ -130,12 +131,11 @@ Note that it is possible to use {{ ansible_vars }} in your Openshift Templates.
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 default tag. tag=stable

```
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 user=cloud-user -e project_repo=https://github.com/arilivigni/ci-pipeline
-e openshift_project=ari-ci-pipeline -K -k
```
_Note: The -K is used to prompt you for your password for sudo (if you require one) <br>
The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same<br>
Expand All @@ -151,37 +151,35 @@ _Note: The -K is used to prompt you for your password for sudo (if you require o
2. OpenShift project -e openshift_project=ari-ci-pipeline
5. Modify my container tags with the default tag. tag=stable
6. Setup Jenkins 2.0 pipelines from the project_repo=https://github.com/arilivigni/ci-pipeline

```
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 setup_pipelines=true -K -k
```
_Note: The -K is used to prompt you for your password for sudo (if you require one) <br>
The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same<br>
Instead of -k you could use --private-key=<absolute_path_to_ssh_private_key>_

### Example 3: Setup on a local machine :: Setup Minishift + 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. Setup a minishift cluster
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
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
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 -K -k
```
_Note: The -K is used to prompt you for your password for sudo (if you require one) <br>
The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same<br>
Expand All @@ -194,19 +192,18 @@ _Note: The -K is used to prompt you for your password for sudo (if you require o
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
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
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) <br>
The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same<br>
Expand All @@ -223,7 +220,6 @@ executed on contra-env-setup.
-e openshift_project=ari-ci-pipeline -e tag=develop -e setup_pipelines=true \
-e setup_sample_project -K -k
--extra-vars='{"hooks": ["/contra-env-setup/playbook_a.yml","/contra-env-setup/playbook_b.yml"]}'
```

### Example 6: Setup on a local machine :: Start Minishift w/profile mysetup + OS templates + Jenkins 2.0 pipelines
Expand All @@ -233,35 +229,50 @@ executed on contra-env-setup.
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
2. OpenShift project -e openshift_project=ari-ci-pipeline
5. Disable setup of the helper containers ansible-executor and linchpin-executor
6. Setup Jenkins 2.0 pipelines from the project_repo=https://github.com/arilivigni/ci-pipeline
7. Setup sample project templates and pipelines
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 setup_helper_containers=false -e setup_pipelines=true \
-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) <br>
The -k is used to prompt you for your ssh password can hit enter if using -K and they are the same<br>
Instead of -k you could use --private-key=<absolute_path_to_ssh_private_key>_

## Mac Setup

In order to run this setup when using a mac, a few other steps must be taken.
* Install [Homebrew](https://brew.sh/) and [Virtualbox](https://www.virtualbox.org/)
* With Homebrew, install jq and gtar. `brew install jq gtar`
* When running the `setup.yml` file..
- Override `host_os` with `darwin`
- Disable pre-reqs `run_prereqs=false`
- Add `--connection=local` to end of command

Example:
```
ansible-playbook -vv -i "localhost," playbooks/setup.yml \
-e user=cloud-user -e run_prereqs=false -e setup_pipelines=true \
-e host_os=darwin -e setup_sample_project -K -k --connection=local
```

## Debugging Issues

### Issue #1: Can't push images to the Minishift cluster

This issue reveals itself as not being able to pull images from the docker registry. This is because your minishift VM can't reach outside addresses.

Pinpointing if you are hitting this issue:
1. In the output of the following task:
1. In the output of the following task:
```
TASK [minishift : Initialization of minishift cluster with profile minishiftpipeline]
```
2. Task contains:
```
Expand All @@ -270,7 +281,7 @@ Pinpointing if you are hitting this issue:

3. Full example output: http://pastebin.centos.org/620286/

#### Solution #1:
#### Solution #1:

Make sure you can ping outside addresses from within the minishift vm.

Expand Down
8 changes: 7 additions & 1 deletion playbooks/group_vars/all/global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ dkvm_version: v0.10.0
# minishift version
minishift_version: v1.23.0

# host os
host_os: linux

# shell configutation file
shell_rc: .bashrc

# default location for minishift
minishift_dest_dir: "{{ contra_env_setup_dir }}/minishift"

Expand Down Expand Up @@ -76,7 +82,7 @@ modify_scc: true
oc_version: v3.10.0

# Path to oc binary directory
oc_bin_path: "{{ ansible_env.HOME }}/.{{ profile }}/cache/oc/{{ oc_version }}/linux"
oc_bin_path: "{{ ansible_env.HOME }}/.{{ profile }}/cache/oc/{{ oc_version }}/{{ host_os }}"

# Path to oc binary
oc_bin: "{{ oc_bin_path }}/oc"
Expand Down
3 changes: 1 addition & 2 deletions playbooks/roles/minishift/tasks/init_minishift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
insertafter: '\s+</features>'
line: " <cpu mode='host-passthrough'/>"
become: yes


when: host_os == "linux"
4 changes: 2 additions & 2 deletions playbooks/roles/minishift/tasks/install_minishift_bin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Install minishift

- name: Query for minishift compressed binary
shell: curl -s https://github.com/minishift/minishift/releases/{{ minishift_version }} | grep 'minishift-.*-linux.*' | head -1 | sed 's/.*<a href="\(.*\)" .*/https:\/\/github.com\1/' | cut -d'"' -f1
shell: curl -s https://github.com/minishift/minishift/releases/{{ minishift_version }} | grep 'minishift-.*-{{ host_os }}.*' | head -1 | sed 's/.*<a href="\(.*\)" .*/https:\/\/github.com\1/' | cut -d'"' -f1
register: get_minishift_bin

- name: "Pull down and extract minishift binary to {{ minishift_dest_dir }}"
Expand All @@ -28,4 +28,4 @@
- name: "Delete {{ ansible_env.HOME }}/{{ minishift_src_dir }}"
file:
path: "{{ minishift_dest_dir }}//{{ minishift_src_dir }}"
state: absent
state: absent
5 changes: 5 additions & 0 deletions playbooks/roles/minishift/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
shell: "{{ minishift_bin }} config set skip-check-openshift-release true"
when: minishift_version != "v1.12.0"

# Set vm-driver to virtualbox if using a mac
- name: "Set minishift vm-driver to virtualbox"
shell: "{{ minishift_bin }} config set vm-driver virtualbox"
when: host_os == "darwin"

- name: "Pull down the minishift iso"
get_url:
url: "{{ minishift_iso }}"
Expand Down
8 changes: 4 additions & 4 deletions playbooks/roles/minishift/tasks/set_minishift_path.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
# set path for minishift

- name: "Set path for minishift in {{ ansible_env.HOME }}/.bashrc"
- name: "Set path for minishift in {{ ansible_env.HOME }}/{{ shell_rc }}"
lineinfile:
path: "{{ ansible_env.HOME }}/.bashrc"
path: "{{ ansible_env.HOME }}/{{ shell_rc }}"
line: 'export PATH="$PATH:{{ minishift_dest_dir }}"'
create: yes

- name: "Source {{ ansible_env.HOME }}/.bashrc"
shell: source {{ ansible_env.HOME }}/.bashrc
- name: "Source {{ ansible_env.HOME }}/{{ shell_rc }}"
shell: source {{ ansible_env.HOME }}/{{ shell_rc }}
5 changes: 2 additions & 3 deletions playbooks/roles/os_temps/tasks/check_new_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

# Setup tag if current container image build is successful
- name: Modify tags on images
shell: "{{ oc_bin }} get imagestream | awk '{print $2}' | grep -v DOCKER | sed 's/.*5000\\///g' | grep '{{ build_config_name_files[template_name] }}' | xargs -i {{ oc_bin }} tag {}:latest {}:{{ tag }}"
shell: "{{ oc_bin }} get imagestream | awk '{print $2}' | grep -v DOCKER | sed 's/.*5000\\///g' | grep '{{ build_config_name_files[template_name] }}' | xargs -I{} {{ oc_bin }} tag {}:latest {}:{{ tag }}"
when: modify_tags|bool == true and current_build_succeeded|bool == true

# Output the OpenShift build logs if the current build failed
- name: Output the OpenShift build logs if the current build failed
shell: "echo \"{{ oc_build_result.stdout }}\" | awk '{print $1}' | xargs -i {{ oc_bin }} logs builds/{}"
shell: "echo \"{{ oc_build_result.stdout }}\" | awk '{print $1}' | xargs -I{} {{ oc_bin }} logs builds/{}"
register: oc_build_log
when: build_results[template_name]|bool == false and oc_build_result.stdout is defined

Expand All @@ -46,4 +46,3 @@
loop_var: failed_resource_name
ignore_errors: yes
when: (build_results[template_name]|bool == false and created_resources[template_name] != "")

16 changes: 10 additions & 6 deletions playbooks/roles/os_temps/tasks/install_oc_bin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# Grab the oc client independent of minishift to talk to any Openshift cluster
- name: "Create directory for the OpenShift client binary(oc)"
file:
path: "{{ ansible_env.HOME }}/.{{ profile }}/cache/oc/{{ oc_version }}/linux"
path: "{{ ansible_env.HOME }}/.{{ profile }}/cache/oc/{{ oc_version }}/{{ host_os }}"
state: directory

- name: "Query for OpenShift client compressed binary version {{ oc_version }}"
shell: curl -s https://github.com/openshift/origin/releases/{{ oc_version }} | grep 'openshift-origin-client-tools-.*-linux.*.tar.gz' | head -1 | sed 's/.*<a href="\(.*\)" .*/https:\/\/github.com\1/' | cut -d'"' -f1
shell: curl -s https://github.com/openshift/origin/releases/{{ oc_version }} | grep {{ client_path }} | head -1 | sed 's/.*<a href="\(.*\)" .*/https:\/\/github.com\1/' | cut -d'"' -f1
register: get_oc_bin
vars:
client_path: "{% if host_os == 'darwin' %}openshift-origin-client-tools-.*-mac.*.zip{% else %}openshift-origin-client-tools-.*-linux.*.tar.gz{% endif %}"

- name: "Pull down and extract OpenShift client binary(oc) to {{ contra_env_setup_dir }}"
unarchive:
Expand All @@ -19,12 +21,14 @@
set_fact:
oc_src_dir: "{{ contra_env_setup_dir }}/{{ get_oc_bin.stdout | basename | regex_search(regexp,'\\1') | join(' ') }}"
vars:
regexp: '(openshift-origin-client-tools-.*linux.*).tar.gz'
regexp: "{% if host_os == 'darwin' %}(openshift-origin-client-tools-.*mac.*).zip{% else %}(openshift-origin-client-tools-.*linux.*).tar.gz{% endif %}"

- name: "Copy OpenShift client binary(oc) version files from {{ oc_src_dir }}/oc to {{ oc_bin_path }}/ "
shell: cp {{ oc_src_dir }}/oc {{ oc_bin_path }}/
- name: "Copy OpenShift client binary(oc) version files from {{ src_path }}/oc to {{ oc_bin_path }}/ "
shell: cp {{ src_path }}/oc {{ oc_bin_path }}/
vars:
src_path: "{% if host_os == 'darwin' %}{{ contra_env_setup_dir }}{% else %}{{ oc_src_dir }}{% endif %}"

- name: "Delete {{ oc_src_dir }}"
file:
path: "{{ oc_src_dir }}"
state: absent
state: absent
4 changes: 2 additions & 2 deletions playbooks/roles/os_temps/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Import_tasks jq for querying container config files
- name: "Install jq for querying container config files"
import_tasks: "{{ playbook_dir }}/roles/prereqs/tasks/install_virtual_reqs.yml"
when: setup_minishift|bool == true
when: (setup_minishift|bool == true and host_os == "linux")

# Setup project_repo containers
- include_tasks: "setup_containers.yml os_template_path={{ project_dir }}/{{ os_template_dir }}"
Expand All @@ -69,4 +69,4 @@

# Add security context constraints
- import_tasks: add_scc.yml
when: modify_scc|bool == true
when: modify_scc|bool == true
4 changes: 2 additions & 2 deletions playbooks/roles/os_temps/tasks/setup_containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
ignore_errors: yes

- name: "Cleanup all failed dc, bc, routes, svc, and imagestreams on the cluster"
shell: "{{ oc_bin }} get all | grep '{{ failed_container_name }}' | awk '{print $1}' | egrep -v 'builds\\/|po\\/' | xargs -i {{ oc_bin }} delete {}"
shell: "{{ oc_bin }} get all | grep '{{ failed_container_name }}' | awk '{print $1}' | egrep -v 'builds\\/|po\\/' | xargs -I{} {{ oc_bin }} delete {}"
with_items: "{{ oc_check_app_status.stdout_lines }}"
loop_control:
loop_var: failed_container_name
ignore_errors: yes
when: oc_check_app_status.stdout != ""

- name: "Cleanup any serviceaccounts, pvc, and rolebindings for an app if it exists on the cluster"
shell: "{{ oc_bin }} get {{ item }} | egrep '{{ oc_check_app_status.stdout_lines|join('|') }}' | awk '{print $1}' | xargs -i {{ oc_bin }} delete {{ item }}/{}"
shell: "{{ oc_bin }} get {{ item }} | egrep '{{ oc_check_app_status.stdout_lines|join('|') }}' | awk '{print $1}' | xargs -I{} {{ oc_bin }} delete {{ item }}/{}"
ignore_errors: yes
with_items:
- serviceaccounts
Expand Down

0 comments on commit ff9fc37

Please sign in to comment.