Skip to content

Commit

Permalink
Get latest release of oc client from OpenShift Builds (#84)
Browse files Browse the repository at this point in the history
Get latest release of oc client from OpenShift Builds
  • Loading branch information
cfchase authored Jul 7, 2017
1 parent 12e3133 commit 7ca1c05
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
57 changes: 57 additions & 0 deletions ansible/roles/openshift_setup/files/get_oc_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python

import urllib
import sys
import re
from HTMLParser import HTMLParser


class CientListHTMLParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.processing_anchor = False
self.latest_version = None

def handle_starttag(self, tag, attrs):
if tag == 'a':
self.processing_anchor = True

def handle_endtag(self, tag):
if tag == 'a':
self.processing_anchor = False

def handle_data(self, data):
if self.processing_anchor:
match = re.search('(\d+)\.(\d+)\.(\d+)\.(\d+)', data) or re.search('(\d+)\.(\d+)\.(\d+)', data)
if match:
if self.latest_version is None:
self.latest_version = match.groups()
else:
for idx, version_str in enumerate(match.groups()):
if idx >= len(self.latest_version):
self.latest_version = match.groups()
break
latest = int(self.latest_version[idx])
current = int(version_str)
if current > latest:
self.latest_version = match.groups()
break
if version_str < self.latest_version[idx]:
break

if re.match('linux', sys.platform):
platform = 'linux'
elif re.match('darwin', sys.platform):
platform = 'macosx'
else:
sys.exit(1)

client_list_html = urllib.urlopen('https://mirror.openshift.com/pub/openshift-v3/clients/').read()

parser = CientListHTMLParser()
parser.feed(client_list_html)
if parser.latest_version is None:
sys.exit(1)
version = '.'.join(parser.latest_version)
sys.stdout.write('https://mirror.openshift.com/pub/openshift-v3/clients/' + version + '/' + platform + '/oc.tar.gz')
sys.stdout.flush()
48 changes: 44 additions & 4 deletions ansible/roles/openshift_setup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,54 @@
state: directory
mode: 0755

# Temporary fix until release version of oc client works with latest images.
- name: Download oc binary "{{ openshift_client_url }}"
# Temporary fix until release version of oc client is stable
- name: Get URL of latest version of oc client packaged by OpenShift
script: get_oc_url.py
register: get_oc_url_output

- set_fact:
openshift_client_release_url: "{{get_oc_url_output.stdout}}"

- set_fact:
openshift_client_release_file: oc.tar.gz

- debug:
var: openshift_client_release_url

- name: Delete previous downloaded client (readonly) file
file:
path: /tmp/{{ openshift_client_release_file }}
state: absent

- name: Delete previous decompressed client file
file:
path: /tmp/oc
state: absent

- name: Download oc client "{{ openshift_client_release_url }}"
get_url:
url: "{{ openshift_client_url }}"
url: "{{ openshift_client_release_url }}"
dest: /tmp/{{ openshift_client_release_file }}
mode: 0440
force: yes
register: get_openshift_release

- name: Untar {{ openshift_client_release_file }}
shell: tar -xzf /tmp/{{ openshift_client_release_file }} -C /tmp

- name: Install oc
copy:
remote_src: True
src: /tmp/oc
dest: "{{ oc_tools_dir }}/oc"
mode: 0755
force: yes

- name: Checking version of oc client
shell: "{{ oc_cmd }} version"
register: oc_version_output

- debug:
msg: "{{ oc_version_output.stdout_lines }}"

# - name: Download oc binary "{{ openshift_client_release_url }}"
# get_url:
Expand Down

0 comments on commit 7ca1c05

Please sign in to comment.