├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── Vagrantfile ├── postman ├── README.md ├── usergrid.json.postman_collection └── usergrid.json.postman_environment ├── provision ├── README.md ├── aws-provision.sh ├── cloudconfig.yaml └── provision.sh └── usergrid ├── Dockerfile └── run.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | sourcetreeconfig 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "elasticsearch"] 2 | path = elasticsearch 3 | url = https://github.com/yep/usergrid-elasticsearch 4 | [submodule "java"] 5 | path = java 6 | url = https://github.com/yep/usergrid-java 7 | [submodule "cassandra"] 8 | path = cassandra 9 | url = https://github.com/yep/usergrid-cassandra 10 | [submodule "portal"] 11 | path = portal 12 | url = https://github.com/yep/usergrid-portal 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Usergrid on Docker 2 | ================== 3 | 4 | A collection of containers to run [Usergrid](https://usergrid.apache.org) on [Docker](https://www.docker.com). 5 | 6 | There are the following containers: 7 | 8 | - Java - Ubuntu base image with Oracle JVM version 8, [github](https://github.com/yep/usergrid-java), [automated build](https://hub.docker.com/r/yep1/usergrid-java), MIT license 9 | - Cassandra - version 2.1, [github](https://github.com/yep/usergrid-cassandra), [automated build](https://hub.docker.com/r/yep1/usergrid-cassandra/) 10 | - Elasticsearch - version 1.7, [github](https://github.com/yep/usergrid-elasticsearch), [automated build](https://hub.docker.com/r/yep1/usergrid-elasticsearch/), MIT license 11 | - Usergrid - version 2.1, [github](https://github.com/yep/usergrid-docker), [automated build](https://hub.docker.com/r/yep1/usergrid) 12 | - Usergrid Admin Portal - version 2.1, [github](https://github.com/yep/usergrid-portal), [automated build](https://hub.docker.com/r/yep1/usergrid-portal) 13 | 14 | To see how the containers can be started, have a look at the `provision.sh` script from the `provision` directory. 15 | 16 | Local testing using [Vagrant](http://vagrantup.com) and deployment to [Amazon Web Services (AWS)](http://aws.amazon.com) are supported, see below. 17 | 18 | 19 | Run on Vagrant 20 | --------------- 21 | 22 | To get started quickly, it is recommended to use Vagrant. 23 | 24 | Install the following dependencies: 25 | 26 | - [Virtualbox](http://virtualbox.org) 27 | - [Vagrant](http://vagrantup.com) 28 | 29 | On windows, you may additionally have to install `rsync` and `ssh` using something like [mingw](http://www.mingw.org) or [cygwin](http://www.cygwin.com). 30 | 31 | In the `Vagrantfile`, set the IP for your Vagrant VM. Use an unassigned IP reachable in your local network: 32 | 33 | ip = YOUR_IP 34 | 35 | Then, in the root directory of the repository run: 36 | 37 | vagrant up 38 | 39 | This should automatically download and start an instance of [CoreOS](http://coreos.com). 40 | 41 | Usergrid API should be available on port 8080 and the admin portal at port 80. 42 | 43 | Usergrid status at `YOUR_IP:8080/status` should show for cassandra `"cassandraAvailable" : true`, `"cassandraStatus" : "GREEN"` and for elasticsearch `"managementAppIndexStatus" : "YELLOW"`. 44 | 45 | If you make any changes to the configuration, update the files inside the VM and restart the containers with 46 | 47 | vagrant rsync && vagrant provision 48 | 49 | Using Vagrant, it is simple to start up multiple virtual machines (VMs) simulatenously by changing the `num_instances` parameter in the `Vagrantfile`. You can also adjust the `vb_memory` and `vb_cpu` parameters to change the amount of memory and number of CPUs available to the VM. 50 | 51 | 52 | Run manually 53 | ------------ 54 | 55 | Instead of using Vagrant, you can use Docker directly. If you are not using Linux on your development machine, it is recommended to install the [Docker Toolbox](https://www.docker.com/products/overview#/docker_toolbox). 56 | 57 | The examples below use the automated builds from the [Docker Hub](https://hub.docker.com). 58 | 59 | Start Cassandra and Elasticsearch: 60 | 61 | docker run --detach --name cassandra --volume $(pwd)/cassandra-data:/var/lib/cassandra yep1/usergrid-cassandra 62 | docker run --detach --name elasticsearch --volume $(pwd)/elasticsearch-data:/data yep1/usergrid-elasticsearch 63 | 64 | Start Usergrid, configuration is done using environment variables (--env). For a list all configuration variables, see below: 65 | 66 | docker run --detach --name usergrid --env ADMIN_PASS=password --env ORG_NAME=org --env APP_NAME=app --link elasticsearch:elasticsearch --link cassandra:cassandra -p 8080:8080 yep1/usergrid 67 | 68 | Start the Usergrid admin portal, change 192.168.1.34:8080 to match the public reachable IP and port of the Usergrid container 69 | 70 | docker run --env USERGRID_HOST=192.168.1.34:8080 -p 80:80 yep1/usergrid-portal 71 | 72 | 73 | Environment Variables 74 | --------------------- 75 | 76 | The following [environment variables](http://docs.docker.com/userguide/dockerlinks/#environment-variables) are used to access [backing services](http://12factor.net/backing-services) in scripts of the usergrid container. The names of the Cassandra and Elasticsearch containers can not be changed or you also have to change the names of the environment variables below. 77 | 78 | CASSANDRA_PORT_9160_TCP_ADDR 79 | CASSANDRA_PORT_9160_TCP_PORT 80 | ELASTICSEARCH_PORT_9300_TCP_ADDR 81 | ELASTICSEARCH_PORT_9300_TCP_PORT 82 | 83 | Configuration variables for the `usergrid` container: 84 | 85 | ADMIN_USER 86 | ADMIN_PASS 87 | ADMIN_MAIL 88 | ORG_NAME 89 | APP_NAME 90 | CASSANDRA_CLUSTER_NAME 91 | USERGRID_CLUSTER_NAME 92 | TOMCAT_RAM 93 | 94 | Configuration variables for the `cassandra` container: 95 | 96 | CASSANDRA_CLUSTER_NAME 97 | CASSANDRA_LISTEN_ADDRESS 98 | CASSANDRA_SEEDS 99 | CASSANDRA_RPC_ADDRESS 100 | CASSANDRA_BROADCAST_RPC_ADDRESS 101 | 102 | Configuration variables for the `portal` container: 103 | 104 | USERGRID_HOST 105 | 106 | 107 | Build 108 | ----- 109 | 110 | Build the containers manually instead of using the automated builds. 111 | 112 | Get the submodules first: 113 | 114 | git clone https://github.com/yep/usergrid-docker.git 115 | cd usergrid-docker 116 | git submodule update --init 117 | 118 | Then, build the java base container: 119 | 120 | cd java && build -t usergrid-java . 121 | 122 | The java container is used by all other containers. By default, automated build of the java container is used. Therefore, in each `Dockerfile` change `FROM yep1/usergrid-java` to `FROM usergrid-java` to use the local java container you just created. 123 | 124 | Finally, build the containers: 125 | 126 | cd cassandra && build -t usergrid-cassandra . 127 | cd elasticsearch && build -t usergrid-elasticsearch . 128 | cd usergrid && build -t usergrid . 129 | cd portal && build -t usergrid-portal . 130 | 131 | Start the containers as shown in section `Usage`, but remove the prefix `yep1/` from the image name to use your local builds. 132 | 133 | 134 | Run on AWS 135 | ---------- 136 | 137 | Deployment to Amazon Web Services [(AWS)](http://aws.amazon.com) can be done using the `aws-deploy.sh` script from the `provision` directory. 138 | 139 | Getting started: 140 | 141 | - Generate key pair in the aws console or add a locally generated key pair 142 | - Create a user called `usergrid` in IAM, download the credentials and attach the `AmazonSQSFullAccess` policy 143 | - Start the latest stable CoreOS community ami with hvm (hardware virtualization) of size `m3.medium`. At time of writing, latest is `ami-0e300d13` called `CoreOS-stable-607.0.0-hvm` 144 | - Set up an SSH alias called `aws` so you can ssh into the machine by typing `ssh aws` without entering a password 145 | - Run `aws-provision.sh` 146 | 147 | Apple push notification (apns) setup note: 148 | 149 | When generating the `notifier` in usergrid, a .p12 certificate is required. 150 | 151 | To create this .p12 certificate, you have to select BOTH the private key (of type `private key`) and the public key signed by Apple (of type `certificate`) in the Apple keychain OSX app at the same time and then export both of them into one .p12 file. 152 | 153 | 154 | Usergrid Documentation 155 | ---------------------- 156 | 157 | * [Usergrid Backend as a Service (BaaS) Documentation](http://apigee.com/docs/api-baas/content/build-apps-home) 158 | * [Usergrid REST Endpoints](http://apigee.com/docs/app-services/content/rest-endpoints) 159 | 160 | 161 | Postman 162 | ------- 163 | 164 | For debugging of REST commands, you can use [Postman](http://getpostman.com). 165 | 166 | Import the postman collection `usergrid.json.postman_collection` and environment `usergrid.json.postman_environment` from the `postman` directory. 167 | 168 | To use `postman`, request an API token using one of the provided commands and set the `token` parameter in the `environment` of `postman` accordingly. Also set the `ip` parameter in the environment. 169 | 170 | 171 | Usage 172 | ----- 173 | 174 | Some useful `vagrant` commands: 175 | 176 | * `vagrant up` - start VM 177 | * `vagrant ssh` - ssh into VM 178 | * `vagrant halt` - stop VM 179 | * `vagrant destroy` - remove VM, run `vagrant up` to start from scratch 180 | * `vagrant rsync` - update shared folder using rsync 181 | * `vagrant provision` - run the provion script from the Vagrantfile 182 | * `vagrant box update` - update CoreOS base box 183 | 184 | Some useful `docker` commands, run these from inside of the VM: 185 | 186 | * `docker build -t usergrid .` - build the dockerfile in the current directory and tag the container with `usergrid` 187 | * `docker run -d --name usergrid --link elasticsearch:elasticsearch --link cassandra:cassandra -t usergrid` - run the container which was built with the above command in the background (detached, -d), expose the usergrid http api port (8080, -p) and make the ports exposed by `elasticsearch` and `cassandra` available by linking the containers together 188 | * `docker ps` - show container ids of running containers 189 | * `docker logs -f usergrid` - follow the log of the container with tag `usergrid` 190 | * `docker stop usergrid` - stop running container with tag `usergrid` 191 | * `docker run -i -t usergrid /bin/bash` - start an interactive bash shell in the container with tag `usergrid` 192 | * `docker ps -q|docker stop; docker images -q|xargs docker rmi -f` - stop and delete ALL old docker images to free up disk space 193 | 194 | Some useful usergrid command line `ugc` commands: 195 | 196 | Install `ugc` with `gem install ugc`. Documentation is [here](https://github.com/apache/incubator-usergrid/tree/master/ugc). For more examples, see the [ugc examples](https://github.com/apache/incubator-usergrid/tree/master/ugc#examples). 197 | 198 | * `ugc profile org` - create profile with name `org`. subsequent commands are applied to this profile. 199 | * `ugc target url http://$IP:8080/org/app` - use host at $IP, organization called `org` and app called `app` 200 | * `ugc login --admin $USERNAME@example.com` - log in as one of the admins users `admin` or `orgadmin`. password is the same as the username. 201 | * `ugc login $USERNAME@example.com` - log in as regular user. there is a default user called `orguser`. password is same as username. 202 | * `ugc list collections` - list collections. think of it as tables in a relational database. you can list other things as well. 203 | 204 | Some useful Virtualbox commands: 205 | 206 | * `VBoxManage hostonlyif remove vboxnet0` - manually delete a hostonly network if it was not properly removed by Virtualbox 207 | 208 | Some useful OSX commands: 209 | 210 | * `ifconfig bridge0 delete` - manually delete a bridge if it was not properly removed by Virtualbox 211 | 212 | 213 | License 214 | ------- 215 | 216 | Copyright 2014-2016 Jahn Bertsch 217 | Copyright 2015 TOMORROW FOCUS News+ GmbH 218 | 219 | Licensed under the Apache License, Version 2.0 (the "License"); 220 | you may not use this file except in compliance with the License. 221 | You may obtain a copy of the License at 222 | 223 | http://www.apache.org/licenses/LICENSE-2.0 224 | 225 | Unless required by applicable law or agreed to in writing, software 226 | distributed under the License is distributed on an "AS IS" BASIS, 227 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 228 | See the License for the specific language governing permissions and 229 | limitations under the License. 230 | 231 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # # vi: set ft=ruby : 3 | 4 | # this file starts a core os virtual machine using vagrant. 5 | # 6 | # based on https://github.com/coreos/coreos-vagrant/blob/master/Vagrantfile 7 | # published under the apache license 8 | # https://github.com/coreos/coreos-vagrant/blob/master/LICENSE 9 | 10 | require 'fileutils' 11 | 12 | Vagrant.require_version ">= 1.6.0" 13 | 14 | CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "user-data") 15 | CONFIG = File.join(File.dirname(__FILE__), "config.rb") 16 | 17 | # VM configuration 18 | $num_instances = 1 19 | $update_channel = "stable" 20 | $enable_serial_logging = false 21 | $vb_gui = false 22 | $vb_memory = 3750 23 | $vb_cpus = 2 24 | 25 | # Attempt to apply the deprecated environment variable NUM_INSTANCES to 26 | # $num_instances while allowing config.rb to override it 27 | if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"] 28 | $num_instances = ENV["NUM_INSTANCES"].to_i 29 | end 30 | 31 | if File.exist?(CONFIG) 32 | require CONFIG 33 | end 34 | 35 | Vagrant.configure("2") do |config| 36 | config.vm.box = "coreos-%s" % $update_channel 37 | config.vm.box_version = ">= 308.0.1" 38 | config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $update_channel 39 | 40 | config.vm.provider :vmware_fusion do |vb, override| 41 | override.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json" % $update_channel 42 | end 43 | 44 | config.vm.provider :virtualbox do |v| 45 | # On VirtualBox, we don't have guest additions or a functional vboxsf 46 | # in CoreOS, so tell Vagrant that so it can be smarter. 47 | v.check_guest_additions = false 48 | v.functional_vboxsf = false 49 | end 50 | 51 | # plugin conflict 52 | if Vagrant.has_plugin?("vagrant-vbguest") then 53 | config.vbguest.auto_update = false 54 | end 55 | 56 | (1..$num_instances).each do |i| 57 | config.vm.define vm_name = "core%01d" % i do |config| 58 | config.vm.hostname = vm_name 59 | 60 | if $enable_serial_logging 61 | logdir = File.join(File.dirname(__FILE__), "log") 62 | FileUtils.mkdir_p(logdir) 63 | 64 | serialFile = File.join(logdir, "%s-serial.txt" % vm_name) 65 | FileUtils.touch(serialFile) 66 | 67 | config.vm.provider :vmware_fusion do |v, override| 68 | v.vmx["serial0.present"] = "TRUE" 69 | v.vmx["serial0.fileType"] = "file" 70 | v.vmx["serial0.fileName"] = serialFile 71 | v.vmx["serial0.tryNoRxLoss"] = "FALSE" 72 | end 73 | 74 | config.vm.provider :virtualbox do |vb, override| 75 | vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"] 76 | vb.customize ["modifyvm", :id, "--uartmode1", serialFile] 77 | end 78 | end 79 | 80 | if $expose_docker_tcp 81 | config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true 82 | end 83 | 84 | config.vm.provider :vmware_fusion do |vb| 85 | vb.gui = $vb_gui 86 | end 87 | 88 | config.vm.provider :virtualbox do |vb| 89 | vb.gui = $vb_gui 90 | vb.memory = $vb_memory 91 | vb.cpus = $vb_cpus 92 | end 93 | 94 | # Private networking with static IPs 95 | # ip = "172.17.8.#{i+100}" 96 | # config.vm.network :private_network, ip: ip 97 | 98 | # Public networking with static IPs 99 | ip = "192.168.1.34" 100 | config.vm.network :public_network, ip: ip 101 | config.vm.network "forwarded_port", guest: 8080, host: 8080, auto_correct: false # usergrid http api 102 | 103 | # Synced folder with rsync 104 | # Unfortunately, rsync is one of the few supported options for syncing folders on windows 105 | config.vm.synced_folder ".", "/home/core/share", type: "rsync" 106 | 107 | # On OSX, it is also possible to use nfs instead of rsync. It additionally supports bidirectional sync. 108 | # config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp'] 109 | 110 | # Run provision script 111 | config.vm.provision :shell, :path => "provision/provision.sh", :args => ip 112 | end 113 | end 114 | end 115 | -------------------------------------------------------------------------------- /postman/README.md: -------------------------------------------------------------------------------- 1 | This directory contains files for use with the [postman](http://www.getpostman.com) REST client. 2 | -------------------------------------------------------------------------------- /postman/usergrid.json.postman_collection: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bfc0f47b-e39a-2b6e-fbe2-130e4950659e", 3 | "name": "Usergrid", 4 | "description": "Collection for use with [Apache Usergrid](http://usergrid.incubator.apache.org)", 5 | "order": [ 6 | "a0c7abef-66ed-3723-5f5b-ea45a1e15521", 7 | "58766f1f-51a8-24c2-edd3-ecc622815a92", 8 | "e03a4dd6-33a4-1de2-b151-5f06a95c07ac", 9 | "f20f3866-626c-e1ec-b67b-4901d6a299b1", 10 | "ab1acb74-52ea-d485-c5f5-47bdb7ac07a4", 11 | "8280151c-ddef-bc80-3c0e-d5e036c5a17d" 12 | ], 13 | "folders": [], 14 | "timestamp": 1412244009006, 15 | "synced": false, 16 | "owner": 0, 17 | "sharedWithTeam": false, 18 | "subscribed": false, 19 | "remoteLink": "", 20 | "public": false, 21 | "write": true, 22 | "requests": [ 23 | { 24 | "id": "58766f1f-51a8-24c2-edd3-ecc622815a92", 25 | "headers": "", 26 | "url": "http://{{ip}}/{{org}}/{{app}}/token", 27 | "preRequestScript": "", 28 | "pathVariables": {}, 29 | "method": "POST", 30 | "data": [ 31 | { 32 | "key": "username", 33 | "value": "orguser", 34 | "type": "text", 35 | "enabled": true 36 | }, 37 | { 38 | "key": "password", 39 | "value": "orguser", 40 | "type": "text", 41 | "enabled": true 42 | }, 43 | { 44 | "key": "grant_type", 45 | "value": "password", 46 | "type": "text", 47 | "enabled": true 48 | } 49 | ], 50 | "dataMode": "urlencoded", 51 | "version": 2, 52 | "tests": "", 53 | "currentHelper": "normal", 54 | "helperAttributes": {}, 55 | "time": 1420543802160, 56 | "name": "create user token", 57 | "description": "", 58 | "collectionId": "bfc0f47b-e39a-2b6e-fbe2-130e4950659e", 59 | "responses": [], 60 | "synced": false, 61 | "owner": 0 62 | }, 63 | { 64 | "id": "8280151c-ddef-bc80-3c0e-d5e036c5a17d", 65 | "headers": "", 66 | "url": "http://{{ip}}/{{org}}/{{app}}/roles/default/permissions?access_token={{token}}", 67 | "preRequestScript": "", 68 | "pathVariables": {}, 69 | "method": "POST", 70 | "data": [], 71 | "dataMode": "raw", 72 | "version": 2, 73 | "tests": "", 74 | "currentHelper": "normal", 75 | "helperAttributes": {}, 76 | "time": 1420541177224, 77 | "name": "create default user permission", 78 | "description": "", 79 | "collectionId": "bfc0f47b-e39a-2b6e-fbe2-130e4950659e", 80 | "responses": [], 81 | "synced": false, 82 | "rawModeData": "{\n \"permission\":\"get,put,post,delete:/users/${user}/*\"\n}", 83 | "owner": 0 84 | }, 85 | { 86 | "id": "a0c7abef-66ed-3723-5f5b-ea45a1e15521", 87 | "headers": "", 88 | "url": "http://{{ip}}/management/token?grant_type=password&username=orgadmin&password=orgadmin", 89 | "preRequestScript": "", 90 | "pathVariables": {}, 91 | "method": "POST", 92 | "data": [], 93 | "dataMode": "urlencoded", 94 | "version": 2, 95 | "tests": "", 96 | "time": 1412253079718, 97 | "name": "create admin token", 98 | "description": "", 99 | "collectionId": "bfc0f47b-e39a-2b6e-fbe2-130e4950659e", 100 | "responses": [], 101 | "synced": false, 102 | "owner": 0 103 | }, 104 | { 105 | "id": "ab1acb74-52ea-d485-c5f5-47bdb7ac07a4", 106 | "headers": "", 107 | "url": "http://{{ip}}/{{org}}/{{app}}/roles?access_token={{token}}", 108 | "preRequestScript": "", 109 | "pathVariables": {}, 110 | "method": "POST", 111 | "data": [], 112 | "dataMode": "raw", 113 | "version": 2, 114 | "tests": "", 115 | "currentHelper": "normal", 116 | "helperAttributes": {}, 117 | "time": 1420541047064, 118 | "name": "create default user role", 119 | "description": "", 120 | "collectionId": "bfc0f47b-e39a-2b6e-fbe2-130e4950659e", 121 | "responses": [], 122 | "synced": false, 123 | "rawModeData": "{\n \"name\":\"Default\"\n}", 124 | "owner": 0 125 | }, 126 | { 127 | "id": "e03a4dd6-33a4-1de2-b151-5f06a95c07ac", 128 | "headers": "", 129 | "url": "http://{{ip}}/{{org}}/{{app}}/users?access_token={{token}}", 130 | "preRequestScript": "", 131 | "pathVariables": {}, 132 | "method": "GET", 133 | "data": [], 134 | "dataMode": "params", 135 | "version": 2, 136 | "tests": "", 137 | "time": 1412253136137, 138 | "name": "list users", 139 | "description": "", 140 | "collectionId": "bfc0f47b-e39a-2b6e-fbe2-130e4950659e", 141 | "responses": [], 142 | "synced": false, 143 | "owner": 0 144 | }, 145 | { 146 | "id": "f20f3866-626c-e1ec-b67b-4901d6a299b1", 147 | "headers": "", 148 | "url": "http://{{ip}}/management/me?access_token={{token}}", 149 | "preRequestScript": "", 150 | "pathVariables": {}, 151 | "method": "GET", 152 | "data": [], 153 | "dataMode": "params", 154 | "version": 2, 155 | "tests": "", 156 | "currentHelper": "normal", 157 | "helperAttributes": {}, 158 | "time": 1420554472224, 159 | "name": "list logged-in user", 160 | "description": "", 161 | "collectionId": "bfc0f47b-e39a-2b6e-fbe2-130e4950659e", 162 | "responses": [], 163 | "synced": false, 164 | "owner": 0 165 | } 166 | ] 167 | } 168 | -------------------------------------------------------------------------------- /postman/usergrid.json.postman_environment: -------------------------------------------------------------------------------- 1 | { 2 | "id": "0515d639-fc03-8ddd-5201-80ef3a6c3adf", 3 | "name": "Usergrid at 192.168.1.34", 4 | "values": [ 5 | { 6 | "key": "ip", 7 | "value": "192.168.1.34:8080", 8 | "type": "text", 9 | "name": "ip", 10 | "enabled": true 11 | }, 12 | { 13 | "key": "org", 14 | "value": "org", 15 | "type": "text", 16 | "name": "org", 17 | "enabled": true 18 | }, 19 | { 20 | "key": "app", 21 | "value": "app", 22 | "type": "text", 23 | "name": "app", 24 | "enabled": true 25 | }, 26 | { 27 | "key": "token", 28 | "value": "YWMt6eQaxrt3EeSYnxNpC2vT3gAAAUvbSh5--19r2ueDPIUIaMwwP1yxqnHPFMU", 29 | "type": "text", 30 | "name": "token", 31 | "enabled": true 32 | } 33 | ], 34 | "timestamp": 1424709029583, 35 | "synced": false, 36 | "syncedFilename": "" 37 | } 38 | -------------------------------------------------------------------------------- /provision/README.md: -------------------------------------------------------------------------------- 1 | run the usergrid stack on aws 2 | ============================= 3 | 4 | - generate key pair in the aws console or add a key pair to the aws console 5 | - start the community ami `ami-8ec1f293` called `CoreOS-stable-557.2.0-hvm` of size `m3.medium` (or a newer version of core os) 6 | - set up an ssh alias called `aws` so you can ssh into the machine by typing `ssh aws` 7 | - run `aws-provision.sh` 8 | 9 | apns setup note 10 | --------------- 11 | 12 | when generating the `notifier` in usergrid, a .p12 certificate is required. 13 | 14 | to create this .p12 certificate, you have to select BOTH the private key (of type `private key`) and the public key signed by apple (of type `certificate`) in the apple keychain osx app AT THE SAME TIME and then export both of them into one .p12 file. 15 | -------------------------------------------------------------------------------- /provision/aws-provision.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2015 TOMORROW FOCUS News+ GmbH 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # use this script to provision to a core os machine on amazon aws 18 | # if set, the following environment variables will be passed to the aws machine: 19 | # ORG_NAME 20 | # APP_NAME 21 | # ADMIN_PASS 22 | 23 | set -x 24 | 25 | # where to copy files - destination folder has to be named `share` 26 | FILE_LOCATION=/home/core/share 27 | DESTINATION=${SSH_ALIAS}:${FILE_LOCATION} 28 | 29 | echo "+++ remove old files on aws machine (if any)" 30 | ssh -v -o StrictHostKeyChecking=no ${SSH_ALIAS} "sudo rm -rf ${FILE_LOCATION}; mkdir -p ${FILE_LOCATION}" 31 | 32 | echo "+++ copy files to aws machine" 33 | scp provision.sh cloudconfig.yaml ${DESTINATION} 34 | scp -r ../java ../usergrid ../cassandra ../elasticsearch ${DESTINATION} 35 | 36 | set +x 37 | 38 | echo "+++ apply cloudconfig.yaml" 39 | ssh ${SSH_ALIAS} "\ 40 | sudo mkdir -p /var/lib/coreos-install && \ 41 | sudo mv /home/core/share/cloudconfig.yaml /var/lib/coreos-install/user_data && \ 42 | sudo coreos-cloudinit -from-file=/var/lib/coreos-install/user_data" 43 | 44 | echo "+++ run provision.sh on aws machine" 45 | PUBLIC_AWS_IP=$(ssh ${SSH_ALIAS} "curl http://169.254.169.254/latest/meta-data/public-ipv4") 46 | ssh ${SSH_ALIAS} "/bin/bash ${FILE_LOCATION}/provision.sh ${PUBLIC_AWS_IP}:8080 ${ORG_NAME} ${APP_NAME} ${ADMIN_PASS} 47 | -------------------------------------------------------------------------------- /provision/cloudconfig.yaml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | # 3 | # cloud config documentation is at: 4 | # https://coreos.com/os/docs/latest/cloud-config.html 5 | # 6 | # attached storage documentation is at: 7 | # https://coreos.com/os/docs/latest/mounting-storage.html 8 | 9 | coreos: 10 | update: 11 | reboot-strategy: off 12 | units: 13 | - name: format-instance.service 14 | command: start 15 | content: | 16 | [Unit] 17 | Description=Format instance storage disc 18 | [Service] 19 | Type=oneshot 20 | RemainAfterExit=yes 21 | ExecStart=/usr/sbin/mkfs.ext4 /dev/xvdb 22 | - name: media-instance.mount 23 | command: start 24 | content: | 25 | [Unit] 26 | Description=Mount instance storage disc to /media/instance 27 | Requires=format-instance.service 28 | After=format-instance.service 29 | Before=docker.service 30 | [Mount] 31 | What=/dev/xvdb 32 | Where=/media/instance 33 | Type=ext4 34 | - name: format-data.service 35 | command: start 36 | content: | 37 | [Unit] 38 | Description=Format data disc 39 | [Service] 40 | Type=oneshot 41 | RemainAfterExit=yes 42 | ExecStart=/usr/sbin/mkfs -t ext4 /dev/xvdf 43 | - name: media-data.mount 44 | command: start 45 | content: | 46 | [Unit] 47 | Description=Mount data disc to /media/data 48 | Requires=format-data.service 49 | After=format-data.service 50 | Before=docker.service 51 | [Mount] 52 | What=/dev/xvdf 53 | Where=/media/data 54 | Type=ext4 55 | - name: settimezone.service 56 | command: start 57 | content: | 58 | [Unit] 59 | Description=Set the timezone 60 | [Service] 61 | ExecStart=/usr/bin/timedatectl set-timezone Europe/Berlin 62 | RemainAfterExit=yes 63 | Type=oneshot 64 | write_files: 65 | - path: /etc/ntp.conf 66 | content: | 67 | # see https://coreos.com/docs/cluster-management/setup/configuring-date-and-timezone/#automating-with-cloud-config 68 | server 0.pool.ntp.org 69 | server 1.pool.ntp.org 70 | server 2.pool.ntp.org 71 | server 3.pool.ntp.org 72 | 73 | # - Allow only time queries, at a limited rate. 74 | # - Allow all local queries (IPv4, IPv6) 75 | restrict default nomodify nopeer noquery limited kod 76 | restrict 127.0.0.1 77 | restrict [::1] 78 | - path: /etc/systemd/timesyncd.conf 79 | content: | 80 | [Time] 81 | NTP=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org 82 | -------------------------------------------------------------------------------- /provision/provision.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2015 TOMORROW FOCUS News+ GmbH 4 | # Copyright 2016 Jahn Bertsch 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | echo "+++ provision.sh" 19 | 20 | # all parameters to this shell script are optional, defaults will be used otherwise 21 | USERGRID_HOST=$1 22 | ORG_NAME=$2 23 | APP_NAME=$3 24 | ADMIN_PASS=$4 25 | 26 | echo "+++ stop running docker containers" 27 | docker stop $(docker ps --quiet) 28 | 29 | echo "+++ remove existing container images" 30 | docker rm -f usergrid cassandra elasticsearch portal 31 | 32 | echo "+++ start containers" 33 | docker run -d --log-driver=syslog --name cassandra -p 9160:9160 -p 9042:9042 --volume ./cassandra-data:/var/lib/cassandra yep1/usergrid-cassandra 34 | docker run -d --log-driver=syslog --name elasticsearch --volume ./elasticsearch-data:/data yep1/usergrid-elasticsearch 35 | docker run -d --log-driver=syslog --name usergrid --env ADMIN_PASS=${ADMIN_PASS} --env ORG_NAME=${ORG_NAME} --env APP_NAME=${APP_NAME} --link elasticsearch:elasticsearch --link cassandra:cassandra -p 8080:8080 -t yep1/usergrid 36 | docker run -d --log-driver=syslog --name portal --env USERGRID_HOST=${USERGRID_HOST} -p 80:80 yep1/usergrid-portal 37 | -------------------------------------------------------------------------------- /usergrid/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2015 Jahn Bertsch 2 | # Copyright 2015 TOMORROW FOCUS News+ GmbH 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # build usergrid from source 17 | 18 | FROM yep1/usergrid-java 19 | 20 | WORKDIR /root 21 | ENV JAVA_HOME /usr/lib/jvm/java-8-oracle 22 | 23 | # build usergrid 24 | # this is done in one run step so less files are included in the layers of the 25 | # docker image, making it smaller. 26 | RUN \ 27 | echo "+++ install tomcat and packages required for compilation" && \ 28 | apt-get update && \ 29 | apt-get install -y maven curl tomcat7 git-core && \ 30 | \ 31 | echo "+++ fix tomcat7 init script: add missing java8 location" && \ 32 | sed -i "s#/usr/lib/jvm/java-7-oracle#/usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-8-oracle#g" /etc/init.d/tomcat7 && \ 33 | \ 34 | echo "+++ get usergrid source, set logging level" && \ 35 | git clone --single-branch --branch master --depth 50 https://github.com/apache/usergrid.git usergrid && \ 36 | cd usergrid && \ 37 | git checkout c6945e3d6f608d1333c269657eb47064866d3e0b && \ 38 | grep -rl log4j.rootLogger=INFO stack | xargs sed -i 's#log4j.rootLogger=INFO#log4j.rootLogger=WARN#g' && \ 39 | \ 40 | echo "+++ build usergrid" && \ 41 | cd /root/usergrid/sdks/java && \ 42 | mvn --quiet clean install -DskipTests -DskipIntegrationTests && \ 43 | mvn --quiet install && \ 44 | cd /root/usergrid/stack && \ 45 | mvn --quiet clean install -DskipTests -DskipIntegrationTests && \ 46 | \ 47 | echo "+++ cleanup" && \ 48 | rm -rf /var/lib/tomcat7/webapps/ROOT && \ 49 | mv /root/usergrid/stack/rest/target/ROOT.war /var/lib/tomcat7/webapps && \ 50 | mv /root/usergrid/stack/config/src/main/resources/usergrid-default.properties /usr/share/tomcat7/lib/usergrid-deployment.properties && \ 51 | apt-get purge --auto-remove -y maven git-core ant && \ 52 | rm -rf /var/lib/apt/lists/* && \ 53 | rm -rf /root/usergrid 54 | 55 | # default command when starting container with "docker run" 56 | CMD /root/run.sh 57 | 58 | # exposed ports: 59 | # 8080 usergrid http interface 60 | # 8443 usergrid https interface 61 | EXPOSE 8080 8443 62 | 63 | # runtime configuration script: since this is updated frequently during development, add it last 64 | COPY run.sh /root/run.sh 65 | -------------------------------------------------------------------------------- /usergrid/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2014-2015 Jahn Bertsch 4 | # Copyright 2015 TOMORROW FOCUS News+ GmbH 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | # this script is invoked after starting up the docker container. 19 | # it allows for configuration at run time instead of baking all 20 | # configuration settings into the container. you can set all configurable 21 | # options using environment variables. 22 | # 23 | # overwrite any of the following default values at run-time like this: 24 | # docker run --env = 25 | 26 | if [ -z "${CASSANDRA_CLUSTER_NAME}" ]; then 27 | CASSANDRA_CLUSTER_NAME='usergrid' 28 | fi 29 | if [ -z "${USERGRID_CLUSTER_NAME}" ]; then 30 | USERGRID_CLUSTER_NAME='usergrid' 31 | fi 32 | if [ -z "${ADMIN_USER}" ]; then 33 | ADMIN_USER=admin 34 | fi 35 | if [ -z "${ADMIN_PASS}" ]; then 36 | ADMIN_PASS=admin 37 | fi 38 | if [ -z "${ADMIN_MAIL}" ]; then 39 | ADMIN_MAIL=admin@example.com 40 | fi 41 | if [ -z "${ORG_NAME}" ]; then 42 | ORG_NAME=org 43 | fi 44 | if [ -z "${APP_NAME}" ]; then 45 | APP_NAME=app 46 | fi 47 | if [ -z "${TOMCAT_RAM}" ]; then 48 | TOMCAT_RAM=512m 49 | fi 50 | 51 | echo "+++ usergrid configuration: CASSANDRA_CLUSTER_NAME=${CASSANDRA_CLUSTER_NAME} USERGRID_CLUSTER_NAME=${USERGRID_CLUSTER_NAME} ADMIN_USER=${ADMIN_USER} ORG_NAME=${ORG_NAME} APP_NAME=${APP_NAME} TOMCAT_RAM=${TOMCAT_RAM}" 52 | 53 | 54 | # start usergrid 55 | # ============== 56 | 57 | echo "+++ configure usergrid" 58 | 59 | USERGRID_PROPERTIES_FILE=/usr/share/tomcat7/lib/usergrid-deployment.properties 60 | 61 | sed -i "s/cassandra.url=localhost:9160/cassandra.url=${CASSANDRA_PORT_9160_TCP_ADDR}:${CASSANDRA_PORT_9160_TCP_PORT}/g" $USERGRID_PROPERTIES_FILE 62 | sed -i "s/cassandra.cluster=Test Cluster/cassandra.cluster=$CASSANDRA_CLUSTER_NAME/g" $USERGRID_PROPERTIES_FILE 63 | sed -i "s/#usergrid.cluster_name=default-property/usergrid.cluster_name=$USERGRID_CLUSTER_NAME/g" $USERGRID_PROPERTIES_FILE 64 | sed -i "s/usergrid.version.build=\${version}/usergrid.version.build=unknown/g" $USERGRID_PROPERTIES_FILE 65 | sed -i "s/usergrid.sysadmin.login.name=superuser/usergrid.sysadmin.login.name=$ADMIN_USER/g" $USERGRID_PROPERTIES_FILE 66 | sed -i "s/usergrid.sysadmin.login.email=super@usergrid.com/usergrid.sysadmin.login.email=$ADMIN_MAIL/g" $USERGRID_PROPERTIES_FILE 67 | sed -i "s/usergrid.sysadmin.login.password=test/usergrid.sysadmin.login.password=$ADMIN_PASS/g" $USERGRID_PROPERTIES_FILE 68 | sed -i "s/usergrid.test-account/#usergrid.test-account/g" $USERGRID_PROPERTIES_FILE 69 | sed -i "s/#elasticsearch.hosts=127.0.0.1/elasticsearch.hosts=${ELASTICSEARCH_PORT_9300_TCP_ADDR}/g" $USERGRID_PROPERTIES_FILE 70 | sed -i "s/#elasticsearch.port=9300/elasticsearch.port=${ELASTICSEARCH_PORT_9300_TCP_PORT}/g" $USERGRID_PROPERTIES_FILE 71 | sed -i "s/#usergrid.use.default.queue=false/usergrid.use.default.queue=true/g" $USERGRID_PROPERTIES_FILE 72 | sed -i "s/#elasticsearch.queue_impl=LOCAL/elasticsearch.queue_impl=LOCAL/g" $USERGRID_PROPERTIES_FILE 73 | sed -i "s/#cassandra.version=1.2/cassandra.version=2.1/g" $USERGRID_PROPERTIES_FILE 74 | 75 | # update tomcat's java options 76 | sed -i "s#\"-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC\"#\"-Djava.awt.headless=true -XX:+UseConcMarkSweepGC -Xmx${TOMCAT_RAM} -Xms${TOMCAT_RAM} -verbose:gc\"#g" /etc/default/tomcat7 77 | 78 | echo "+++ start usergrid" 79 | service tomcat7 start 80 | 81 | 82 | # database setup 83 | # ============== 84 | 85 | while [ -z "$(curl -s localhost:8080/status | grep '"cassandraAvailable" : true')" ] ; 86 | do 87 | echo "+++ tomcat log:" 88 | tail -n 20 /var/log/tomcat7/catalina.out 89 | echo "+++ waiting for cassandra being available to usergrid" 90 | sleep 2 91 | done 92 | 93 | echo "+++ usergrid database setup" 94 | curl --user ${ADMIN_USER}:${ADMIN_PASS} -X PUT http://localhost:8080/system/database/setup 95 | 96 | echo "+++ usergrid database bootstrap" 97 | curl --user ${ADMIN_USER}:${ADMIN_PASS} -X PUT http://localhost:8080/system/database/bootstrap 98 | 99 | echo "+++ usergrid superuser setup" 100 | curl --user ${ADMIN_USER}:${ADMIN_PASS} -X GET http://localhost:8080/system/superuser/setup 101 | 102 | echo "+++ create organization and corresponding organization admin account" 103 | curl -D - \ 104 | -X POST \ 105 | -d "organization=${ORG_NAME}&username=${ORG_NAME}admin&name=${ORG_NAME}admin&email=${ORG_NAME}admin@example.com&password=${ORG_NAME}admin" \ 106 | http://localhost:8080/management/organizations 107 | 108 | echo "+++ create admin token with permissions" 109 | export ADMINTOKEN=$(curl -X POST --silent "http://localhost:8080/management/token" -d "{ \"username\":\"${ORG_NAME}admin\", \"password\":\"${ORG_NAME}admin\", \"grant_type\":\"password\"} " | cut -f 1 -d , | cut -f 2 -d : | cut -f 2 -d \") 110 | echo ADMINTOKEN=$ADMINTOKEN 111 | 112 | echo "+++ create app" 113 | curl -D - \ 114 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 115 | -H "Content-Type: application/json" \ 116 | -X POST -d "{ \"name\":\"${APP_NAME}\" }" \ 117 | http://localhost:8080/management/orgs/${ORG_NAME}/apps 118 | 119 | 120 | echo "+++ delete guest permissions" 121 | curl -D - \ 122 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 123 | -X DELETE "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/guest" 124 | 125 | echo "+++ delete default permissions which are too permissive" 126 | curl -D - \ 127 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 128 | -X DELETE "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/default" 129 | 130 | 131 | echo "+++ create new guest role" 132 | curl -D - \ 133 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 134 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles" \ 135 | -d "{ \"name\":\"guest\", \"title\":\"Guest\" }" 136 | 137 | echo "+++ create new default role, applied to each logged in user" 138 | curl -D - \ 139 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 140 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles" \ 141 | -d "{ \"name\":\"default\", \"title\":\"User\" }" 142 | 143 | 144 | echo "+++ create guest permissions required for login" 145 | curl -D - \ 146 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 147 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/guest/permissions" \ 148 | -d "{ \"permission\":\"post:/token\" }" 149 | 150 | curl -D - \ 151 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 152 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/guest/permissions" \ 153 | -d "{ \"permission\":\"post:/users\" }" 154 | 155 | curl -D - \ 156 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 157 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/guest/permissions" \ 158 | -d "{ \"permission\":\"get:/auth/facebook\" }" 159 | 160 | curl -D - \ 161 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 162 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/guest/permissions" \ 163 | -d "{ \"permission\":\"get:/auth/googleplus\" }" 164 | 165 | echo "+++ create default permissions for a logged in user" 166 | curl -D - \ 167 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 168 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/default/permissions" \ 169 | -d "{ \"permission\":\"get,put,post,delete:/users/\${user}/**\" }" 170 | 171 | curl -D - \ 172 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 173 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/roles/default/permissions" \ 174 | -d "{ \"permission\":\"post:/notifications\" }" 175 | 176 | echo "+++ create user" 177 | curl -D - \ 178 | -H "Authorization: Bearer ${ADMINTOKEN}" \ 179 | -X POST "http://localhost:8080/${ORG_NAME}/${APP_NAME}/users" \ 180 | -d "{ \"username\":\"${ORG_NAME}user\", \"password\":\"${ORG_NAME}user\", \"email\":\"${ORG_NAME}user@example.com\" }" 181 | 182 | echo 183 | echo "+++ done" 184 | 185 | # log usergrid output do stdout so it shows up in docker logs 186 | tail -f /var/log/tomcat7/catalina.out /var/log/tomcat7/localhost_access_log.20*.txt 187 | --------------------------------------------------------------------------------