Permalink
Browse files

initial commit

  • Loading branch information...
githubsaturn committed Oct 25, 2017
1 parent 12789e9 commit 5191cf19e31057e4d9099d3e9dcc8c3c9547fa85
Showing with 18,060 additions and 2 deletions.
  1. +35 −0 .gitignore
  2. +167 −2 README.md
  3. +6 −0 app-backend/.gitignore
  4. +189 −0 app-backend/app.js
  5. +107 −0 app-backend/bin/www
  6. +16 −0 app-backend/deploy-certbot-to-dockerhub.sh
  7. +116 −0 app-backend/deploy-to-docker-hub.js
  8. +14 −0 app-backend/dev-clean-run-as-dev.sh
  9. +5 −0 app-backend/dev-reset-service.sh
  10. +3 −0 app-backend/dev-shell-to-container.sh
  11. +523 −0 app-backend/dist/css/rdash-custom.css
  12. +1,317 −0 app-backend/dist/fonts/montserrat-regular-webfont.svg
  13. BIN app-backend/dist/fonts/montserrat-regular-webfont.ttf
  14. BIN app-backend/dist/fonts/montserrat-regular-webfont.woff
  15. BIN app-backend/dist/img/avatar.jpg
  16. BIN app-backend/dist/img/icon-512x512.png
  17. +99 −0 app-backend/dist/index.html
  18. +1,446 −0 app-backend/dist/js/dashboard.min.js
  19. +9 −0 app-backend/dist/lib/css/main.min.css
  20. +655 −0 app-backend/dist/lib/fonts/fontawesome-webfont.svg
  21. BIN app-backend/dist/lib/fonts/fontawesome-webfont.ttf
  22. BIN app-backend/dist/lib/fonts/fontawesome-webfont.woff
  23. BIN app-backend/dist/lib/fonts/fontawesome-webfont.woff2
  24. +288 −0 app-backend/dist/lib/fonts/glyphicons-halflings-regular.svg
  25. BIN app-backend/dist/lib/fonts/glyphicons-halflings-regular.ttf
  26. BIN app-backend/dist/lib/fonts/glyphicons-halflings-regular.woff
  27. BIN app-backend/dist/lib/fonts/glyphicons-halflings-regular.woff2
  28. +14 −0 app-backend/dist/lib/js/main.min.js
  29. +193 −0 app-backend/dist/templates/apps.html
  30. +119 −0 app-backend/dist/templates/dashboard.html
  31. +32 −0 app-backend/dist/templates/login.html
  32. +17 −0 app-backend/dist/templates/modals/delete-app.html
  33. +13 −0 app-backend/dist/templates/modals/enable-ssl.html
  34. +13 −0 app-backend/dist/templates/modals/force-ssl.html
  35. +10 −0 app-backend/dist/templates/modals/simple.html
  36. +16 −0 app-backend/dist/templates/modals/upload-source.html
  37. +297 −0 app-backend/dist/templates/monitoring.html
  38. +107 −0 app-backend/dist/templates/nodes.html
  39. +88 −0 app-backend/dist/templates/settings.html
  40. +23 −0 app-backend/dockerfile-captain.debug
  41. +14 −0 app-backend/dockerfile-captain.release
  42. +34 −0 app-backend/package.json
  43. +1 −0 app-backend/public/dont-put-anything-here
  44. BIN app-backend/public/favicon.ico
  45. +33 −0 app-backend/src/api/ApiStatusCodes.js
  46. +12 −0 app-backend/src/api/BaseApi.js
  47. +12 −0 app-backend/src/api/TokenApi.js
  48. +643 −0 app-backend/src/datastore/DataStoreImpl.js
  49. +23 −0 app-backend/src/datastore/DataStoreProvider.js
  50. +1,040 −0 app-backend/src/docker/DockerApi.js
  51. +11 −0 app-backend/src/dockerfiles/node
  52. +2 −0 app-backend/src/dockerfiles/php
  53. +10 −0 app-backend/src/dockerfiles/python
  54. +95 −0 app-backend/src/injection/Injector.js
  55. +90 −0 app-backend/src/routes/AppDataRouter.js
  56. +299 −0 app-backend/src/routes/AppDefinitionRouter.js
  57. +44 −0 app-backend/src/routes/LoginRouter.js
  58. +527 −0 app-backend/src/routes/SystemRouter.js
  59. +93 −0 app-backend/src/routes/UserRouter.js
  60. +31 −0 app-backend/src/template/base-nginx-conf.ejs
  61. +86 −0 app-backend/src/template/default-page.ejs
  62. +90 −0 app-backend/src/template/root-nginx-conf.ejs
  63. +43 −0 app-backend/src/template/server-block-conf.ejs
  64. +159 −0 app-backend/src/user/Authenticator.js
  65. +852 −0 app-backend/src/user/CaptainManager.js
  66. +371 −0 app-backend/src/user/CertbotManager.js
  67. +248 −0 app-backend/src/user/DockerRegistry.js
  68. +436 −0 app-backend/src/user/LoadBalancerManager.js
  69. +590 −0 app-backend/src/user/ServiceManager.js
  70. +246 −0 app-backend/src/user/TemplateHelper.js
  71. +128 −0 app-backend/src/utils/CaptainConstants.js
  72. +119 −0 app-backend/src/utils/CaptainInstaller.js
  73. +18 −0 app-backend/src/utils/EnvVars.js
  74. +48 −0 app-backend/src/utils/Logger.js
  75. +3 −0 app-backend/views/error.ejs
  76. +11 −0 app-backend/views/index.ejs
  77. +282 −0 app-cli/captainduckduck-deploy.js
  78. +40 −0 app-cli/captainduckduck-list.js
  79. +225 −0 app-cli/captainduckduck-login.js
  80. +90 −0 app-cli/captainduckduck-logout.js
  81. +21 −0 app-cli/index.js
  82. +42 −0 app-cli/package.json
  83. +70 −0 app-cli/readme.md
  84. +3 −0 app-frontend/.bowerrc
  85. +22 −0 app-frontend/.gitattributes
  86. +51 −0 app-frontend/.gitignore
  87. +21 −0 app-frontend/LICENSE
  88. +24 −0 app-frontend/README.md
  89. +35 −0 app-frontend/bower.json
  90. +121 −0 app-frontend/gulpfile.js
  91. +23 −0 app-frontend/package.json
  92. BIN app-frontend/src/fonts/montserrat-regular-webfont.eot
  93. +1,317 −0 app-frontend/src/fonts/montserrat-regular-webfont.svg
  94. BIN app-frontend/src/fonts/montserrat-regular-webfont.ttf
  95. BIN app-frontend/src/fonts/montserrat-regular-webfont.woff
  96. BIN app-frontend/src/img/avatar.jpg
  97. BIN app-frontend/src/img/icon-512x512.png
  98. +108 −0 app-frontend/src/index.html
  99. +360 −0 app-frontend/src/js/captain/apiManager.js
  100. +26 −0 app-frontend/src/js/captain/authChecker.js
  101. +13 −0 app-frontend/src/js/captain/captainLogger.js
  102. +90 −0 app-frontend/src/js/captain/captainToast.js
  103. +27 −0 app-frontend/src/js/controllers/alert-ctrl.js
  104. +230 −0 app-frontend/src/js/controllers/app-definitions-ctrl.js
  105. +210 −0 app-frontend/src/js/controllers/dashboard-ctrl.js
  106. +20 −0 app-frontend/src/js/controllers/login-ctrl.js
  107. +66 −0 app-frontend/src/js/controllers/master-ctrl.js
  108. +91 −0 app-frontend/src/js/controllers/monitoring-ctrl.js
  109. +49 −0 app-frontend/src/js/controllers/nodes-info-ctrl.js
  110. +70 −0 app-frontend/src/js/controllers/settings-ctrl.js
  111. +22 −0 app-frontend/src/js/directives/file-read.js
  112. +16 −0 app-frontend/src/js/directives/loading.js
  113. +21 −0 app-frontend/src/js/directives/widget-body.js
  114. +17 −0 app-frontend/src/js/directives/widget-footer.js
  115. +21 −0 app-frontend/src/js/directives/widget-header.js
  116. +20 −0 app-frontend/src/js/directives/widget.js
  117. +2 −0 app-frontend/src/js/module.js
  118. +72 −0 app-frontend/src/js/routes.js
  119. +31 −0 app-frontend/src/less/captain.css
  120. +19 −0 app-frontend/src/less/content.less
  121. +34 −0 app-frontend/src/less/hamburg.less
  122. +91 −0 app-frontend/src/less/header.less
  123. +40 −0 app-frontend/src/less/loading.less
  124. +73 −0 app-frontend/src/less/main.less
  125. +5 −0 app-frontend/src/less/mixins.less
  126. +133 −0 app-frontend/src/less/sidebar.less
  127. +12 −0 app-frontend/src/less/variables.less
  128. +103 −0 app-frontend/src/less/widgets.less
  129. +197 −0 app-frontend/src/templates/apps.html
  130. +124 −0 app-frontend/src/templates/dashboard.html
  131. +32 −0 app-frontend/src/templates/login.html
  132. +17 −0 app-frontend/src/templates/modals/delete-app.html
  133. +13 −0 app-frontend/src/templates/modals/enable-ssl.html
  134. +13 −0 app-frontend/src/templates/modals/force-ssl.html
  135. +10 −0 app-frontend/src/templates/modals/simple.html
  136. +16 −0 app-frontend/src/templates/modals/upload-source.html
  137. +307 −0 app-frontend/src/templates/monitoring.html
  138. +108 −0 app-frontend/src/templates/nodes.html
  139. +89 −0 app-frontend/src/templates/settings.html
  140. +1 −0 app-placeholder/.gitignore
  141. +12 −0 app-placeholder/Dockerfile
  142. +35 −0 app-placeholder/app.js
  143. +90 −0 app-placeholder/bin/www
  144. +13 −0 app-placeholder/deploy-placeholder-to-dockerhub.sh
  145. +17 −0 app-placeholder/package.json
  146. BIN app-placeholder/public/favicon.ico
  147. +82 −0 app-placeholder/public/index.html
  148. +3 −0 app-placeholder/readme.md
  149. BIN captain-sample-apps/node.tar
  150. BIN captain-sample-apps/php.tar
  151. BIN captain-sample-apps/python.tar
  152. +3 −0 captain-sample-apps/readme.md
  153. BIN icon.png
View
@@ -0,0 +1,35 @@
app-backend/temp_upload
app-backend/currentdirectory
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://docs.npmjs.com/cli/shrinkwrap#caveats
node_modules
.idea
# Debug log from npm
npm-debug.log
View
169 README.md
@@ -1,2 +1,167 @@
# captainduckduck
Automated Scalable Ready Webserver Package
# CaptainDuckDuck
Captain is a modern automated app deployment & web server manager.
- Deploy apps in your own space
- Secure your services over HTTPS for FREE
- Scale in seconds
- Focus on your apps! Not the bells and whistles just to run your apps!
## Getting started!
### Step 0: Prerequisites
#### A) Domain Name
During installation, you'll be asked to point a wildcard DNS entry to your Captain IP Address. If you don't know what this is, see Domain & DNS details?????. This will cost you as low as $2 a year.
#### B) Server with a Public IP
Captain has to be installed on a machine with a public IP address. If you don't know what this is, see get a server?????. This will cost you as low as $5 a month. If you use the DigitalOcean referral code, you'll get $10 credit - two months worth of free server: https://m.do.co/c/6410aa23d3f3
Note that you can install Captain on your laptop which behind NAT (your router) for testing, but it requires some special setup, like port forwarding.
#### C) Install Docker on Server
If you get your server from DigitalOcean, you can select a server with "pre-installed Docker". This will be the easiest option. Otherwise, you can install Docker CE by following this instruction:
https://docs.docker.com/engine/installation
### Step 1: Captain Installation
Just run the following line, sit back and enjoy!
```bash
$ mkdir /captain && docker run -v /var/run/docker.sock:/var/run/docker.sock dockersaturn/captainduckduck
```
You will see a bunch of output on your screen. Once the Captain is initialized, you can visit `http://[IP_OF_YOUR_SERVER]:3000` in your browser and login to Captain using the default password `captain42`. You can change your password in settings.
### Step 2: Connect Root Domain
Let's say you own `mydomain.com`. You can set `*.something.mydomain.com` as an `A-record` in your DNS settings to point to the IP address of the server where you installed Captain. If you don't know how to do this, see Domain & DNS details?????. Note that it can take several hours for this change to take into effect. Go to `http://[IP_OF_YOUR_SERVER]:3000` in your browser, and enter `something.mydomain.com` as your root, and click update. If DNS changes are succesful, you will get a success message and you can access your captain from `captain.something.mydomain.com` instead of `http://[IP_OF_YOUR_SERVER]:3000`.
### Step 3: Install Captain CLI
Assuming you have npm installed. Simply run (add `sudo` if needed):
```bash
$ npm install -g npm captainduckduck
```
Then, run `captainduckduck login`, follow the steps and login to your captain instance.
### Step 4: Deploy the Test App
Go to the Captain in your browser, from the left menu select Apps and create a new app. Name it `my-first-app`. Then, download any of the test apps????, unzip the content. and while inside the directory of the test app, run:
```bash
/home/Desktop/captain-examples/captain-node $ captainduckduck deploy
```
Follow the instructions, enter `my-first-app` when asked for app name. First time build takes about two minutes. After build is completed, visit `my-first-app.something.mydomain.com` where `something.mydomain.com` is your root domain.
CONGRATS! Your app is live!!
You can visit Captain in the browser and set custom parameters for your app such as environment variables, and do much more!
## Do Much More:
### Enable HTTPS on Captain:
One of a benefits of Captain, is ONE CLICK HTTPS activation. Simply click on Enable HTTPs on your dashboard and after a coupld of seconds your HTTPS is enabled. Note that once HTTPS is enabled, you cannot change your root domain, i.e. `something.mydomain.com`, of course it's always possible to re-install Captain and change it. After enabling HTTPS, you can optionally, although very recommented, enforce HTTPS for all connections, i.e. denying plain insecure HTTP connections and redirect them to HTTPS. Make sure you manually check HTTPS before doing this. Simply go to `https://captain.something.mydomain.com` and if it works, you can safely force HTTPS.
### Enable HTTPS for Apps:
You have full control over enabling HTTPS on your own apps. Once Captain root HTTPS is enabled, you can enable HTTPS for individual apps. To do so, simply go to Captain web, select Apps from the left side menu, scroll to your desired app, and click on Enable HTTPS. That's it!
### Connect Custom Domains to Apps:
Let's say, your `pizza.something.yourdomain.com` is very popular and you want to take the next step and make it available on `www.pizza.com`. First you buy the domain! Next, similar to Captain setup, you go to your DNS settings and point `www` host to your Captain IP address. Alternatively, you can point `*` to Captain IP address. After doing this, go to Apps section, and enter `www.pizza.com` as custom domain and click on connect! Done!
### Run Multiple Instances of App:
Your Pizza app is doing great and you are getting thousands of hits on your website. Having once instance of your app is not good enough. Your latency has gone up. Next thing you want to consider to run multiple instances of your app on your Captain. You can do this from the Apps section of Captain web. Let's say you change your instance count to 3. Captain creates 3 instances of your app running at the same time. If any of them dies (crashes), it automatically spins off a new one! You always have 3 instances of your Pizza app running! The best part? Captain automatically spreads the requests between different instances of your app.
### Run Multiple Servers:
Wow! Your Pizza app is really popular! You have 3 instances of your app running on the same server, RAM and CPU are almost maxed out. You need a get a second server. How do you connect the servers? Captain does that for you ;-) You simply get a server with Docker installed on it, similar to what you did for the original Captain server.
At this point, you have IP address of your new server, IP address of your main Captain node, username of your remote server (root is required for Docker use), private SSH key. Now, go to the "Nodes" section of Captain, enter the values and click on Join Cluster. Done! You now have a real cluster of your own! You can now change the instance count to 6, and Captain will new up some instances on the other server for you, automatically load balances the request and create new instances if one machine dies.
Note on worker / manager nodes. Rule of thumb is you keep your manager count as an odd number:
- 2 machines: main machine manager, the other machine worker
- 3 machines: either one manager, two workers, or 3 managers
- 4 machines: either one manager, two workers, or 3 managers and one worker
For more details, see this link:
https://docs.docker.com/engine/swarm/how-swarm-mode-works/nodes/
Note: for cluster mode you will need to setup a Docker Registry.
### Setup Docker Registery:
Docker Registry is simply the repository that different nodes in a cluster can access to download your app and run it. If you are not running your instance on a cluster, there is pretty much no benefit to setting up Docker Registry.
On the other hand, Docker Registry is necessary for clusters. To setup Registry, simply go to your Captain web dashboard and follow the instructions. You will be given two options:
- Docker Registry managed by Captain.
- Docker Registry managed by a 3rd party provider.
For most cases, a Registry managed by Captain should be good enough. Note that before switching to cluster from a single node, if you have any existing app, you will have to setup Registry and re-deploy all your existing app to make sure they are pushed to the registry and are available to all nodes, not just the main leader node.
### Resource Consumption of Server:
You want to see how your app is behaving. Is it eating up your memory or CPU? Or is your network connection slow? You can answer all these questions by visiting Captain Monitoring menu from the web dashboard. You can enable NetData which is a server monitoring tool and monitor your server.
## Need More Help?
### Firewall & Port Forwarding
Captain uses:
7946 TCP/UDP for Container Network Discovery
4789 TCP/UDP for Container Overlay Network
2377 TCP/UDP for Docker swarm API
3000 TCP for initial Captain Installation (can be blocked once Captain is attached to a domain)
80 TCP for regular HTTP connectiosn
443 TCP for secure HTTPS connections
996 TCP for secure HTTPS connections specific to Docker Registry
### Setup Domain and DNS
To do this, you need to login to the domain provider which you used to purchase your `mydomain.com` domain. You can use GoDaddy.com or NameCheap.com. If you are first time buyer with GoDaddy, just google for GoDaddy 99 cent domains. You'll find copouns that offer 1-year leas for dot com domains for 99 cents!
After you purchased your domain, look for DNS settings under your domain settings. You should see a table of some sort with various entries. Look for an ADD button. Then fill the entries:
- Type: A / A-Record
- Host: `*.something` Replace with `*.anything-you-want`
- Points To: `199.199.199.199` Replace with your server's IP
- TTL: Pick the smallest TTL available, typically 30 minutes.
This process takes minutes, sometimes hours to take into effect.
To confirm, you can use a DNS lookup tool, like: https://mxtoolbox.com/DNSLookup.aspx
Enter `some-random-word.something.mydomain.com` and check to see if the IP is correct.
### Server & Public IP address
If you don't know how to get a server, DigitalOcean is probably the easiest solution for you. Plus, you can use this link and get $10 credit!
https://m.do.co/c/6410aa23d3f3
DigitalOcean calls their servers "Droplets". After signing up, go to the Droplets section and click on "Create Droplet". Under choose an image, click on One-Click Apps, and select Docker. This way, Docker comes pre-installed with your server. If you have an SSH key, enter your SSH key at the bottom of this Droplet Create page, if not, don't worry, it's just alternative password. Once your Droplet is created, you will get an email with IP address of your server, user and pass. If you know how to SSH, then great, SSH into your server. If not, again don't worry! DigitalOcean is really beginner friendly. Simply go to your Droplets section on your DigitalOcean account, click on the Droplet you created. From the menu on the left side, select ACCESS and lauch console. Enter `root` when asked for login and enter the password which you received in email. If you didn't receive your password in email, click on Reset Root Password below Launch Console button. Note that you'll have to type your long password. The web interface that DigitalOcean gives you does not support Copy/Paste ctrl+c ctrl+v.
At this point you are logged into your server and you can run:
```bash
docker run -v /var/run/docker.sock:/var/run/docker.sock dockersaturn/captainduckduck
```
> Icon made by Freepik from www.flaticon.com
View
@@ -0,0 +1,6 @@
# Node modules
/node_modules
# JetBrains
.idea
Oops, something went wrong.

0 comments on commit 5191cf1

Please sign in to comment.