Update type files for R6
[dcaegen2/deployments.git] / cm-container / README.md
1 # Cloudify Manager Container Builder
2 ## Purpose
3 The artifacts in this directory build a Docker image based on the
4 public image from Cloudify (`cloudifyplatform/community`).  The
5 image has the Cloudify Manager software from the base image
6 and adds our types files.  It configures
7 the import resolver to use our local type files instead
8 of fetching them over the Internet.   It sets up the `/opt/onap` mount point
9 for our config files.  It also sets up the certificate, key and other
10 configuration for using TLS.
11
12 ## Running the Container
13 The container is intended to be launched via a Helm chart as part
14 of the ONAP deployment process, guided by OOM. It can be run directly
15 into a native Docker environment, using:
16 ```
17 docker run --name cfy-mgr -d --restart unless-stopped \
18    -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
19    -p <some_external_port>:80 \
20    --tmpfs /run \
21    --tmpfs /run/lock \
22    --security-opt seccomp:unconfined
23    --cap-add SYS_ADMIN \
24    -v <path_to_kubeconfig_file>:/etc/cloudify/.kube/config
25    -v <path_to_config_file>:/opt/onap/config.txt
26    <image_name>
27 ```
28 In a Kubernetes environment, we expect that the <path_to_kubeconfile_file> and the
29 <path_to_config_file> mounts would be Kubernetes ConfigMaps.
30
31 We also expect that in a Kubernetes environment the external port mapping would not be
32 needed.
33
34 ## Persistent Storage
35 In an ONAP deployment driven by OOM, Cloudify Manager will store data related to its state
36 in a Kubernetes PersistentVolume.  If the Cloudify Manager pod is destroyed and recreated,
37 the new instance will have all of the state information from the previous run.
38
39 To set up persistent storage, we replace the command run by the container (`CMD` in the Dockerfile) with
40 our own script `start-persistent.sh`.  This script checks to see if a persistent volume has been
41 mounted in a well-known place (`/cfy-persist` in the container's file system).  If so, the script
42 then checks to see if the persistent volume has been populated with data.  There are two possibilities:
43 1. The persistent volume hasn't been populated, indicating that this is the first time Cloudify Manager is
44 being run in the current environment.  In this case, the script copies state data from several directories in
45 the container file system into directories in the persistent volume.  This is data (such as database schemas for
46 Cloudify Manager's internal postgres instance) that was generated when the original Cloudify Manager image was
47 created by Cloudify.
48 2. The persistent volume has been populated, indicating that this is not the first time Cloudify Manager is being
49 run in the current environment.   The data in the persistent volume reflects the state that Cloudify Manager was in
50 when it exited at some point in the past.   There's no need to copy data in this case.
51 In either case, the script will create symbolic links from the original data directories to the corresponding directories
52 in the persistent store.
53
54 If there is no persistent volume mounted, the script does nothing to set up persistent data, and the container will have
55 no persistent storage.
56
57 The last command in the script is the command from the original Cloudify version of the Cloudify Manager image. It runs `/sbin/init`,
58 which then brings up the many other processes needed for a working instance of Cloudify Manager.
59
60 ## The `setup-secret.sh` script
61 When Kubernetes starts a container, it mounts a directory containing the credentials that the container needs to access the Kubernetes API on the local Kubernetes cluster.  The mountpoint is `/var/run/secrets/kubernetes.io/serviceaccount`.   Something about the way that Cloudify Manager is started (possibly because `/sbin/init` is run) causes this mountpoint to be hidden.   `setup-secret.sh` will recreated the directory if it's not present and symbolically link it to a copy of the credentials mounted at `/secret` in the container file system.  This gives Cloudify Manager the credentials that the Kubernetes plugin needs to deploy Kubernetes-based DCAE components.
62
63 `setup-secret.sh` needs to run after '/sbin/init'.  The Dockerfile installs it in the `rc.local` script that runs at startup.
64
65 ## Cleaning up Kubernetes components deployed by Cloudify Manager
66 Using the `helm undeploy` (or `helm delete`) command will destroy the Kubernetes components deployed via helm.  In an ONAP deployment
67 driven by OOM, this includes destroying Cloudify Manager.  helm will *not* delete Kubernetes components deployed by Cloudify Manager.
68 This includes components ("microservices") deployed as part of the ONAP installation process by the DCAE bootstrap container as well as
69 components deployed after the initial installation using CLAMP.   Removing *all* of DCAE, including any components deployed by Cloudify
70 Manager, requires running a command before running the `helm undeploy` or `helm delete` command.
71
72 ```kubectl -n _namespace_ exec _cloudify_manager_pod_ /scripts/dcae-cleanup.sh```
73 where _namespace_ is the namespace in which ONAP was deployed and _cloudify_manager_pod_ is the ID of the pod running Cloudify Manager.
74
75 For example:
76 ```
77 $ kubectl -n onap exec dev-dcaegen2-dcae-cloudify-manager-bf885f5bd-hm97x /scripts/dcae-cleanup.sh
78 + set +e
79 ++ grep admin_password: /etc/cloudify/config.yaml
80 ++ cut -d : -f2
81 ++ tr -d ' '
82 + CMPASS=admin
83 + TYPENAMES='[\"dcae.nodes.ContainerizedServiceComponent\",\"dcae.nodes.ContainerizedServiceComponentUsingDmaap\",\"dcae.nodes.ContainerizedPlatformComponent\",\"dcae.nodes.ContainerizedApplication\"]'
84 + xargs -I % sh -c 'cfy executions start -d %  -p '\''{'\''\"type_names\":[\"dcae.nodes.ContainerizedServiceComponent\",\"dcae.nodes.ContainerizedServiceComponentUsingDmaap\",\"dcae.nodes.ContainerizedPlatformComponent\",\"dcae.nodes.ContainerizedApplication\"],\"operation\":\"cloudify.interfaces.lifecycle.stop\"'\''}'\'' execute_operation'
85 + /bin/jq '.items[].id'
86 + curl -Ss --user admin:admin -H 'Tenant: default_tenant' 'localhost/api/v3.1/deployments?_include=id'
87 Executing workflow execute_operation on deployment pgaas_initdb [timeout=900 seconds]
88 2019-03-06 23:06:06.838  CFY <pgaas_initdb> Starting 'execute_operation' workflow execution
89 2019-03-06 23:06:07.518  CFY <pgaas_initdb> 'execute_operation' workflow execution succeeded
90 Finished executing workflow execute_operation on deployment pgaas_initdb
91 * Run 'cfy events list -e c88d5a0a-9699-4077-961b-749384b1e455' to retrieve the execution's events/logs
92 Executing workflow execute_operation on deployment hv-ves [timeout=900 seconds]
93 2019-03-06 23:06:14.928  CFY <hv-ves> Starting 'execute_operation' workflow execution
94 2019-03-06 23:06:15.535  CFY <hv-ves> [hv-ves_dlkit2] Starting operation cloudify.interfaces.lifecycle.stop
95 2019-03-06 23:06:15.535  CFY <hv-ves> [hv-ves_dlkit2.stop] Sending task 'k8splugin.stop_and_remove_container'
96 2019-03-06 23:06:16.554  CFY <hv-ves> [hv-ves_dlkit2.stop] Task started 'k8splugin.stop_and_remove_container'
97 2019-03-06 23:06:20.163  CFY <hv-ves> [hv-ves_dlkit2.stop] Task succeeded 'k8splugin.stop_and_remove_container'
98 2019-03-06 23:06:20.561  CFY <hv-ves> [hv-ves_dlkit2] Finished operation cloudify.interfaces.lifecycle.stop
99 2019-03-06 23:06:21.570  CFY <hv-ves> 'execute_operation' workflow execution succeeded
100 Finished executing workflow execute_operation on deployment hv-ves
101 * Run 'cfy events list -e b4ea6608-befd-421d-9851-94527deab372' to retrieve the execution's events/logs
102 Executing workflow execute_operation on deployment datafile-collector [timeout=900 seconds]
103 2019-03-06 23:06:27.471  CFY <datafile-collector> Starting 'execute_operation' workflow execution
104 2019-03-06 23:06:28.593  CFY <datafile-collector> [datafile-collector_j2b0r4] Starting operation cloudify.interfaces.lifecycle.stop
105 2019-03-06 23:06:28.593  CFY <datafile-collector> [datafile-collector_j2b0r4.stop] Sending task 'k8splugin.stop_and_remove_container'
106 2019-03-06 23:06:28.593  CFY <datafile-collector> [datafile-collector_j2b0r4.stop] Task started 'k8splugin.stop_and_remove_container'
107 2019-03-06 23:06:32.078  CFY <datafile-collector> [datafile-collector_j2b0r4.stop] Task succeeded 'k8splugin.stop_and_remove_container'
108 2019-03-06 23:06:32.609  CFY <datafile-collector> [datafile-collector_j2b0r4] Finished operation cloudify.interfaces.lifecycle.stop
109 2019-03-06 23:06:32.609  CFY <datafile-collector> 'execute_operation' workflow execution succeeded
110 Finished executing workflow execute_operation on deployment datafile-collector
111 * Run 'cfy events list -e 24749c7e-591f-4cac-b127-420b0932ef09' to retrieve the execution's events/logs
112 Executing workflow execute_operation on deployment ves [timeout=900 seconds]
113 ```
114 The exact content of the output will depend on what components have been deployed.  Note that in the example output
115 above, the `pgaas_initdb` node was visited, but no 'stop' operation was sent because `pgaas_initdb` is not a Kubernetes node.
116