You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/02/20 03:40:32 UTC

[GitHub] csantanapr closed pull request #3100: add remote_redirect mode for openwhisk_cli installation

csantanapr closed pull request #3100: add remote_redirect mode for openwhisk_cli installation
URL: https://github.com/apache/incubator-openwhisk/pull/3100
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ansible/group_vars/all b/ansible/group_vars/all
index 78366dd2fc..2af34a2e4b 100644
--- a/ansible/group_vars/all
+++ b/ansible/group_vars/all
@@ -295,11 +295,14 @@ catalog_repos:
 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.
+# installation_mode can be specified into three modes: remote_redirect, remote and local.
+# The mode remote_redirect means to not install the available binaries
+# into the nginx container but to rely on a redirect to an external location.
 # 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.
+# for openwhisk is remote_redirect.
+# NOTE: the remote and local modes are likely to be removed at some future time.
 #
 # The name specifies the package name of the binaries in remote mode.
 #
@@ -310,13 +313,17 @@ openwhisk_cli_tag: "{{ lookup('ini', 'git_tag section=openwhisk-cli file={{ open
 #
 
 openwhisk_cli:
-  installation_mode: "{{ cli_installation_mode | default('remote') }}"
+  installation_mode: "{{ cli_installation_mode | default('remote_redirect') }}"
   local:
     location: "{{ openwhisk_cli_home }}/bin"
   remote:
     name: OpenWhisk_CLI
     dest_name: OpenWhisk_CLI
     location: "https://github.com/apache/incubator-openwhisk-cli/releases/download/{{ openwhisk_cli_tag }}"
+  remote_redirect:
+    package_name: OpenWhisk_CLI
+    location_browse: "https://github.com/apache/incubator-openwhisk-cli/releases/{{ openwhisk_cli_tag }}"
+    location_download: "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.
diff --git a/ansible/roles/cli/tasks/deploy.yml b/ansible/roles/cli/tasks/deploy.yml
index 3961ab84c0..c3cb80def1 100644
--- a/ansible/roles/cli/tasks/deploy.yml
+++ b/ansible/roles/cli/tasks/deploy.yml
@@ -1,14 +1,15 @@
 ---
 # Tasks for handling CLI customization and publishing
 
+- set_fact:
+    cli_installation_mode="{{ openwhisk_cli.installation_mode }}"
+
 - name: "ensure nginx directory for cli exists"
   file:
     path: "{{ cli.nginxdir  }}"
     state: directory
   become: "{{ cli.dir.become }}"
-
-- set_fact:
-    cli_installation_mode="{{ openwhisk_cli.installation_mode }}"
+  when: cli_installation_mode != "remote_redirect"
 
 - include: docker_login.yml
 
@@ -26,3 +27,7 @@
   when: cli_installation_mode == "local"
 
 - include: download_cli.yml
+  when: cli_installation_mode != "remote_redirect"
+
+- include: download_remote_redirect_cli.yml
+  when: cli_installation_mode == "remote_redirect"
diff --git a/ansible/roles/cli/tasks/download_remote_redirect_cli.yml b/ansible/roles/cli/tasks/download_remote_redirect_cli.yml
new file mode 100644
index 0000000000..1d295a846c
--- /dev/null
+++ b/ansible/roles/cli/tasks/download_remote_redirect_cli.yml
@@ -0,0 +1,38 @@
+# Download the cli package from the remote_redirect location to openwhisk_home/bin and unarchive it.
+
+- name: "set the file name to download for linux"
+  set_fact:
+    cli_download_name={{ openwhisk_cli.remote_redirect.package_name }}-{{ openwhisk_cli_tag }}-linux-amd64.tgz
+  when: ('environments/docker-machine' not in inventory_dir) and (ansible_os_family != "Darwin")
+
+- name: "set the file name to download for mac"
+  set_fact:
+    cli_download_name={{ openwhisk_cli.remote_redirect.package_name }}-{{ openwhisk_cli_tag }}-mac-amd64.zip
+  when: ('environments/docker-machine' in inventory_dir ) or (ansible_os_family == "Darwin")
+
+
+- name: "set the http header for downloading the binary packages"
+  set_fact:
+    headers="{{ openwhisk_cli.remote_redirect.headers }}"
+  when: openwhisk_cli.remote_redirect.headers is defined
+
+- name: "set the http header for downloading the binary packages to empty"
+  set_fact:
+    headers=""
+  when: openwhisk_cli.remote_redirect.headers is not defined
+
+
+- name: "download cli package to openwhisk home at {{ openwhisk_home }}"
+  local_action: >
+    get_url
+    url="{{ openwhisk_cli.remote_redirect.location_download }}/{{ cli_download_name }}"
+    headers="{{ headers }}"
+    dest="{{ openwhisk_home }}/bin/{{ cli_download_name }}"
+    mode=0755
+
+- name: "unarchive cli {{ openwhisk_home }}/bin/wsk"
+  local_action: >
+    unarchive
+    src="{{ openwhisk_home }}/bin/{{ cli_download_name }}"
+    dest="{{ openwhisk_home }}/bin"
+    creates="{{ openwhisk_home }}/bin/wsk"
diff --git a/ansible/roles/nginx/templates/nginx.conf.j2 b/ansible/roles/nginx/templates/nginx.conf.j2
index 2212102bc8..3757665c6b 100644
--- a/ansible/roles/nginx/templates/nginx.conf.j2
+++ b/ansible/roles/nginx/templates/nginx.conf.j2
@@ -90,9 +90,25 @@ http {
             return 301 https://github.com/apache/incubator-openwhisk-client-swift/releases/download/0.2.3/starterapp-0.2.3.zip;
         }
 
+{% if openwhisk_cli.installation_mode == "remote_redirect" %}
+        # redirect requests for specific binaries to the matching one from the {{ openwhisk_cli_tag }} openwhisk-cli release.
+  {% for os in cli_os %}
+     {% for arch in cli_arch %}
+        location /cli/go/download/{{ os }}/{{ arch }} {
+            return 301 {{ openwhisk_cli.remote_redirect.location_download }}/{{ openwhisk_cli.remote_redirect.package_name }}-{{ openwhisk_cli_tag }}-{{ os }}-{{ arch }}{% if os == 'linux' %}.tgz{% else %}.zip{% endif %};
+        }
+    {% endfor %}
+  {% endfor %}
+
+        # redirect top-level cli downloads to the {{ openwhisk_cli_tag }} openwhisk-cli release.
+        location /cli/go/download {
+            return 301 {{ openwhisk_cli.remote_redirect.location_browse }};
+         }
+{% else %}
         location /cli/go/download {
             autoindex on;
             root /etc/nginx;
         }
+{% endif %}
     }
 }
diff --git a/ansible/templates/whisk.properties.j2 b/ansible/templates/whisk.properties.j2
index 925c246eec..e58681a687 100644
--- a/ansible/templates/whisk.properties.j2
+++ b/ansible/templates/whisk.properties.j2
@@ -3,6 +3,7 @@ openwhisk.home={{ openwhisk_home }}
 python.27=python
 use.cli.download=false
 nginx.conf.dir={{ nginx.confdir }}
+nginx.cli.redirect={{ openwhisk_cli.installation_mode == "remote_redirect" }}
 testing.auth={{ openwhisk_home }}/ansible/files/auth.guest
 vcap.services.file=
 
diff --git a/tests/src/test/scala/common/WhiskProperties.java b/tests/src/test/scala/common/WhiskProperties.java
index b770c1ba74..116fc5d55c 100644
--- a/tests/src/test/scala/common/WhiskProperties.java
+++ b/tests/src/test/scala/common/WhiskProperties.java
@@ -152,6 +152,10 @@ public static boolean useCLIDownload() {
         return whiskProperties.getProperty("use.cli.download").equals("true");
     }
 
+    public static boolean nginxCLIRedirect() {
+        return whiskProperties.getProperty("nginx.cli.redirect").equalsIgnoreCase("true");
+    }
+
     public static String[] getInvokerHosts() {
         // split of empty string is non-empty array
         String hosts = whiskProperties.getProperty("invoker.hosts");
diff --git a/tests/src/test/scala/system/rest/GoCLINginxTests.scala b/tests/src/test/scala/system/rest/GoCLINginxTests.scala
index a5049a63f5..33640cb40b 100644
--- a/tests/src/test/scala/system/rest/GoCLINginxTests.scala
+++ b/tests/src/test/scala/system/rest/GoCLINginxTests.scala
@@ -27,6 +27,8 @@ import com.jayway.restassured.RestAssured
 import spray.json._
 import DefaultJsonProtocol._
 
+import common.WhiskProperties
+
 /**
  * Basic tests of the download link for Go CLI binaries
  */
@@ -37,8 +39,10 @@ class GoCLINginxTests extends FlatSpec with Matchers with RestUtil {
   val OperatingSystems = List("mac", "linux", "windows")
   val Architectures = List("386", "amd64")
   val ServiceURL = getServiceURL()
+  val remoteRedirect = WhiskProperties.nginxCLIRedirect
 
   it should s"respond to all files in root directory" in {
+    assume(!remoteRedirect)
     val response = RestAssured.given().config(sslconfig).get(s"$ServiceURL/$DownloadLinkGoCli")
     response.statusCode should be(200)
     val responseString = response.body.asString
@@ -54,6 +58,7 @@ class GoCLINginxTests extends FlatSpec with Matchers with RestUtil {
   }
 
   it should "respond to all operating systems and architectures in HTML index" in {
+    assume(!remoteRedirect)
     val responseJSON = RestAssured.given().config(sslconfig).get(s"$ServiceURL/$DownloadLinkGoCli/content.json")
     responseJSON.statusCode should be(200)
     val cli = responseJSON.body.asString.parseJson.asJsObject
@@ -74,6 +79,7 @@ class GoCLINginxTests extends FlatSpec with Matchers with RestUtil {
   }
 
   it should "respond to the download paths in content.json" in {
+    assume(!remoteRedirect)
     val response = RestAssured.given().config(sslconfig).get(s"$ServiceURL/$DownloadLinkGoCli/content.json")
     response.statusCode should be(200)
     val cli =
@@ -82,4 +88,28 @@ class GoCLINginxTests extends FlatSpec with Matchers with RestUtil {
       RestAssured.given().config(sslconfig).get(s"$ServiceURL/$DownloadLinkGoCli/$path").statusCode should be(200)
     }
   }
+
+  it should s"check redirect for root directory request" in {
+    assume(remoteRedirect)
+    val response =
+      RestAssured.given().config(sslconfig).redirects().follow(false).get(s"$ServiceURL/$DownloadLinkGoCli")
+    response.statusCode should be(301)
+    response.header("Location") should include("https://github.com/apache/incubator-openwhisk-cli/releases")
+  }
+
+  it should "check redirect exists for all operating system and architecture pairs" in {
+    assume(remoteRedirect)
+    for (os <- OperatingSystems) {
+      for (arch <- Architectures) {
+        val response = RestAssured
+          .given()
+          .config(sslconfig)
+          .redirects()
+          .follow(false)
+          .get(s"$ServiceURL/$DownloadLinkGoCli/$os/$arch")
+        response.statusCode should be(301)
+        response.header("Location") should include(s"$os-$arch")
+      }
+    }
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services