You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2017/06/30 17:59:47 UTC

[incubator-openwhisk] branch master updated: Add the support to install the binaries from the new repo (#2379)

This is an automated email from the ASF dual-hosted git repository.

csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 4711de7  Add the support to install the binaries from the new repo (#2379)
4711de7 is described below

commit 4711de738e463f0a70027c8343e6d41db17a364a
Author: Vincent <sh...@us.ibm.com>
AuthorDate: Fri Jun 30 13:59:45 2017 -0400

    Add the support to install the binaries from the new repo (#2379)
    
    * Rename build.sh into createContent.sh
    
    * Add the support to install the binaries from the new repo
    
    This PR adds the functionalities to either install openwhisk
    binaries from the releases page of openwhisk cli or copy the
    binaries locally.
    
    The key installation_mode of openwhisk_cli dict can be set to
    remote or local. The default one is local.
    
    Closes-Bug: #2101
---
 ansible/files/package-versions.ini                 |  2 +
 ansible/group_vars/all                             | 44 +++++++++++++-
 ansible/roles/cli/files/createContentJson.sh       | 69 +++++++++++++++++++++
 ansible/roles/cli/tasks/cli_remote_mode.yml        | 18 ++++++
 .../roles/cli/tasks/copy_local_openwhisk_cli.yml   | 10 ++++
 ansible/roles/cli/tasks/deploy.yml                 | 30 +++++-----
 ansible/roles/cli/tasks/download_cli.yml           |  2 +
 ansible/roles/cli/tasks/download_openwhisk_cli.yml | 70 ++++++++++++++++++++++
 8 files changed, 230 insertions(+), 15 deletions(-)

diff --git a/ansible/files/package-versions.ini b/ansible/files/package-versions.ini
new file mode 100644
index 0000000..2464ea7
--- /dev/null
+++ b/ansible/files/package-versions.ini
@@ -0,0 +1,2 @@
+[openwhisk-cli]
+git_tag=latest
diff --git a/ansible/group_vars/all b/ansible/group_vars/all
index 743e1c2..2c78b29 100644
--- a/ansible/group_vars/all
+++ b/ansible/group_vars/all
@@ -1,6 +1,7 @@
 mode: deploy
 prompt_user: true
 openwhisk_home: "{{ lookup('env', 'OPENWHISK_HOME')|default(playbook_dir + '/..', true) }}"
+openwhisk_cli_home: "{{ lookup('env', 'OPENWHISK_CLI') | default(openwhisk_home, true) }}"
 exclude_logs_from: []
 
 # This whisk_api_localhost_name_default is used to configure nginx to permit vanity URLs for web actions
@@ -254,4 +255,45 @@ catalog_repos:
     # Set the local location as the same level as openwhisk home, but it can be changed.
     location: "{{ openwhisk_home }}/../openwhisk-catalog"
     version: "HEAD"
-    repo_update: "no"
\ No newline at end of file
+    repo_update: "no"
+
+openwhisk_cli_tag: "{{ lookup('ini', 'git_tag section=openwhisk-cli file={{ openwhisk_home }}/ansible/files/package-versions.ini') }}"
+
+# The openwhisk_cli is used to determine how to install the OpenWhisk CLI. The
+# installation_mode can be specified into two modes: remote and local.
+# The mode remote means to download the available binaries from the releases page
+# of the official openwhisk cli repository. The mode local means to build the binaries
+# locally in a directory and get them from the local directory. The default value
+# for openwhisk is local.
+#
+# The name specifies the package name of the binaries in remote mode.
+#
+# The dest_name specifies the package name of the binaries in Nginx in remote mode.
+#
+# The location specifies the official website where Openwhisk CLI is hosted in
+# remote mode or location to save the binaries of the OpenWhisk CLI in local mode.
+#
+
+openwhisk_cli:
+  installation_mode: local
+  local:
+    location: "{{ openwhisk_cli_home }}/bin"
+
+# If you would like to use the remote mode, you can uncomment the following section.
+#  remote:
+#    name: OpenWhisk_CLI
+#    dest_name: OpenWhisk_CLI
+#    location: "https://github.com/apache/incubator-openwhisk-cli/releases/download/{{ openwhisk_cli_tag }}"
+ 
+# The list of operating systems for which openwhisk cli binaries are downloaded,
+# if the installation_mode is remote.
+cli_os:
+  - linux
+  - mac
+  - windows
+
+# The list of architectures for which openwhisk cli binaries are downloaded,
+# if the installation_mode is remote.
+cli_arch:
+  - amd64
+  - 386
diff --git a/ansible/roles/cli/files/createContentJson.sh b/ansible/roles/cli/files/createContentJson.sh
new file mode 100755
index 0000000..6171568
--- /dev/null
+++ b/ansible/roles/cli/files/createContentJson.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+set +x
+set -e
+
+get_compressed_name() {
+  local os=$1
+  local arch=$2
+  local product_name=$3
+
+  if [ $arch = amd64 ]; then
+    comp_name="$product_name-$os";
+  elif [ $arch = 386 ]; then
+    comp_name="$product_name-$os-32bit";
+  else
+    comp_name="$product_name-$os-$arch";
+  fi
+
+  echo $comp_name;
+};
+
+get_binary_path() {
+    local comp_name=$1
+    local os=$2
+    local arch=$3
+
+    if [ $os = "linux" ]; then
+        comp_name="$comp_name.tgz"
+    else
+    		comp_name="$comp_name.zip"
+    fi
+    echo $os/$arch/$comp_name;
+};
+
+create_cli_packages() {
+  local dirIndex="{\"cli\":{"
+
+  for platform in $platforms; do
+    dirIndex="$dirIndex\"$platform\":{"
+
+    for arch in $archs; do
+      comp_name=$(get_compressed_name $platform $arch $zip_name)
+      comp_path=$(get_binary_path $comp_name $platform $arch)
+
+      if [ $arch = $default_arch ]; then
+          dirIndex="$dirIndex\"default\":{\"path\":\"$comp_path\"},";
+      fi
+
+      dirIndex="$dirIndex\"$arch\":{\"path\":\"$comp_path\"},";
+    done
+
+    dirIndex="$(echo $dirIndex | rev | cut -c2- | rev)"
+    dirIndex="$dirIndex},";
+  done
+
+  dirIndex="$(echo $dirIndex | rev | cut -c2- | rev)"
+  dirIndex="$dirIndex}}"
+
+  echo $dirIndex > $PATH_CONTENT_JSON/content.json
+};
+
+archs="386 amd64";
+default_arch="amd64"
+
+PATH_CONTENT_JSON=$1
+BINARY_TAG=$2
+platforms=$3
+zip_name=$4
+create_cli_packages
diff --git a/ansible/roles/cli/tasks/cli_remote_mode.yml b/ansible/roles/cli/tasks/cli_remote_mode.yml
new file mode 100644
index 0000000..3c3eb57
--- /dev/null
+++ b/ansible/roles/cli/tasks/cli_remote_mode.yml
@@ -0,0 +1,18 @@
+---
+
+# Download the cli for the remote mode and generate the content.json file
+
+- name: "download the binaries from the release page of OpenWhisk CLI"
+  include: download_openwhisk_cli.yml
+  with_nested:
+    - "{{ cli_os }}"
+    - "{{ cli_arch }}"
+
+- name: "generate content.json locally for Nginx CLI directory"
+  local_action: shell "./createContentJson.sh" "{{ config_root_dir }}" "{{ openwhisk_cli_tag }}" "{{ cli_os | join(" ") }}" "{{ openwhisk_cli.remote.dest_name }}" chdir="{{ openwhisk_home }}/ansible/roles/cli/files"
+
+- name: "copy the local content.json to the remote node"
+  copy: src={{ config_root_dir }}/content.json dest={{ cli.nginxdir }}/
+
+- name: "delete the local content.json"
+  local_action: file path={{ config_root_dir }}/content.json state=absent
diff --git a/ansible/roles/cli/tasks/copy_local_openwhisk_cli.yml b/ansible/roles/cli/tasks/copy_local_openwhisk_cli.yml
new file mode 100644
index 0000000..a219e68
--- /dev/null
+++ b/ansible/roles/cli/tasks/copy_local_openwhisk_cli.yml
@@ -0,0 +1,10 @@
+---
+
+# Copy the cli binaries to Nginx directory
+
+- stat: path={{ openwhisk_cli.local.location }}/{{ item }}
+  register: binary_path
+
+- name: "copy the local binaries from a local directory to Nginx directory"
+  copy: src={{ openwhisk_cli.local.location }}/{{ item }} dest={{ cli.nginxdir }}/
+  when: binary_path.stat.exists
diff --git a/ansible/roles/cli/tasks/deploy.yml b/ansible/roles/cli/tasks/deploy.yml
index 151f6a8..d3e551c 100644
--- a/ansible/roles/cli/tasks/deploy.yml
+++ b/ansible/roles/cli/tasks/deploy.yml
@@ -6,24 +6,26 @@
     path: "{{ cli.nginxdir  }}"
     state: directory
 
-- include: docker_login.yml
+- set_fact:
+    cli_installation_mode="{{ openwhisk_cli.installation_mode }}"
 
-- name: "pull the {{ docker_image_tag }} image of cli"
-  shell: "docker pull {{ docker_registry }}{{ docker_image_prefix }}/cli:{{ docker_image_tag }}"
-  when: docker_registry != ""
-  retries: 3
+- include: docker_login.yml
 
-- name: "run Docker"
-  shell: "docker run --name cli {{ docker_registry }}{{ docker_image_prefix }}/cli:{{ docker_image_tag }}"
+- name: "download the binaries from the release page of OpenWhisk CLI"
+  include: cli_remote_mode.yml
+  when: cli_installation_mode == "remote"
 
-- name: "copy all the cli binaries into nginx"
-  shell: "docker cp cli:/src/github.com/go-whisk-cli/build/. '{{ cli.nginxdir }}'"
-  ignore_errors: yes
+- name: "copy the binaries from a local directory to Nginx directory"
+  include: copy_local_openwhisk_cli.yml
+  when: cli_installation_mode == "local"
+  with_items: "{{ cli_os }}"
 
-- name: "stop Docker"
-  shell: "docker stop cli"
+- name: "copy the local content.json from a local directory to Nginx directory"
+  copy: src={{ openwhisk_cli.local.location }}/content.json dest={{ cli.nginxdir }}/
+  when: cli_installation_mode == "local"
 
-- name: "remove cli container after publishing"
-  shell: "docker rm cli"
+- name: "copy the binaries from a local directory to Nginx directory"
+  copy: src={{ openwhisk_cli.local.location }}/content.json dest={{ cli.nginxdir }}/
+  when: cli_installation_mode == "local"
 
 - include: download_cli.yml
diff --git a/ansible/roles/cli/tasks/download_cli.yml b/ansible/roles/cli/tasks/download_cli.yml
index 7ac9209..2a33bf7 100644
--- a/ansible/roles/cli/tasks/download_cli.yml
+++ b/ansible/roles/cli/tasks/download_cli.yml
@@ -9,6 +9,7 @@
     dest="{{ openwhisk_home }}/bin/wsk"
     mode=0755
     validate_certs=False
+    force=True
   when: "'environments/docker-machine' not in inventory_dir"
 
 - name: "download cli (docker-machine) to openwhisk home at {{ openwhisk_home }}"
@@ -18,4 +19,5 @@
     dest="{{ openwhisk_home }}/bin/wsk"
     mode=0755
     validate_certs=False
+    force=True
   when: "'environments/docker-machine' in inventory_dir"
diff --git a/ansible/roles/cli/tasks/download_openwhisk_cli.yml b/ansible/roles/cli/tasks/download_openwhisk_cli.yml
new file mode 100644
index 0000000..573ccf8
--- /dev/null
+++ b/ansible/roles/cli/tasks/download_openwhisk_cli.yml
@@ -0,0 +1,70 @@
+---
+
+# Download the cli to Nginx CLI directory and unzip them
+
+- name: "set the basic variables os, arc and suffix"
+  set_fact:
+    os="{{ item[0] }}"
+    arc="{{ item[1] }}"
+    suffix="zip"
+
+- name: "change the suffix to tgz if the operating system is Linux"
+  set_fact:
+    suffix="tgz"
+  when: os == "linux"
+
+- name: "set the file name to download"
+  set_fact:
+    source_name="{{ openwhisk_cli.remote.name }}-{{ openwhisk_cli_tag }}-{{ os }}-{{ arc }}.{{ suffix }}"
+
+- name: "set the destination file name locally after download for 32 bit"
+  set_fact:
+    dest_name="{{ openwhisk_cli.remote.dest_name }}-{{ os }}-32bit.{{ suffix }}"
+  when: arc == "386"
+
+- name: "set the destination file name locally after download for 64 bit"
+  set_fact:
+    dest_name="{{ openwhisk_cli.remote.dest_name }}-{{ os }}.{{ suffix }}"
+  when: arc == "amd64"
+
+- name: "set the http header used to download the binary packages"
+  set_fact:
+    headers="{{ openwhisk_cli.remote.headers }}"
+  when: openwhisk_cli.remote.headers is defined
+
+- name: "set the http header to empty"
+  set_fact:
+    headers=""
+  when: openwhisk_cli.remote.headers is not defined
+
+- name: "set the instance volume_dir"
+  set_fact:
+    instance: "{{instances | selectattr('name', 'equalto', 'db') | list | first}}"
+    volume_dir: "{{ instance.volume.fsmount | default( '/mnt/' + group_names|first, true ) }}:/usr/local/var/lib/couchdb"
+  when: (block_device is defined) and (block_device in disk_status.stdout)
+
+- name: "ensure Nginx cli directory for ({{ os }}) {{ arc }} exists"
+  file:
+    path: "{{ cli.nginxdir }}/{{ os }}/{{ arc }}"
+    state: directory
+
+- name: "download cli ({{ os }}) {{ arc }} to Nginx directory"
+  get_url:
+    url: "{{ openwhisk_cli.remote.location }}/{{ source_name }}"
+    dest: "{{ cli.nginxdir }}/{{ os }}/{{ arc }}/{{ dest_name }}"
+    headers: "{{ headers }}"
+    mode: 0755
+
+- name: "unarchive cli for Mac and Windows"
+  unarchive:
+    src: "{{ cli.nginxdir }}/{{ os }}/{{ arc }}/{{ dest_name }}"
+    dest: "{{ cli.nginxdir }}/{{ os }}/{{ arc }}/"
+    remote_src: True
+  when: os != "linux"
+
+- name: "unarchive cli for Linux"
+  command: tar -zxvf {{ dest_name }}
+  args:
+    chdir: "{{ cli.nginxdir }}/{{ os }}/{{ arc }}/"
+  when: os == "linux"
+

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].