swarm_orca 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.overcommit.yml +33 -0
  4. data/.rubocop.yml +1 -0
  5. data/.rubocop_todo.yml +17 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/CHANGELOG.md +15 -0
  9. data/Gemfile +5 -0
  10. data/Gemfile.lock +57 -0
  11. data/README.md +335 -0
  12. data/Rakefile +3 -0
  13. data/bin/orca +7 -0
  14. data/lib/capistrano/scm/copy.rb +62 -0
  15. data/lib/capistrano/scm/tasks/copy.cap +33 -0
  16. data/lib/capistrano/scm/tasks/deploy.rb +16 -0
  17. data/lib/capistrano/swarm_orca/bash/crypt +1 -0
  18. data/lib/capistrano/swarm_orca/deploy.rb +3 -0
  19. data/lib/capistrano/swarm_orca/docker.rb +3 -0
  20. data/lib/capistrano/swarm_orca/helpers/fetch_config.rb +134 -0
  21. data/lib/capistrano/swarm_orca/local.rb +43 -0
  22. data/lib/capistrano/swarm_orca/set_global_config.rb +3 -0
  23. data/lib/capistrano/swarm_orca/tasks/deploy.cap +200 -0
  24. data/lib/capistrano/swarm_orca/tasks/docker.cap +318 -0
  25. data/lib/capistrano/swarm_orca/tasks/set_global_config.cap +28 -0
  26. data/lib/swarm_orca.rb +11 -0
  27. data/lib/swarm_orca/encrypt.rb +40 -0
  28. data/lib/swarm_orca/new.rb +73 -0
  29. data/lib/swarm_orca/orca_cli.rb +41 -0
  30. data/lib/swarm_orca/templates/orca/.gitignore +50 -0
  31. data/lib/swarm_orca/templates/orca/.ruby-gemset.tt +1 -0
  32. data/lib/swarm_orca/templates/orca/.ruby-version +1 -0
  33. data/lib/swarm_orca/templates/orca/README.md +93 -0
  34. data/lib/swarm_orca/templates/orca/application_stack/docker-stack-elasticsearch.yml.erb.tt +22 -0
  35. data/lib/swarm_orca/templates/orca/application_stack/docker-stack-errbit.yml.erb.tt +43 -0
  36. data/lib/swarm_orca/templates/orca/application_stack/docker-stack-mysql.yml.erb.tt +17 -0
  37. data/lib/swarm_orca/templates/orca/application_stack/docker-stack-nginx.yml.erb.tt +22 -0
  38. data/lib/swarm_orca/templates/orca/application_stack/docker-stack-rabbitmq.yml.erb.tt +19 -0
  39. data/lib/swarm_orca/templates/orca/application_stack/docker-stack-redis.yml.erb.tt +19 -0
  40. data/lib/swarm_orca/templates/orca/capistrano/Capfile +45 -0
  41. data/lib/swarm_orca/templates/orca/capistrano/Gemfile.tt +4 -0
  42. data/lib/swarm_orca/templates/orca/capistrano/config/deploy.rb.tt +30 -0
  43. data/lib/swarm_orca/templates/orca/capistrano/config/deploy/template_stage.rb +64 -0
  44. data/lib/swarm_orca/templates/orca/nginx/Dockerfile +5 -0
  45. data/lib/swarm_orca/templates/orca/nginx/nginx.conf +31 -0
  46. data/lib/swarm_orca/templates/orca/redis/Dockerfile +5 -0
  47. data/lib/swarm_orca/templates/orca/redis/redis.conf +2 -0
  48. data/lib/swarm_orca/version.rb +5 -0
  49. data/swarm_orca.gemspec +26 -0
  50. metadata +174 -0
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require_relative 'new'
5
+ require_relative 'encrypt'
6
+ module SwarmOrca
7
+ module Cli
8
+ # Orca command line class
9
+ class OrcaCli < Thor
10
+ desc 'new ORCA_DIRECTORY_NAME GIT_FORK DOCKER_NETWORK',
11
+ 'This Command will create a new Orca project'
12
+ long_desc <<-ORCA_NEW
13
+ ORCA_DIRECTORY_NAME: Name of the root directory of orca.\n
14
+ GIT_FORK: Orca github fork.\n
15
+ DOCKER_NETWORK: Docker swarm newtwork name.
16
+ ORCA_NEW
17
+
18
+ def new(orca_directory_name, git_fork, docker_network)
19
+ New.new(root_dir: Dir.pwd,
20
+ orca_dir_name: orca_directory_name,
21
+ git_fork: git_fork,
22
+ network: docker_network).execute
23
+ end
24
+
25
+ desc 'gen_enc_key', 'This Command will generate new encryption key'
26
+ def gen_enc_key
27
+ say("Encryption Key: #{Encrypt.generate_key}")
28
+ end
29
+
30
+ desc 'encrypt KEY TEXT', 'This Command will encrypt the given text'
31
+ def encrypt(key, text)
32
+ say(Encrypt.new(key).encrypt(text).to_s)
33
+ end
34
+
35
+ desc 'decrypt KEY CIPHER', 'This Command will decrypt the given cipher'
36
+ def decrypt(key, cipher)
37
+ say(Encrypt.new(key).decrypt(cipher).to_s)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
@@ -0,0 +1 @@
1
+ <%= @gemset %>
@@ -0,0 +1,93 @@
1
+ # Orca
2
+ - A Template project for deploying services to a docker swarm cluster. This template includes the deployment stakes for the following services.
3
+
4
+ * Elasticsearch
5
+ * Errbit
6
+ * Nginx
7
+ * RabbitMQ
8
+ * Redis
9
+ * MySql
10
+
11
+ # Directories & Files Structure
12
+ - application_stack :
13
+ a folder that contains docker-comppose templates files for applications.
14
+ - Capistrano:
15
+ Capistrano gem home folder
16
+ - capistrano/config/deploy/template_stage.rb:
17
+ Deployment stage template.
18
+ - capistrano/config/deploy
19
+ Organize deployment stages and their configurations.
20
+ - capistrano/config/deploy.rb:
21
+ Define all deployment tasks and functions.
22
+ - capistrano/log: capistrano log folder
23
+ - nginx: nginx docker image configurations
24
+ - redis: redis docker image configurations
25
+ - seeds: contains applications DB seed scripts and data.
26
+
27
+ # Deployment Steps
28
+ - Prepare your deployment stage file under `config/deploy/${your_stage_name}.rb`. You can duplicate the `template_stage` and replace all the necessary configurations.
29
+ - Upload deployment scripts to the swarm manager server
30
+
31
+ ```sh
32
+ cd capistrano
33
+ bundle exec cap ${your_stage_name} deploy:setup
34
+ ```
35
+
36
+ - Create Databases (assuming that orca have two applications web and backend)
37
+
38
+ ```sh
39
+ ➜ cd capistrano
40
+ ➜ cap -T | grep "create.*dbs"
41
+ cap deploy:create_web_dbs
42
+ cap deploy:create_backend_dbs
43
+ ```
44
+
45
+ - Seed Databases (assuming that orca have two applications web and backend)
46
+
47
+ ```sh
48
+ ➜ cd capistrano
49
+ ➜ cap -T | grep "seed.*dbs"
50
+ cap deploy:seed_web_dbs
51
+ cap deploy:seed_backend_dbs
52
+ ```
53
+
54
+ - Create and seed all databases at once
55
+
56
+ ```sh
57
+ ➜ cd capistrano
58
+ ➜ cap deploy:all_dbs
59
+ ```
60
+
61
+ - Deploy services/applications individually
62
+
63
+ ```sh
64
+ cd capistrano
65
+ bundle exec cap ${your_stage_name} deploy:${service_name}
66
+ ```
67
+
68
+ - Deploy all services
69
+
70
+ ```sh
71
+ cd capistrano
72
+ bundle exec cap ${your_stage_name} deploy:all
73
+ ```
74
+
75
+ - Deploy subset of the defined services
76
+ ```
77
+ export DEPLOYED_STACKS='nginx redis'
78
+ export FORK=wshihadeh
79
+ bundle exec cap ${stage} deploy:auto
80
+ ```
81
+
82
+ - Check Stage status
83
+
84
+ ```
85
+ bundle exec cap ${your_stage_name} docker:deploy:info
86
+ ```
87
+
88
+
89
+ - Stop a given stack
90
+
91
+ ```
92
+ bundle exec cap ${your_stage_name} docker:stop:${service_name}
93
+ ```
@@ -0,0 +1,22 @@
1
+ version: '3.7'
2
+
3
+ networks:
4
+ <%%= NETWORK %>:
5
+ external: true
6
+
7
+ services:
8
+
9
+ # --- ELASTICSEARCH ---
10
+
11
+ elasticsearch:
12
+ image: ${ELASTICSEARCH_DOCKER_IMAGE}:${ELASTICSEARCH_DOCKER_IMAGE_TAG}
13
+ ports:
14
+ - ${ELASTIC_FIRST_PORT}:9200/tcp
15
+ - ${ELASTIC_SECOND_PORT}:9300/tcp
16
+ environment:
17
+ $$$$$$$$PWD/config: /usr/share/elasticsearch/config
18
+ $$$$$$$$PWD/esdata: /usr/share/elasticsearch/data
19
+ deploy:
20
+ replicas: 1
21
+ networks:
22
+ - <%%= NETWORK %>
@@ -0,0 +1,43 @@
1
+ version: '3.7'
2
+
3
+ networks:
4
+ <%%= NETWORK %>:
5
+ external: true
6
+
7
+ services:
8
+
9
+ mongo_db:
10
+ image: ${ERRBIT_DB_DOCKER_IMAGE}:${ERRBIT_DB_DOCKER_IMAGE_TAG}
11
+ volumes:
12
+ - ${MONGO_VOLUME}:/data/db
13
+ deploy:
14
+ replicas: 1
15
+ networks:
16
+ - <%%= NETWORK %>
17
+
18
+ errbit_web:
19
+ image: ${ERRBIT_DOCKER_IMAGE}:${ERRBIT_DOCKER_IMAGE_TAG}
20
+ environment:
21
+ SECRET_KEY_BASE: 152944e50d19ab5601f3ef9bcc15d428fe6cd0d0c94a832b13528f6d5b0f82e6e957a1638695c37af94b3c1bd0f98fb1d0a98951d9ce964c8781892be644ecd0
22
+ RACK_ENV: production
23
+ MONGO_URL: 'mongodb://mongo_db'
24
+ ERRBIT_HOST: ${ERRBIT_HOST}
25
+ ERRBIT_PROTOCOL: ${ERRBIT_PROTOCOL}
26
+ ERRBIT_PORT: ${ERRBIT_PORT}
27
+ GOOGLE_AUTHENTICATION: 'false'
28
+ GITHUB_AUTHENTICATION: 'false'
29
+ ERRBIT_LOG_LOCATION: 'STDOUT'
30
+ PORT: '8080'
31
+ ERRBIT_USER_HAS_USERNAME: 'true'
32
+ ERRBIT_PER_APP_NOTIFY_AT_NOTICES: 'true'
33
+ LDAP_HOST: ${LDAP_HOST}
34
+ LDAP_USER: ${LDAP_USER}
35
+ LDAP_PASSWORD: ${LDAP_PASSWORD}
36
+ http_proxy: ${HTTP_PROXY}
37
+ https_proxy: ${HTTPS_PROXY}
38
+ no_proxy: ${NO_PROXY}
39
+ healthcheck:
40
+ test: "curl --fail http://localhost:8080/users/sign_in || exit 1"
41
+ interval: 5s
42
+ networks:
43
+ - <%%= NETWORK %>
@@ -0,0 +1,17 @@
1
+ version: '3.7'
2
+
3
+ networks:
4
+ <%%= NETWORK %>:
5
+ external: true
6
+
7
+ services:
8
+
9
+ mysql:
10
+ image: ${MYSQL_DOCKER_IMAGE}:${MYSQL_DOCKER_IMAGE_TAG}
11
+ volumes:
12
+ - ${MYSQL_VOLUME}:/var/lib/mysql
13
+ environment:
14
+ - MYSQL_ROOT_PASSWORD=dummy
15
+ deploy:
16
+ networks:
17
+ - <%%= NETWORK %>
@@ -0,0 +1,22 @@
1
+ version: '3.7'
2
+
3
+ networks:
4
+ <%%= NETWORK %>:
5
+ external: true
6
+
7
+ services:
8
+
9
+ # --- NGINX ---
10
+
11
+ nginx:
12
+ image: ${NGINX_DOCKER_IMAGE}:${NGINX_DOCKER_IMAGE_TAG}
13
+ ports:
14
+ - '${PORT_HTTP}:80'
15
+ - '${PORT_HTTPS}:443'
16
+ deploy:
17
+ replicas: 1
18
+ update_config:
19
+ parallelism: 1
20
+ delay: 3s
21
+ networks:
22
+ - <%%= NETWORK %>
@@ -0,0 +1,19 @@
1
+ version: '3.7'
2
+
3
+ networks:
4
+ <%%= NETWORK %>:
5
+ external: true
6
+
7
+ services:
8
+
9
+ # --- RABBITMQ ---
10
+
11
+ rabbitmq:
12
+ image: ${RABBITMQ_DOCKER_IMAGE}:${RABBITMQ_DOCKER_IMAGE_TAG}
13
+ hostname: rabbitmq
14
+ volumes:
15
+ - ${RABBITMQ_VOLUME}:/var/lib/rabbitmq
16
+ deploy:
17
+ replicas: 1
18
+ networks:
19
+ - <%%= NETWORK %>
@@ -0,0 +1,19 @@
1
+ version: '3.7'
2
+
3
+ networks:
4
+ <%%= NETWORK %>:
5
+ external: true
6
+
7
+ services:
8
+
9
+ redis:
10
+ image: ${DOCKER_IMAGE_PREFIX}${REDIS_DOCKER_IMAGE}:${REDIS_DOCKER_IMAGE_TAG}
11
+ ports:
12
+ - '${PORT}:6379'
13
+ volumes:
14
+ - ${NFS_MOUNT}:/data
15
+ command: ['redis-server', '/usr/local/etc/redis/redis.conf']
16
+ deploy:
17
+ replicas: 1
18
+ networks:
19
+ - <%%= NETWORK %>
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load DSL and set up stages
4
+ require 'capistrano/setup'
5
+
6
+ # Include default deployment tasks
7
+ require 'capistrano/deploy'
8
+
9
+ require 'shellwords'
10
+
11
+ # Load the SCM plugin appropriate to your project:
12
+ #
13
+ # require "capistrano/scm/hg"
14
+ # install_plugin Capistrano::SCM::Hg
15
+ # or
16
+ # require "capistrano/scm/svn"
17
+ # install_plugin Capistrano::SCM::Svn
18
+ # or
19
+ require 'swarm_orca'
20
+
21
+ scm = ENV.fetch('SCM', 'git')
22
+ require "capistrano/scm/#{scm}"
23
+ install_plugin Module.const_get("Capistrano::SCM::#{scm.capitalize}")
24
+
25
+ # Include tasks from other gems included in your Gemfile
26
+ #
27
+ # For documentation on these, see for example:
28
+ #
29
+ # https://github.com/capistrano/rvm
30
+ # https://github.com/capistrano/rbenv
31
+ # https://github.com/capistrano/chruby
32
+ # https://github.com/capistrano/bundler
33
+ # https://github.com/capistrano/rails
34
+ # https://github.com/capistrano/passenger
35
+ #
36
+ # require "capistrano/rvm"
37
+ # require "capistrano/rbenv"
38
+ # require "capistrano/chruby"
39
+ # require "capistrano/bundler"
40
+ # require "capistrano/rails/assets"
41
+ # require "capistrano/rails/migrations"
42
+ # require "capistrano/passenger"
43
+
44
+ # Load custom tasks from `lib/capistrano/tasks` if you have any defined
45
+ Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'capistrano', '3.8.0'
4
+ gem 'swarm_orca', '<%= @orca_version%>'
@@ -0,0 +1,30 @@
1
+ # config valid only for current version of Capistrano
2
+ lock "3.8.0"
3
+ require "capistrano/swarm_orca/set_global_config"
4
+
5
+ # Overwrite swarm_orca global vars
6
+
7
+ set :fork, "<%= @git_fork %>"
8
+ set (:network) { "<%= @docker_network %>" }
9
+
10
+ #Overwite gem global vars
11
+ #set (:repo_url) { ENV["REPO_URL"] || "git@github.com:#{ENV.fetch('FORK', fetch(:fork))}/orca.git" }
12
+
13
+ #set :keep_releases, 5
14
+ #set (:application) { "orca" }
15
+ #set (:deploy_to) { "/home/deploy/orca" }
16
+ #set :pty, true
17
+
18
+ #set (:service_stacks) { %w(elasticsearch rabbitmq errbit mysql) }
19
+ #set (:service_stacks_with_build_image) { %w(nginx redis) }
20
+ #set (:db_apps_stacks_mapping), {}
21
+
22
+ #set (:elasticsearch_apps) { }
23
+ #set the path containing docker command
24
+ #set (:docker_path) { "" }
25
+ set (:docker_erb_templates) { true }
26
+ #set (:docker_cleanup) { %w(yes 1 true).include? ENV.fetch("PRUNE", 'true') }
27
+ #set (:auto_image_build){ %w(yes 1 true).include? ENV.fetch("BUILD_IMAGE", 'true') }
28
+
29
+ require "capistrano/swarm_orca/deploy"
30
+ require "capistrano/swarm_orca/docker"
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ server '${SERVER_NAME}', user: '${USER}',
4
+ roles: %w[
5
+ mysql
6
+ rabbitmq
7
+ nginx
8
+ elasticsearch
9
+ redis
10
+ swarm_manager
11
+ ]
12
+
13
+ set :shared, network: fetch(:network)
14
+
15
+ set :mysql,
16
+ stack_name: 'mysql',
17
+ mysql_docker_image: 'mysql',
18
+ mysql_docker_image_tag: '5.7',
19
+ mysql_volume: "#{fetch(:deploy_to)}/mysql"
20
+
21
+ set :rabbitmq,
22
+ stack_name: 'rabbitmq',
23
+ rabbitmq_docker_image: 'rabbitmq',
24
+ rabbitmq_docker_image_tag: '3.6-management',
25
+ rabbitmq_volume: "#{fetch(:deploy_to)}/rabbitmq"
26
+
27
+ set :nginx,
28
+ stack_name: 'nginx',
29
+ nginx_docker_image: 'nginx',
30
+ nginx_docker_image_tag: 'latest',
31
+ port_http: '80',
32
+ port_https: '443'
33
+
34
+ set :redis,
35
+ stack_name: 'redis',
36
+ docker_image_prefix: 'docker.io/',
37
+ redis_docker_image: 'redis',
38
+ redis_docker_image_tag: 'latest',
39
+ nfs_mount: "#{fetch(:deploy_to)}/redis",
40
+ port: '6379'
41
+
42
+ set :elasticsearch,
43
+ stack_name: 'elasticsearch',
44
+ elasticsearch_docker_image: 'elasticsearch',
45
+ elasticsearch_docker_image_tag: '5.4.0-alpine',
46
+ elastic_first_port: '9200',
47
+ elastic_second_port: '9300'
48
+
49
+ set :errbit,
50
+ stack_name: 'errbit',
51
+ errbit_docker_image: 'docker.io/errbit/errbit',
52
+ errbit_db_docker_image: 'mongo',
53
+ errbit_docker_image_tag: 'latest',
54
+ errbit_db_docker_image_tag: '3.2',
55
+ errbit_host: '${ERRBIT_HOST}',
56
+ errbit_protocol: 'http',
57
+ errbit_port: '80',
58
+ ldap_host: '${LDAP_HOST}',
59
+ ldap_user: '${LDAP_USER}',
60
+ ldap_password: '${LDAP_PASSWORD}',
61
+ http_proxy: '${HTTP_PROXY}',
62
+ https_proxy: '${hTTPS_PROXY}',
63
+ no_proxy: '${NO_PROXY}',
64
+ mongo_volume: "#{fetch(:deploy_to)}/mongo"