├── .gitignore ├── Dockerfile ├── .travis.yml ├── bin └── tsb ├── README.md ├── docker-compose.yml └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | conf 2 | data 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker/compose:1.11.2 2 | MAINTAINER Marco Capuccini 3 | 4 | ADD docker-compose.yml ./ 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | services: 4 | - docker 5 | 6 | script: 7 | - docker build -t mcapuccini/thesparkbox . 8 | - bin/tsb up -d 9 | - sleep 60 # Give the stack 60s to get up 10 | - curl localhost:8080 11 | - curl localhost:8081 12 | - curl localhost:8082 13 | - curl localhost:8888 14 | - curl localhost:9999 15 | - bin/tsb down 16 | 17 | after_success: 18 | - > 19 | if [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ]; then 20 | docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" 21 | docker push mcapuccini/thesparkbox 22 | fi 23 | -------------------------------------------------------------------------------- /bin/tsb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Abort if docker is not installed 4 | command -v docker >/dev/null 2>&1 || { \ 5 | echo >&2 "TheSparkBox requires docker but it's not installed. Aborting."; exit 1; } 6 | 7 | #Usage 8 | USAGE=$(cat < 11 | Commands: 12 | help print this message 13 | up get TheSparkBox up and running (add -d for detached mode) 14 | down tear down TheSparkBox 15 | EOF) 16 | 17 | # Validate command 18 | if [ $# -eq 0 ]; then 19 | >&2 echo "Error: no arguments supplied" 20 | echo "$USAGE" 21 | exit 1 22 | fi 23 | COMMAND=$1 24 | ALLOWED="help up down" 25 | if [[ ! $ALLOWED =~ $COMMAND ]]; then 26 | >&2 echo "Error: unrecognized command '$COMMAND'" 27 | echo "$USAGE" 28 | exit 1 29 | fi 30 | 31 | # Print help if required 32 | if [ "$COMMAND" = "help" ]; then 33 | echo "$USAGE" 34 | exit 0 35 | fi 36 | 37 | # Set TSB_DATA_DIR if empty or unset 38 | if [ -z "$TSB_DATA_DIR" ]; then 39 | TSB_DATA_DIR="$HOME/.TheSparkBox" 40 | fi 41 | 42 | # Wrap docker run 43 | docker run \ 44 | -v /var/run/docker.sock:/var/run/docker.sock \ 45 | -e TSB_DATA_DIR=$TSB_DATA_DIR \ 46 | -e SPARK_WORKER_CORES=$SPARK_WORKER_CORES \ 47 | -e SPARK_WORKER_MEMORY=$SPARK_WORKER_MEMORY \ 48 | -e TSB_JUPYTER_TOKEN=$TSB_JUPYTER_TOKEN \ 49 | -e SPARK_PUBLIC_DNS=$SPARK_PUBLIC_DNS \ 50 | -e ZEPPELINHUB_API_TOKEN=$ZEPPELINHUB_API_TOKEN \ 51 | mcapuccini/thesparkbox \ 52 | $@ 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TheSparkBox 2 | 3 | [![Build Status](https://travis-ci.org/mcapuccini/TheSparkBox.svg?branch=master)](https://travis-ci.org/mcapuccini/TheSparkBox) 4 | 5 | TheSparkBox is an all-in-one Spark deployment that you can use to fire up a local cluster. Deploying TheSparkBox you will get: 6 | 7 | - One Spark master 8 | - Two Spark workers 9 | - A Jupyter interface for interactive analysis 10 | - A Zeppelin interface for interactive analysis 11 | 12 | Everything is going to get deployed on your workstation, so you will be able to test your Spark applications locally. The advantege of this approach over running Spark applications in `local` mode, is that you will get a sandbox that is closer to a real production environment. 13 | 14 | ## Table of Contents 15 | 16 | - [Getting Started](#getting-started) 17 | - [Install Docker](#install-docker) 18 | - [Get TheSparkBox](#get-thesparkbox) 19 | - [Run TheSparkBox](#run-thesparkbox) 20 | - [Where is the distributed storage?](#where-is-the-distributed-storage) 21 | - [How to update TheSparkBox](#how-to-update-thesparkbox) 22 | - [Configuration](#configuration) 23 | 24 | ## Getting Started 25 | 26 | ### Install Docker 27 | TheSparkBox uses [Docker](https://www.docker.com/) to fire up the environment. Plase make sure that Docker is installed in your workstation, and that your user has the rights to pull images and to start containers. You can find the Docker installation guide following this link: https://docs.docker.com/engine/installation. 28 | 29 | ### Get TheSparkBox 30 | TheSparkBox comes as a single executable that you can install with one line: 31 | 32 | ```bash 33 | curl -Lo tsb https://raw.githubusercontent.com/mcapuccini/TheSparkBox/master/bin/tsb && chmod +x tsb && sudo mv tsb /usr/local/bin/ 34 | ``` 35 | 36 | ### Run TheSparkBox 37 | 38 | To fire up a local Spark cluster you can run: 39 | 40 | ```bash 41 | tsb up -d 42 | ``` 43 | 44 | > **Note:** `-d` stands for *detached mode*, and it runs all of the services in background 45 | 46 | The first time you fire up the cluster, the process might take several minutes, as Docker needs to download all of the required images. On the next executions the cluster is going to be ready in a bunch of seconds. 47 | 48 | If everything went good, you should be able to reach the UIs at: 49 | 50 | - http://localhost:8080 (Spark master) 51 | - http://localhost:8888 (Jupyter) 52 | - http://localhost:9999 (Zeppelin) 53 | 54 | When you are done with your local Spark cluster, you can tear it down as it follows: 55 | 56 | ```bash 57 | tsb down 58 | ``` 59 | 60 | Your Jupyter notebooks, and all of the data in the Jupyter working directory is going to persist in your computer in the `~/.TheSparkBox/data` directory. 61 | 62 | ## Where is the distributed storage? 63 | There is no need to have a distributed file system in a single-node deployment. However, you may wonder how data can be accessed concurrently by the worker nodes, the master and the notebooks. TheSparkBox uses your host operating system storage to achieve this. A host path volume is mounted on `/data` on each cluster component, hence as long as you access files in that path your local Spark cluster is going to handle concurrent operation correctly. 64 | 65 | ## How to update TheSparkBox 66 | There is no stable TheSparkBox release yet, but we are probably going to update the master at a certain point. If you already installed it and you want to make sure that the version that you are running is the latest, please run: 67 | 68 | ```bash 69 | curl -Lo tsb https://raw.githubusercontent.com/mcapuccini/TheSparkBox/master/bin/tsb && sudo chmod +x tsb && sudo mv tsb /usr/local/bin/ 70 | docker pull mcapuccini/thesparkbox 71 | ``` 72 | 73 | ## Configuration 74 | You can tune TheSparkBox setting the following environment variables: 75 | 76 | - **TSB_DATA_DIR:** TheSparkBox data directory (default: `~/.TheSparkBox/data`) 77 | - **TSB_JUPYTER_TOKEN:** a string token for Jupyter authentication. If empty, or unset, authentication is disabled (default: empty) 78 | - **SPARK_WORKER_CORES:** number of cores for each worker (default: `1`) 79 | - **SPARK_WORKER_MEMORY:** amount of memory for each worker (default: `512m`) 80 | - **SPARK_PUBLIC_DNS:** hostname advertised by Spark (default: `localhost`) 81 | - **ZEPPELINHUB_API_TOKEN:** your ZeppelinHub token (default: empty) 82 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2.1" 2 | 3 | services: 4 | spark-master: 5 | image: gettyimages/spark:2.1.0-hadoop-2.7 6 | command: bin/spark-class org.apache.spark.deploy.master.Master -h spark-master 7 | hostname: spark-master 8 | environment: 9 | MASTER: spark://spark-master:7077 10 | SPARK_CONF_DIR: /conf 11 | SPARK_PUBLIC_DNS: ${SPARK_PUBLIC_DNS:-localhost} 12 | expose: 13 | - 7001 14 | - 7002 15 | - 7003 16 | - 7004 17 | - 7005 18 | - 7006 19 | - 7077 20 | - 6066 21 | ports: 22 | - 4040:4040 23 | - 6066:6066 24 | - 7077:7077 25 | - 8080:8080 26 | volumes: 27 | - ${TSB_DATA_DIR:-.}/conf/master:/conf 28 | - ${TSB_DATA_DIR:-.}/data:/data 29 | - /var/run/docker.sock:/var/run/docker.sock 30 | restart: always 31 | 32 | spark-worker-1: 33 | image: gettyimages/spark:2.1.0-hadoop-2.7 34 | command: bin/spark-class org.apache.spark.deploy.worker.Worker spark://spark-master:7077 35 | hostname: spark-worker-1 36 | environment: 37 | SPARK_CONF_DIR: /conf 38 | SPARK_WORKER_CORES: ${SPARK_WORKER_CORES:-1} 39 | SPARK_WORKER_MEMORY: ${SPARK_WORKER_MEMORY:-512m} 40 | SPARK_WORKER_PORT: 8881 41 | SPARK_WORKER_WEBUI_PORT: 8081 42 | SPARK_PUBLIC_DNS: ${SPARK_PUBLIC_DNS:-localhost} 43 | links: 44 | - spark-master 45 | expose: 46 | - 7012 47 | - 7013 48 | - 7014 49 | - 7015 50 | - 7016 51 | - 8881 52 | ports: 53 | - 8081:8081 54 | volumes: 55 | - ${TSB_DATA_DIR:-.}/conf/worker:/conf 56 | - ${TSB_DATA_DIR:-.}/data:/data 57 | - /var/run/docker.sock:/var/run/docker.sock 58 | restart: always 59 | 60 | spark-worker-2: 61 | image: gettyimages/spark:2.1.0-hadoop-2.7 62 | command: bin/spark-class org.apache.spark.deploy.worker.Worker spark://spark-master:7077 63 | hostname: spark-worker-2 64 | environment: 65 | SPARK_CONF_DIR: /conf 66 | SPARK_WORKER_CORES: ${SPARK_WORKER_CORES:-1} 67 | SPARK_WORKER_MEMORY: ${SPARK_WORKER_MEMORY:-512m} 68 | SPARK_WORKER_PORT: 8881 69 | SPARK_WORKER_WEBUI_PORT: 8082 70 | SPARK_PUBLIC_DNS: ${SPARK_PUBLIC_DNS:-localhost} 71 | links: 72 | - spark-master 73 | expose: 74 | - 7012 75 | - 7013 76 | - 7014 77 | - 7015 78 | - 7016 79 | - 8881 80 | ports: 81 | - 8082:8082 82 | volumes: 83 | - ${TSB_DATA_DIR:-.}/conf/worker:/conf 84 | - ${TSB_DATA_DIR:-.}/data:/data 85 | - /var/run/docker.sock:/var/run/docker.sock 86 | restart: always 87 | 88 | jupyter: 89 | image: jupyter/all-spark-notebook:c33a7dc0eece 90 | command: jupyter notebook --NotebookApp.token='${TSB_JUPYTER_TOKEN}' 91 | working_dir: /data 92 | hostname: jupyter 93 | environment: 94 | SPARK_OPTS: "--master=spark://spark-master:7077 --conf spark.ui.port=4041" 95 | SPARK_PUBLIC_DNS: ${SPARK_PUBLIC_DNS:-localhost} 96 | SPARK_EXECUTOR_CORES: ${SPARK_WORKER_CORES:-1} 97 | SPARK_EXECUTOR_MEMORY: ${SPARK_WORKER_MEMORY:-512m} 98 | links: 99 | - spark-master 100 | ports: 101 | - 8888:8888 102 | - 4041:4041 103 | volumes: 104 | - ${TSB_DATA_DIR:-.}/data:/data 105 | - /var/run/docker.sock:/var/run/docker.sock 106 | restart: always 107 | user: "root" 108 | 109 | zeppelin: 110 | image: dylanmei/zeppelin:0.7.0 111 | command: /usr/zeppelin/bin/zeppelin.sh 112 | working_dir: /data 113 | hostname: zeppelin 114 | environment: 115 | MASTER: spark://spark-master:7077 116 | SPARK_PUBLIC_DNS: ${SPARK_PUBLIC_DNS:-localhost} 117 | SPARK_SUBMIT_OPTIONS: "--conf spark.ui.port=4042" 118 | ZEPPELIN_NOTEBOOK_DIR: /data 119 | SPARK_EXECUTOR_CORES: ${SPARK_WORKER_CORES:-1} 120 | SPARK_EXECUTOR_MEMORY: ${SPARK_WORKER_MEMORY:-512m} 121 | ZEPPELIN_NOTEBOOK_STORAGE: "org.apache.zeppelin.notebook.repo.GitNotebookRepo, org.apache.zeppelin.notebook.repo.zeppelinhub.ZeppelinHubRepo" 122 | ZEPPELINHUB_API_ADDRESS: "https://www.zeppelinhub.com" 123 | ZEPPELINHUB_API_TOKEN: ${ZEPPELINHUB_API_TOKEN} 124 | links: 125 | - spark-master 126 | ports: 127 | - 9999:8080 128 | - 4042:4042 129 | volumes: 130 | - ${TSB_DATA_DIR:-.}/data:/data 131 | - /var/run/docker.sock:/var/run/docker.sock 132 | restart: always 133 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------