appril 0.0.3 → 0.0.4

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/appril.gemspec +0 -1
  3. data/lib/appril/version.rb +1 -1
  4. data/lib/appril.rb +0 -117
  5. metadata +4 -73
  6. data/bin/appril +0 -5
  7. data/boilerplate/app/.gitignore +0 -6
  8. data/boilerplate/app/.pryrc +0 -1
  9. data/boilerplate/app/Gemfile +0 -6
  10. data/boilerplate/app/Rakefile +0 -1
  11. data/boilerplate/app/base/api/base_controller.rb +0 -21
  12. data/boilerplate/app/base/api/index/client.coffee +0 -4
  13. data/boilerplate/app/base/api/index/layout.html +0 -3
  14. data/boilerplate/app/base/api/index/server.rb +0 -3
  15. data/boilerplate/app/base/api/rtcp_controller.rb +0 -22
  16. data/boilerplate/app/base/assets/styles.css +0 -0
  17. data/boilerplate/app/base/boot.rb +0 -2
  18. data/boilerplate/app/base/core.coffee +0 -143
  19. data/boilerplate/app/base/helpers/application_helpers.coffee +0 -1
  20. data/boilerplate/app/base/helpers/application_helpers.rb +0 -4
  21. data/boilerplate/app/base/load.rb +0 -0
  22. data/boilerplate/app/base/models/base_model.rb +0 -0
  23. data/boilerplate/app/base/templates/access_denied.html +0 -3
  24. data/boilerplate/app/base/templates/layout.liquid +0 -11
  25. data/boilerplate/app/base/templates/layouts/main.html +0 -1
  26. data/boilerplate/app/base/templates/layouts/none.html +0 -1
  27. data/boilerplate/app/config/config.rb +0 -9
  28. data/boilerplate/app/config/config.yml +0 -18
  29. data/boilerplate/app/config/env/development.yml +0 -0
  30. data/boilerplate/app/config/env/production.yml +0 -0
  31. data/boilerplate/app/config/env/stage.yml +0 -0
  32. data/boilerplate/app/config/env/test.yml +0 -0
  33. data/boilerplate/app/config.ru +0 -3
  34. data/boilerplate/app/core/Gemfile +0 -4
  35. data/boilerplate/app/core/boot.rb +0 -16
  36. data/boilerplate/app/core/generate_configs.rb +0 -7
  37. data/boilerplate/app/core/load.rb +0 -14
  38. data/boilerplate/app/core/load_controllers.rb +0 -14
  39. data/boilerplate/app/generators/api/client.coffee +0 -4
  40. data/boilerplate/app/generators/api/layout.html +0 -0
  41. data/boilerplate/app/generators/api/server.rb +0 -3
  42. data/boilerplate/app/package.json +0 -10
  43. data/boilerplate/app/public/.ignore +0 -0
  44. data/boilerplate/app/tmp/.ignore +0 -0
  45. data/boilerplate/app/var/.ignore +0 -0
  46. data/boilerplate/app/webpack.config.js +0 -53
  47. data/boilerplate/crudle/Gemfile +0 -7
  48. data/boilerplate/crudle/base/core.coffee +0 -128
  49. data/boilerplate/crudle/base/templates/menu.html +0 -3
  50. data/boilerplate/crudle/generators/api/client.coffee +0 -11
  51. data/boilerplate/crudle/generators/api/editor.html +0 -0
  52. data/boilerplate/crudle/generators/api/server.rb +0 -26
  53. data/boilerplate/crudle/package.json +0 -15
  54. data/boilerplate/crudle/webpack.config.js +0 -54
  55. data/docker/Dockerfile +0 -5
  56. data/docker/run +0 -66
  57. data/docker/skel/build.sh +0 -1
  58. data/docker/skel/cleanup.sh +0 -7
  59. data/docker/skel/config.yml +0 -24
  60. data/docker/skel/prepare_build.sh +0 -5
  61. data/docker/skel/start.sh +0 -1
  62. data/docker/start +0 -7
  63. data/lib/appril/cli/app/install.rb +0 -45
  64. data/lib/appril/cli/app/update.rb +0 -26
  65. data/lib/appril/cli/app.rb +0 -11
  66. data/lib/appril/cli/assertions.rb +0 -60
  67. data/lib/appril/cli/docker/build.rb +0 -150
  68. data/lib/appril/cli/docker/install.rb +0 -21
  69. data/lib/appril/cli/docker/update.rb +0 -24
  70. data/lib/appril/cli/docker.rb +0 -16
  71. data/lib/appril/cli/generator.rb +0 -15
  72. data/lib/appril/cli/helpers.rb +0 -47
  73. data/lib/appril/cli.rb +0 -204
@@ -1,150 +0,0 @@
1
- module Appril
2
- class CLI
3
- module Docker
4
- class Build
5
-
6
- def initialize dir, update_runner_only: false, push_opted: false
7
- Dir.chdir dir do
8
-
9
- config = load_config
10
- validate_config(config)
11
-
12
- build_dir = Pathname.new(File.expand_path('__tmpbuildir__'))
13
-
14
- prepare_build_dir(build_dir)
15
-
16
- install_files(build_dir)
17
-
18
- app_dir = Pathname.new(File.expand_path(config['APP_DIR']))
19
-
20
- if update_runner_only
21
- puts "Skipping image building"
22
- else
23
- prepare_build(build_dir, app_dir)
24
-
25
- image_built = build_image(build_dir, config['IMAGE_NAME'], config['BUILD_OPTS'])
26
-
27
- if image_built && push_opted
28
- push_image(config['IMAGE_NAME'])
29
- end
30
- end
31
-
32
- puts "Installing run script"
33
- install_run_script(app_dir, *config.values_at('IMAGE_NAME', 'CONTAINER_NAME', 'RUN_SCRIPT', 'RUN_OPTS'))
34
-
35
- FileUtils.rm_rf(build_dir)
36
- end
37
- end
38
-
39
- def load_config
40
- YAML.load(File.read(CONFIG_FILE))
41
- end
42
-
43
- def validate_config config
44
- {
45
- 'IMAGE_NAME' => :validate_config__image_name,
46
- 'CONTAINER_NAME' => :validate_config__container_name,
47
- 'APP_DIR' => :validate_config__app_dir,
48
- 'RUN_SCRIPT' => :validate_config__run_script,
49
- }.each_pair do |key,validator|
50
- next if send(validator, config[key])
51
- puts "", "\t::: Please set #{key} in config.yml :::", ""
52
- exit 1
53
- end
54
- end
55
-
56
- def validate_config__image_name value
57
- !value.nil? && !value.empty?
58
- end
59
-
60
- def validate_config__container_name value
61
- !value.nil? && !value.empty? && value.values.any?
62
- end
63
-
64
- def validate_config__app_dir value
65
- !value.nil? && !value.empty?
66
- end
67
-
68
- def validate_config__run_script value
69
- !value.nil? && !value.empty?
70
- end
71
-
72
- def prepare_build_dir dir
73
- FileUtils.rm_rf(dir)
74
- FileUtils.mkdir_p(dir / 'build')
75
- end
76
-
77
- def install_files dir
78
- install_dockerfile(dir)
79
- install_start_file(dir)
80
- install_build_files(dir)
81
- install_cleanup_file(dir)
82
- end
83
-
84
- def install_dockerfile dir
85
- FileUtils.cp(BASE_DIR / 'Dockerfile', dir)
86
- end
87
-
88
- def install_start_file dir
89
- File.open dir / 'start', 'w' do |f|
90
- f << File.read(BASE_DIR / 'start').sub('{start}', File.read(START_FILE))
91
- end
92
- end
93
-
94
- def install_build_files dir
95
- FileUtils.cp(PREPARE_BUILD_FILE, dir / 'build')
96
- FileUtils.cp(BUILD_FILE, dir / 'build/build')
97
- end
98
-
99
- def install_cleanup_file dir
100
- FileUtils.cp(CLEANUP_FILE, dir / 'build/cleanup')
101
- end
102
-
103
- def prepare_build dir, app_dir
104
- Dir.chdir dir / 'build' do
105
- CLI.run "APP_DIR=#{app_dir} #{PREPARE_BUILD_FILE}"
106
- exit 1 unless $? && $?.success?
107
- end
108
- end
109
-
110
- def build_image dir, image_name, build_opts
111
- CLI.run "docker build -t #{image_name} #{build_opts} '#{dir}'"
112
- $? && $?.success?
113
- end
114
-
115
- def push_image image_name
116
- CLI.run "docker push #{image_name}"
117
- $? && $?.success?
118
- end
119
-
120
- def install_run_script app_dir, image_name, container_name, run_script, run_opts
121
- FileUtils.mkdir_p(app_dir / File.dirname(run_script))
122
-
123
- script_path = app_dir / run_script
124
-
125
- File.open script_path, 'w' do |f|
126
- f << File.read(BASE_DIR / 'run').
127
- gsub('{image}', image_name).
128
- gsub('{script_path_traversal}', script_path_traversal(run_script)).
129
- gsub('{run_opts}', run_opts).
130
- gsub('{environments}', container_name.keys.join(' ')).
131
- gsub('{container_definitions}', container_definitions(container_name))
132
- end
133
-
134
- FileUtils.chmod('+x', script_path)
135
- end
136
-
137
- def container_definitions container_name
138
- container_name.map do |kv|
139
- '[ "$APP_ENV" = "%s" ] && CONTAINER_NAME="%s"' % kv
140
- end.join("\n")
141
- end
142
-
143
- def script_path_traversal run_script
144
- run_script.gsub(/\A\/+|\/+\Z/, '').scan(/\/+/).map {'..'}*'/'
145
- end
146
-
147
- end
148
- end
149
- end
150
- end
@@ -1,21 +0,0 @@
1
- module Appril
2
- class CLI
3
- module Docker
4
- class Install
5
- include Helpers
6
-
7
- def initialize dir, working_dir_opted: false
8
- install(dir, working_dir_opted)
9
- make_executable(dir / PREPARE_BUILD_FILE)
10
- puts "Done. All files installed into #{dir}"
11
- end
12
-
13
- def install dir, working_dir_opted
14
- src = working_dir_opted ? BASE_DIR.to_path + '/skel/.' : BASE_DIR / 'skel'
15
- FileUtils.cp_r(src, dir)
16
- end
17
-
18
- end
19
- end
20
- end
21
- end
@@ -1,24 +0,0 @@
1
- module Appril
2
- class CLI
3
- module Docker
4
- class Update
5
- include Helpers
6
-
7
- def initialize dir
8
- Dir.chdir BASE_DIR / 'skel' do
9
-
10
- Dir['**/*'].select {|e| File.file?(e)}.each do |file|
11
- next if File.file?(dir / file)
12
- create_dirname_for(dir / file)
13
- puts "Installing #{File.basename(dir)}/#{file}"
14
- FileUtils.cp(file, dir / file)
15
- end
16
-
17
- end
18
- puts "Done"
19
- end
20
-
21
- end
22
- end
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- module Appril
2
- class CLI
3
- module Docker
4
- BASE_DIR = (Appril::BASE_DIR / 'docker').freeze
5
- CONFIG_FILE = './config.yml'.freeze
6
- START_FILE = './start.sh'.freeze
7
- PREPARE_BUILD_FILE = './prepare_build.sh'.freeze
8
- BUILD_FILE = './build.sh'.freeze
9
- CLEANUP_FILE = './cleanup.sh'.freeze
10
- end
11
- end
12
- end
13
-
14
- require 'appril/cli/docker/install'
15
- require 'appril/cli/docker/build'
16
- require 'appril/cli/docker/update'
@@ -1,15 +0,0 @@
1
- module Appril
2
- class CLI
3
- class Generator
4
- class API
5
- include Helpers
6
-
7
- def initialize gen_dir, api_dir, api_name
8
- FileUtils.cp_r(gen_dir, api_dir)
9
- puts "Done"
10
- end
11
-
12
- end
13
- end
14
- end
15
- end
@@ -1,47 +0,0 @@
1
- module Appril
2
- class CLI
3
- module Helpers
4
-
5
- def display_error error
6
- puts "", "\t::: #{error} :::", ""
7
- end
8
-
9
- def fatal_error! error, exit_code = 1
10
- display_error(error)
11
- exit exit_code
12
- end
13
-
14
- def expanded_path *path
15
- Pathname.new(File.expand_path(File.join(*path.map(&:to_s))))
16
- end
17
-
18
- def create_dirname_for dir
19
- FileUtils.mkdir_p(File.dirname(dir))
20
- end
21
-
22
- def make_executable *entries
23
- entries.flatten.each {|e| FileUtils.chmod('+x', e)}
24
- end
25
-
26
- def working_dir_opted? opted_dir
27
- opted_dir == '.'
28
- end
29
-
30
- def extract_namespace args
31
- return unless index = args.index('-n')
32
- return unless namespace = args[index + 1]
33
- if namespace =~ /::/
34
- fatal_error! "Nested namespaces not supported"
35
- end
36
- if namespace =~ /\W/
37
- fatal_error! "Namespace may contain only alphanumerics"
38
- end
39
- unless namespace =~ /\A[A-Z]/
40
- fatal_error! "Namespace should start with a capital letter"
41
- end
42
- namespace
43
- end
44
-
45
- end
46
- end
47
- end
data/lib/appril/cli.rb DELETED
@@ -1,204 +0,0 @@
1
- require 'fileutils'
2
- require 'pathname'
3
- require 'yaml'
4
- require 'pty'
5
- require 'appril/version'
6
- require 'appril/cli/helpers'
7
- require 'appril/cli/assertions'
8
-
9
- module Appril
10
- BASE_DIR = Pathname.new(File.expand_path('../../..', __FILE__))
11
- BOILERPLATE_DIR = BASE_DIR / 'boilerplate'
12
-
13
- class CLI
14
- include Helpers
15
- include Assertions
16
-
17
- def initialize args
18
- case command = args[0]
19
- when 'a', 'app'
20
- app(args)
21
- when 'g', 'gen', 'generate'
22
- generator(args)
23
- when 'd', 'docker'
24
- docker(args)
25
- when 'v', '-v', '--version'
26
- puts Appril::VERSION
27
- when nil, '-h', '--help'
28
- usage
29
- else
30
- display_error "Unknown command #{command}"
31
- usage
32
- end
33
- end
34
-
35
-
36
- def usage
37
- puts "
38
- Arguments in round brackets are required.
39
- Arguments in square brackets are optional.
40
-
41
-
42
- === Install a new app ===
43
- $ appril (app || a) (install || i) (dir || .) [-crudle]
44
- * If -crudle option provided it will install a Crudle app
45
-
46
- === Update existing app ===
47
- $ appril (app || a) (update || u) (dir || .)
48
-
49
- === Generate a new API ===
50
- $ appril (generate || g) (api) (api name) (dir || .)
51
-
52
- === Install Docker builder ===
53
- $ appril (docker || d) (install || i) (dir || .)
54
-
55
- === Update Docker builder ===
56
- $ appril (docker || d) (update || u) (dir || .)
57
-
58
- === Build Docker image and install run script ===
59
- $ appril (docker || d) (build || b) (dir || .) [-u] [-p]
60
- * If -u option provided it will only update the run script without building the image.
61
- * If -p option provided it will try to push the image to Docker registry after successful build.
62
-
63
- === Usage ===
64
- $ appril [-h || --help]
65
- ".split("\n").map {|l| "\t" + l.strip}.join("\n")
66
- end
67
-
68
-
69
- begin # App
70
- def app args
71
- opted_dir = args[2]
72
- assert_directory_provided(opted_dir)
73
- dir = expanded_path(opted_dir)
74
-
75
- case instruction = args[1]
76
- when 'i', 'install'
77
-
78
- app_install(dir, {
79
- working_dir_opted: working_dir_opted?(opted_dir),
80
- namespace: extract_namespace(args),
81
- crudle_app: args.find {|a| a == '-crudle'}
82
- })
83
-
84
- when 'u', 'update'
85
-
86
- app_update(dir)
87
-
88
- else
89
- unknown_instruction_error!(instruction, 'install (or i)', 'update (or u)')
90
- end
91
- end
92
-
93
- def app_install dir, opts
94
- create_dirname_for(dir)
95
- assert_installable_dir(dir, opts[:working_dir_opted])
96
- App::Install.new(dir, opts)
97
- end
98
-
99
- def app_update dir
100
- assert_is_app_dir(dir)
101
- App::Update.new(dir)
102
- end
103
- end
104
-
105
-
106
- begin # Generator
107
- def generator args
108
-
109
- case instruction = args[1]
110
- when 'api', 'a'
111
- api_name = args[2]
112
- assert_valid_api_name_given(api_name)
113
-
114
- app_dir = args[3]
115
- assert_directory_provided(app_dir)
116
- app_dir = expanded_path(app_dir)
117
- assert_is_app_dir(app_dir)
118
-
119
- gen_dir = app_dir / 'generators/api'
120
- assert_directory_exists(gen_dir)
121
-
122
- api_dir = app_dir / "base/api/#{api_name}"
123
- assert_directory_does_not_exists(api_dir)
124
-
125
- Generator::API.new(gen_dir, api_dir, api_name)
126
- else
127
- unknown_instruction_error!(instruction, 'api (or a)')
128
- end
129
- end
130
- end
131
-
132
-
133
- begin # Docker
134
- def docker args
135
- opted_dir = args[2]
136
- assert_directory_provided(opted_dir)
137
- dir = expanded_path(opted_dir)
138
-
139
- case instruction = args[1]
140
- when 'i', 'install'
141
-
142
- docker_install(dir, working_dir_opted: working_dir_opted?(opted_dir))
143
-
144
- when 'b', 'build'
145
-
146
- docker_build(dir, {
147
- update_runner_only: args.find {|a| a == '-u'},
148
- push_opted: args.find {|a| a == '-p'}
149
- })
150
-
151
- when 'u', 'update'
152
-
153
- docker_update(dir)
154
-
155
- else
156
- unknown_instruction_error!(instruction, 'install (or i)', 'build (or b)', 'update (or u)')
157
- end
158
- end
159
-
160
- def docker_install dir, opts
161
- create_dirname_for(dir)
162
- assert_installable_dir(dir, opts[:working_dir_opted])
163
- Docker::Install.new(dir, opts)
164
- end
165
-
166
- def docker_build dir, opts
167
- assert_directory_exists(dir)
168
- assert_config_file_exists(dir)
169
- Docker::Build.new(dir, opts)
170
- end
171
-
172
- def docker_update dir
173
- assert_is_docker_dir(dir)
174
- Docker::Update.new(dir)
175
- end
176
- end
177
-
178
-
179
- def unknown_instruction_error! instruction, *available_instructions
180
- fatal_error! "Unknown instruction #{instruction}. Use one of #{available_instructions*', '}"
181
- end
182
-
183
-
184
- def self.run cmd
185
- puts "", "$ #{cmd}"
186
- PTY.spawn cmd do |r, w, pid|
187
- begin
188
- r.sync
189
- r.each_char do |char|
190
- print(char)
191
- end
192
- rescue Errno::EIO => e
193
- # simply ignoring this
194
- ensure
195
- Process.wait(pid)
196
- end
197
- end
198
- end
199
- end
200
- end
201
-
202
- require 'appril/cli/app'
203
- require 'appril/cli/generator'
204
- require 'appril/cli/docker'