You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2017/09/15 23:31:32 UTC

[incubator-openwhisk] branch master updated: Support docker for mac using the 'local' environment (#2686)

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

rabbah 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 929c84f  Support docker for mac using the 'local' environment (#2686)
929c84f is described below

commit 929c84f778eecb3cced46816d2e4487069970a03
Author: Carlos Santana <cs...@gmail.com>
AuthorDate: Fri Sep 15 19:31:29 2017 -0400

    Support docker for mac using the 'local' environment (#2686)
---
 ansible/README.md                                  | 37 ++++++++------
 ansible/environments/distributed/group_vars/all    |  2 +-
 ansible/environments/mac/group_vars/all            | 26 ----------
 ansible/environments/mac/hosts                     | 28 -----------
 ansible/logs.yml                                   | 13 +++--
 ansible/roles/cli/tasks/download_cli.yml           |  6 +--
 ansible/roles/invoker/tasks/deploy.yml             | 56 ++++++++++++++++++----
 core/nodejs6Action/Dockerfile                      |  1 +
 core/php7.1Action/Dockerfile                       |  2 +-
 .../scala/actionContainers/ActionContainer.scala   |  4 +-
 tools/build/redo                                   |  2 +-
 tools/macos/README.md                              |  4 +-
 tools/macos/docker-machine/README.md               |  2 +-
 tools/ubuntu-setup/ansible.sh                      |  2 +
 14 files changed, 92 insertions(+), 93 deletions(-)

diff --git a/ansible/README.md b/ansible/README.md
index 0ae63e7..60e4a84 100644
--- a/ansible/README.md
+++ b/ansible/README.md
@@ -30,18 +30,7 @@ You need to depend on the workarounds until Docker provides official methods.
 If you prefer [Docker-machine](https://docs.docker.com/machine/) to [Docker for mac](https://docs.docker.com/docker-for-mac/), you can follow instructions in [docker-machine/README.md](../tools/macos/docker-machine/README.md).
 
 ##### Enable Docker remote API
-
-During the deployment steps, each component communicates with Docker via Docker remote API.
-Currently however, Docker for Mac does not support such a feature.
-
-There are many workarounds for this.
-One way is to use `socat` command to setup proxy for the UNIX socket.
-
-```
-docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 4243:2375 bobrik/socat TCP4-LISTEN:2375,fork,reuseaddr UNIX-CONNECT:/var/run/docker.sock
-```
-
-If you want to deploy OpenWhisk in distributed environment, you are required to enable Docker remote API in all Mac hosts.
+The remote Docker API is required for collecting logs using the Ansible playbook [logs.yml](logs.yml).
 
 ##### Activate docker0 network
 This is an optional step for local deployment.
@@ -74,8 +63,11 @@ systemProp.http.proxyPort=3128
 **Caveat:** All Ansible commands are meant to be executed from the `ansible` directory.
 This is important because that's where `ansible.cfg` is located which contains generic settings that are needed for the remaining steps.
 
-In all instructions, replace `<environment>` with your target environment. e.g. `mac`if you want to deploy using a local mac setup.
-By default, if you omit the `-i` parameter, the `local` environment will be used.
+In all instructions, replace `<environment>` with your target environment. The default environment is `local` which works for Ubuntu and
+Docker for Mac. To use the default environment, you may omit the `-i` parameter entirely. For older Mac installation using Docker Machine,
+use `-i environments/docker-machine`.
+
+
 
 In all instructions, replace `<openwhisk_home>` with the base directory of your OpenWhisk source tree. e.g. `openwhisk`
 
@@ -125,7 +117,9 @@ ansible-playbook -i environments/<environment> setup.yml
 ```
 
 #### Install Prerequisites
-This step needs to be done only once per target environment (in a local setup the development environment and the target environment are the same). It will install necessary prerequisites on all target hosts in the environment.
+This step is not required for local environments since all prerequisites are already installed, and therefore may be skipped.`
+
+This step needs to be done only once per target environment. It will install necessary prerequisites on all target hosts in the environment.
 
 ```
 ansible-playbook -i environments/<environment> prereq.yml
@@ -269,6 +263,19 @@ Alternatively, you can also configure the location of Python interpreter in `env
 ansible_python_interpreter: "/usr/local/bin/python"
 ```
 
+#### Failed to import docker-py
+
+After `brew install ansible`, the following lines are printed out:
+
+```
+==> Caveats
+If you need Python to find the installed site-packages:
+  mkdir -p ~/Library/Python/2.7/lib/python/site-packages
+  echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
+```
+  
+Just run the two commands to fix this issue.
+
 #### Spaces in Paths
 Ansible 2.1.0.0 and earlier versions do not support a space in file paths.
 Many file imports and roles will not work correctly when included from a path that contains spaces.
diff --git a/ansible/environments/distributed/group_vars/all b/ansible/environments/distributed/group_vars/all
index ba0622c..5335800 100755
--- a/ansible/environments/distributed/group_vars/all
+++ b/ansible/environments/distributed/group_vars/all
@@ -7,7 +7,7 @@ db_password: couch_password
 db_host: "{{ groups['db'] | first }}"
 db_prefix: whisk_distributed_
 
-whisk_version_name: local
+whisk_version_name: distributed
 config_root_dir: /tmp
 whisk_logs_dir: /tmp/wsklogs
 registry_storage_dir: "/"
diff --git a/ansible/environments/mac/group_vars/all b/ansible/environments/mac/group_vars/all
deleted file mode 100755
index 9dae69c..0000000
--- a/ansible/environments/mac/group_vars/all
+++ /dev/null
@@ -1,26 +0,0 @@
-whisk_version_name: mac
-config_root_dir: /Users/Shared
-whisk_logs_dir: /Users/Shared/wsklogs
-docker_registry: ""
-docker_dns: ""
-
-db_prefix: whisk_mac_
-
-# Auto lookup to find the db credentials
-db_provider: "{{ lookup('ini', 'db_provider section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
-db_username: "{{ lookup('ini', 'db_username section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
-db_password: "{{ lookup('ini', 'db_password section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
-db_protocol: "{{ lookup('ini', 'db_protocol section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
-db_host: "{{ lookup('ini', 'db_host section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
-db_port: "{{ lookup('ini', 'db_port section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
-
-# API GW connection configuration
-apigw_auth_user: ""
-apigw_auth_pwd: ""
-apigw_host: "http://{{ groups['apigateway']|first }}:{{apigateway.port.api}}/v1"
-apigw_host_v2: "http://{{ groups['apigateway']|first }}:{{apigateway.port.api}}/v2"
-
-controller_arguments: '-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1098'
-invoker_arguments: "{{ controller_arguments }}"
-
-invoker_allow_multiple_instances: true
diff --git a/ansible/environments/mac/hosts b/ansible/environments/mac/hosts
deleted file mode 100644
index 00702f3..0000000
--- a/ansible/environments/mac/hosts
+++ /dev/null
@@ -1,28 +0,0 @@
-; the first parameter in a host is the inventory_hostname
-
-; used for local actions only
-ansible ansible_connection=local
-
-[edge]
-172.17.0.1          ansible_host=172.17.0.1 ansible_connection=local
-
-[controllers]
-controller0         ansible_host=172.17.0.1 ansible_connection=local
-controller1         ansible_host=172.17.0.1 ansible_connection=local
-
-[kafka]
-172.17.0.1          ansible_host=172.17.0.1 ansible_connection=local
-
-[invokers]
-invoker0            ansible_host=172.17.0.1 ansible_connection=local
-invoker1            ansible_host=172.17.0.1 ansible_connection=local
-
-; db group is only used if db_provider is CouchDB
-[db]
-172.17.0.1          ansible_host=172.17.0.1 ansible_connection=local
-
-[redis]
-172.17.0.1          ansible_host=172.17.0.1 ansible_connection=local
-
-[apigateway]
-172.17.0.1          ansible_host=172.17.0.1 ansible_connection=local
diff --git a/ansible/logs.yml b/ansible/logs.yml
index edcf192..86cc2c2 100644
--- a/ansible/logs.yml
+++ b/ansible/logs.yml
@@ -27,11 +27,18 @@
 - hosts: all:!ansible
   serial: 1
   tasks:
+  - name: init var docker_host_flag
+    set_fact:
+      docker_host_flag: ""
+  - name: set host flag when using docker remote API
+    set_fact:
+      docker_host_flag: "--host tcp://{{ ansible_host }}:{{ docker.port }}"
+    when: whisk_version_name != "local"
   - name: get all docker containers
-    local_action: shell docker --host tcp://{{ ansible_host }}:{{ docker.port }} ps -a --format="{% raw %}{{.Names}}{% endraw %}"
+    local_action: shell docker {{ docker_host_flag }} ps -a --format="{% raw %}{{.Names}}{% endraw %}"
     register: container_names
   - name: get logs from all containers
-    local_action: shell docker --host tcp://{{ ansible_host }}:{{ docker.port }} logs {{ item }} > "{{ openwhisk_home }}/logs/{{ item }}.log"; exit 0
+    local_action: shell docker  {{ docker_host_flag }} logs {{ item }} > "{{ openwhisk_home }}/logs/{{ item }}.log"; exit 0
     with_items: "{{ container_names.stdout_lines | difference('whisk_docker_registry') }}"
     when: "'docker' not in exclude_logs_from"
   - name: workaround to make synchronize work
@@ -40,4 +47,4 @@
     when: ansible_ssh_private_key_file is defined
   - name: fetch logs from all machines
     synchronize: src="{{ whisk_logs_dir }}/" dest="{{ openwhisk_home }}/logs" mode=pull
-    when: "'machine' not in exclude_logs_from"
+    when: ('machine' not in exclude_logs_from) and (whisk_version_name != "local")
\ No newline at end of file
diff --git a/ansible/roles/cli/tasks/download_cli.yml b/ansible/roles/cli/tasks/download_cli.yml
index 0e9c5c2..6024b06 100644
--- a/ansible/roles/cli/tasks/download_cli.yml
+++ b/ansible/roles/cli/tasks/download_cli.yml
@@ -10,9 +10,9 @@
     mode=0755
     validate_certs=False
     force=True
-  when: "'environments/docker-machine' not in inventory_dir and 'environments/mac' not in inventory_dir"
+  when: ('environments/docker-machine' not in inventory_dir) and (ansible_os_family != "Darwin")
 
-- name: "download cli (docker-machine) to openwhisk home at {{ openwhisk_home }}"
+- name: "download cli for mac (docker-machine or Docker for Mac) to openwhisk home at {{ openwhisk_home }}"
   local_action: >
     get_url
     url="https://{{ groups['edge'] | first }}/cli/go/download/mac/amd64/wsk"
@@ -20,4 +20,4 @@
     mode=0755
     validate_certs=False
     force=True
-  when: "'environments/docker-machine' in inventory_dir or 'environments/mac' in inventory_dir"
+  when: ('environments/docker-machine' in inventory_dir ) or (ansible_os_family == "Darwin")
diff --git a/ansible/roles/invoker/tasks/deploy.yml b/ansible/roles/invoker/tasks/deploy.yml
index 8b6536e..5cac803 100644
--- a/ansible/roles/invoker/tasks/deploy.yml
+++ b/ansible/roles/invoker/tasks/deploy.yml
@@ -26,9 +26,25 @@
   retries: "{{ docker.pull.retries }}"
   delay: "{{ docker.pull.delay }}"
 
-- name: determine docker root dir
+- name: "determine docker root dir on docker-machine"
   uri:  url="http://{{ ansible_host }}:{{ docker.port }}/info" return_content=yes
-  register: dockerInfo
+  register: dockerInfo_output
+  when: whisk_version_name == "mac"
+
+- set_fact:
+    dockerInfo: "{{ dockerInfo_output['json'] }}"
+  when: whisk_version_name == "mac"
+
+- name: "determine docker root dir"
+  shell: echo -e "GET http:/v1.24/info HTTP/1.0\r\n" | nc -U /var/run/docker.sock | grep "{"
+  args:
+    executable: /bin/bash
+  register: dockerInfo_output
+  when: whisk_version_name != "mac"
+
+- set_fact:
+    dockerInfo: "{{ dockerInfo_output.stdout|from_json }}"
+  when: whisk_version_name != "mac"
 
 - name: ensure invoker log directory is created with permissions
   file:
@@ -40,23 +56,43 @@
 - name: define options when deploying invoker on Ubuntu
   set_fact:
     linuxOptions: "-v /usr/lib/x86_64-linux-gnu/libapparmor.so.1:/usr/lib/x86_64-linux-gnu/libapparmor.so.1"
-  when: whisk_version_name != "mac"
+  when: ansible_distribution == "Ubuntu"
 
 - name: get running invoker information
-  uri:
-    url: "http://{{ ansible_host }}:{{ docker.port }}/containers/json?filters={{ '{\"name\":[ \"invoker\" ],\"ancestor\":[ \"invoker\" ]}' | urlencode }}"
-    return_content: yes
-  register: invokerInfo
+  uri: url="http://{{ ansible_host }}:{{ docker.port }}/containers/json?filters={{ '{"name":[ "invoker" ],"ancestor":[ "invoker" ]}' | urlencode }}" return_content=yes
+  register: invokerInfo_output
+  when: whisk_version_name == "mac"
+
+- set_fact:
+    invokerInfo: "{{ invokerInfo_output['json'] }}"
+  when: whisk_version_name == "mac"
+
+- name: "get invoker info"
+  shell: |
+    INFO=`echo -e "GET http:/v1.24/containers/json?filters={{ '{"name":[ "invoker" ],"ancestor":[ "invoker" ]}' | urlencode }} HTTP/1.0\r\n" | nc -U /var/run/docker.sock | grep "{"`
+    if [ -z "$INFO" ]; then
+      echo []
+    else
+      echo $INFO
+    fi
+  args:
+    executable: /bin/bash
+  register: invokerInfo_output
+  when: whisk_version_name != "mac"
+
+- set_fact:
+    invokerInfo: "{{ invokerInfo_output.stdout|from_json }}"
+  when: whisk_version_name != "mac"
 
 - name: determine if more than one invoker is running
   fail:
     msg: "more than one invoker is running"
-  when: not invoker.allowMultipleInstances and invokerInfo.json|length > 1
+  when: not invoker.allowMultipleInstances and invokerInfo|length > 1
 
 - name: determine if index of invoker is same with index of inventory host
   fail:
     msg: "invoker index is invalid. expected: /invoker{{ groups['invokers'].index(inventory_hostname) }} found: {{ item.Names[0] }}"
-  with_items: "{{ invokerInfo.json }}"
+  with_items: "{{ invokerInfo }}"
   when: not invoker.allowMultipleInstances and item.Names[0] != "/invoker{{ groups['invokers'].index(inventory_hostname) }}"
 
 - name: start invoker using docker cli
@@ -99,7 +135,7 @@
         -v /sys/fs/cgroup:/sys/fs/cgroup
         -v /run/runc:/run/runc
         -v {{ whisk_logs_dir }}/invoker{{ groups['invokers'].index(inventory_hostname) }}:/logs
-        -v {{ dockerInfo["json"]["DockerRootDir"] }}/containers/:/containers
+        -v {{ dockerInfo["DockerRootDir"] }}/containers/:/containers
         -v {{ docker_sock | default('/var/run/docker.sock') }}:/var/run/docker.sock
         -p {{ invoker.port + groups['invokers'].index(inventory_hostname) }}:8080
         {{ docker_registry }}{{ docker.image.prefix }}/invoker:{{ docker.image.tag }}
diff --git a/core/nodejs6Action/Dockerfile b/core/nodejs6Action/Dockerfile
index 8863b0f..347ea00 100644
--- a/core/nodejs6Action/Dockerfile
+++ b/core/nodejs6Action/Dockerfile
@@ -74,5 +74,6 @@ xml2js@0.4.17 \
 xmlhttprequest@1.8.0 \
 yauzl@2.7.0
 
+
 # See app.js
 CMD node --expose-gc app.js
diff --git a/core/php7.1Action/Dockerfile b/core/php7.1Action/Dockerfile
index a37ed52..f3cd93f 100644
--- a/core/php7.1Action/Dockerfile
+++ b/core/php7.1Action/Dockerfile
@@ -46,5 +46,5 @@ COPY router.php /action
 COPY runner.php /action
 
 # Run webserver on port 8080
-EXPOSE 8080
+
 CMD [ "php", "-S", "0.0.0.0:8080", "-d", "expose_php=0", "-d", "html_errors=0", "-d", "error_reporting=E_ALL", "/action/router.php" ]
diff --git a/tests/src/test/scala/actionContainers/ActionContainer.scala b/tests/src/test/scala/actionContainers/ActionContainer.scala
index 63da8c7..f60cbfe 100644
--- a/tests/src/test/scala/actionContainers/ActionContainer.scala
+++ b/tests/src/test/scala/actionContainers/ActionContainer.scala
@@ -90,7 +90,9 @@ object ActionContainer {
   }
 
   private lazy val dockerCmd: String = {
-    val hostStr = if (WhiskProperties.onMacOSX()) {
+    val version = WhiskProperties.getProperty("whisk.version.name")
+    // Check if we are running on docker-machine env.
+    val hostStr = if (version.toLowerCase().contains("mac")) {
       s" --host tcp://${WhiskProperties.getMainDockerEndpoint()} "
     } else {
       " "
diff --git a/tools/build/redo b/tools/build/redo
index cfe2a21..3794751 100755
--- a/tools/build/redo
+++ b/tools/build/redo
@@ -205,7 +205,7 @@ Components = [
     makeComponent('fresh',
                   'setup, build, and deploy a fresh whisk system using couchdb',
                   yaml = False,
-                  steps = 'setup, prereq, couchdb, initdb, wipedb, deploy, catalog'),
+                  steps = 'setup, couchdb, initdb, wipedb, deploy, catalog'),
 
     makeComponent('fmt',
                   'apply source code formats',
diff --git a/tools/macos/README.md b/tools/macos/README.md
index 7eb3a5b..4314d08 100644
--- a/tools/macos/README.md
+++ b/tools/macos/README.md
@@ -29,10 +29,8 @@ brew cask install java
 brew install scala
 # install pip
 sudo easy_install pip
-# install docker for python
-/usr/local/bin/pip install docker==2.2.1
 # install script prerequisites
-sudo -H pip install ansible==2.3.0.0 jinja2==2.9.6 couchdb' | bash
+sudo -H pip install docker==2.2.1 ansible==2.3.0.0 jinja2==2.9.6 couchdb==1.1 httplib2==0.9.2 requests==2.10.0' | bash
 ```
 
 # Build
diff --git a/tools/macos/docker-machine/README.md b/tools/macos/docker-machine/README.md
index ec33347..602f813 100644
--- a/tools/macos/docker-machine/README.md
+++ b/tools/macos/docker-machine/README.md
@@ -37,7 +37,7 @@ brew install scala
 # install pip
 sudo easy_install pip
 # install script prerequisites
-sudo -H pip install ansible==2.3.0.0 jinja2==2.9.6 couchdb' | bash
+sudo -H pip install docker==2.2.1 ansible==2.3.0.0 jinja2==2.9.6 couchdb==1.1 httplib2==0.9.2 requests==2.10.0' | bash
 ```
 
 # Create and configure Docker machine
diff --git a/tools/ubuntu-setup/ansible.sh b/tools/ubuntu-setup/ansible.sh
index 2a58e7d..20c500e 100755
--- a/tools/ubuntu-setup/ansible.sh
+++ b/tools/ubuntu-setup/ansible.sh
@@ -10,6 +10,8 @@ sudo pip install markupsafe
 sudo pip install ansible==2.3.0.0
 sudo pip install docker==2.2.1
 sudo pip install jinja2==2.9.6
+sudo pip install httplib2==0.9.2
+sudo pip install requests==2.10.0
 
 ansible --version
 ansible-playbook --version
\ No newline at end of file

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