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/13 20:24:21 UTC

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

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 be6682a  Add the support to install the binaries from the new repo (#2345)
be6682a is described below

commit be6682a9df3bbf871b29ef51b3944f1a9c3d67a3
Author: Vincent <sh...@us.ibm.com>
AuthorDate: Tue Jun 13 16:24:18 2017 -0400

    Add the support to install the binaries from the new repo (#2345)
    
    * 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 build the
    binaries locally.
    
    The key installation_mode of openwhisk_cli dict can be set to
    download, meaning to download the binaries, or build, meaning
    to build the binaries locally. The default value is download.
    
    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 ++++++
 ansible/roles/cli/tasks/deploy.yml                 | 24 +++-----
 ansible/roles/cli/tasks/download_cli.yml           |  2 +
 ansible/roles/cli/tasks/download_openwhisk_cli.yml | 70 ++++++++++++++++++++++
 tools/vagrant/Vagrantfile                          |  1 -
 8 files changed, 214 insertions(+), 16 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 59ef946..b0540f8 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(playbook_dir + '/../../incubator-openwhisk-cli', true) }}"
 exclude_logs_from: []
 
 # This whisk_api_localhost_name_default is used to configure nginx to permit vanity URLs for web actions
@@ -228,3 +229,46 @@ catalog_repos:
     location: "{{ openwhisk_home }}/../openwhisk-catalog"
     version: "HEAD"
     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 get the binaries
+# from a local directory. The default value for openwhisk is remote.
+#
+# 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: remote
+  name: OpenWhisk_CLI
+  dest_name: OpenWhisk_CLI
+  location: "https://github.com/apache/incubator-openwhisk-cli/releases/download/{{ openwhisk_cli_tag }}"
+
+# If you would like to use the binaries available locally, e.g. the binaries generated in the development
+# environment, you can uncomment the following section to use the local mode. Please be advised that the
+# binaries are generated and the location is set correctly before running the ansible scripts.
+#
+#openwhisk_cli:
+#  installation_mode: local
+#  location: "{{ openwhisk_cli_home }}/bin"
+
+# 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_arc:
+  - 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..ddacdf5
--- /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_arc }}"
+
+- 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.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/deploy.yml b/ansible/roles/cli/tasks/deploy.yml
index 1bf872d..58e000d 100644
--- a/ansible/roles/cli/tasks/deploy.yml
+++ b/ansible/roles/cli/tasks/deploy.yml
@@ -6,23 +6,17 @@
     path: "{{ cli.nginxdir  }}"
     state: directory
 
-- include: docker_login.yml
-
-- name: "pull the {{ docker_image_tag }} image of cli"
-  shell: "docker pull {{ docker_registry }}{{ docker_image_prefix }}/cli:{{ docker_image_tag }}"
-  when: docker_registry != ""
+- set_fact:
+    cli_installation_mode="{{ openwhisk_cli.installation_mode }}"
 
-- name: "run Docker"
-  shell: "docker run --name cli {{ docker_registry }}{{ docker_image_prefix }}/cli:{{ docker_image_tag }}"
-
-- name: "copy all the cli binaries into nginx"
-  shell: "docker cp cli:/src/github.com/go-whisk-cli/build/. '{{ cli.nginxdir }}'"
-  ignore_errors: yes
+- include: docker_login.yml
 
-- name: "stop Docker"
-  shell: "docker stop cli"
+- name: "download the binaries for the remote mode"
+  include: cli_remote_mode.yml
+  when: cli_installation_mode == "remote"
 
-- 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.location }}/ 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 df18b3d..27a2735 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/mac' not in inventory_dir"
 
 - name: "download cli (mac) to openwhisk home at {{ openwhisk_home }}"
@@ -18,4 +19,5 @@
     dest="{{ openwhisk_home }}/bin/wsk"
     mode=0755
     validate_certs=False
+    force=True
   when: "'environments/mac' 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..9b53e89
--- /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.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.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.dest_name }}-{{ os }}.{{ suffix }}"
+  when: arc == "amd64"
+
+- name: "set the http header used to download the binary packages"
+  set_fact:
+    headers="{{ openwhisk_cli.headers }}"
+  when: openwhisk_cli.headers is defined
+
+- name: "set the http header to empty"
+  set_fact:
+    headers=""
+  when: openwhisk_cli.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.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"
+
diff --git a/tools/vagrant/Vagrantfile b/tools/vagrant/Vagrantfile
index 3ab2bba..33bd5a7 100644
--- a/tools/vagrant/Vagrantfile
+++ b/tools/vagrant/Vagrantfile
@@ -137,7 +137,6 @@ $script_end = <<SCRIPT
   source /etc/environment
   # Build OpenWhisk using gradle
   cd ${OPENWHISK_HOME}
-  su vagrant -c './gradlew  tools:cli:distDocker -PdockerImagePrefix=openwhisk'
 
   echo "`date`: deploy-start" >> /tmp/vagrant-times.txt
   # Deploy OpenWhisk using ansible

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