mobile_workflow 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mwf +33 -0
- data/lib/generators/mobile_workflow/install/templates/Gemfile.erb +53 -0
- data/lib/generators/mobile_workflow/install/templates/Procfile +2 -0
- data/lib/generators/mobile_workflow/install/templates/Procfile.dev +1 -0
- data/lib/generators/mobile_workflow/install/templates/README.md.erb +22 -0
- data/lib/generators/mobile_workflow/install/templates/ability.rb +7 -0
- data/lib/generators/mobile_workflow/install/templates/storage.s3.yml +14 -0
- data/lib/mobile_workflow/cli.rb +9 -0
- data/lib/mobile_workflow/cli/app_builder.rb +84 -0
- data/lib/mobile_workflow/cli/app_server_cleaner.rb +24 -0
- data/lib/mobile_workflow/cli/app_server_generator.rb +98 -0
- data/lib/mobile_workflow/cli/aws_backend.rb +80 -0
- data/lib/mobile_workflow/cli/dokku_backend.rb +57 -0
- data/lib/mobile_workflow/cli/heroku_backend.rb +47 -0
- data/lib/mobile_workflow/version.rb +3 -1
- metadata +20 -12
- data/lib/tasks/mobile_workflow_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db09862ea4eafb49f52d1d37ca42e97408b77e0e0d406d00d83fb83ab47e00a1
|
4
|
+
data.tar.gz: f7720006c7171c7e4ca98861497de3f8064ffed9e4bad53c9a8205d35adf6624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8935b569351f6f584d9587ca9e250425f44b8a8a2ed0829d04032d889216ad92c2333ceba287c354eb3d6d679716889a335e5dbecedeba4ee5cfa975d19b1fb
|
7
|
+
data.tar.gz: 5c9856de14ffb565562078371a1b9b8bbef2529f80c2ae027378f4a73d41effe9737091563d567f911b9ff81d29ab668d6fb91ce753afb6f69e4d5514b1172af
|
data/bin/mwf
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/mobile_workflow/cli'
|
3
|
+
|
4
|
+
# Byebug for dev
|
5
|
+
begin
|
6
|
+
require 'byebug'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
if ARGV.empty?
|
11
|
+
puts "USAGE: mwf <platform> <command> [options]"
|
12
|
+
puts "Example: mwf rails create:app_server --help"
|
13
|
+
exit 0
|
14
|
+
elsif ['-v', '--version'].include? ARGV[0]
|
15
|
+
puts MobileWorkflow::VERSION
|
16
|
+
exit 0
|
17
|
+
elsif 'rails' == ARGV[0] && 'create:app_server' == ARGV[1]
|
18
|
+
ARGV.shift
|
19
|
+
ARGV.shift
|
20
|
+
|
21
|
+
templates_root = File.expand_path(File.join("..", "lib", "generators", "mobile_workflow", "install", "templates"), File.dirname(__FILE__))
|
22
|
+
MobileWorkflow::Cli::AppServerGenerator.source_root templates_root
|
23
|
+
MobileWorkflow::Cli::AppServerGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
|
24
|
+
MobileWorkflow::Cli::AppServerGenerator.start
|
25
|
+
elsif 'rails' == ARGV[0] && 'destroy:app_server' == ARGV[1]
|
26
|
+
ARGV.shift
|
27
|
+
ARGV.shift
|
28
|
+
|
29
|
+
ARGV.unshift(MobileWorkflow::Cli::AppServerCleaner.default_task) unless ARGV[0] == '--help'
|
30
|
+
MobileWorkflow::Cli::AppServerCleaner.start(ARGV)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
|
4
|
+
ruby '2.6.6'
|
5
|
+
|
6
|
+
# Core Gems
|
7
|
+
gem 'rails', '~> 6.0.2', '>= 6.0.2.2'
|
8
|
+
gem 'puma', '~> 4.1'
|
9
|
+
gem 'sass-rails', '>= 6'
|
10
|
+
gem 'turbolinks', '~> 5'
|
11
|
+
gem 'bootsnap', '>= 1.4.2', require: false
|
12
|
+
|
13
|
+
# Mobile Workflow
|
14
|
+
#gem 'mobile_workflow', path: '../mobile_workflow'
|
15
|
+
gem 'mobile_workflow', github: 'FutureWorkshops/mobile_workflow'
|
16
|
+
|
17
|
+
# Authorisation / Authentication
|
18
|
+
<%- if options[:doorkeeper_oauth] %>
|
19
|
+
gem 'doorkeeper'
|
20
|
+
gem 'bcrypt-ruby'
|
21
|
+
<%- end %>
|
22
|
+
gem 'cancancan', '~> 3.1'
|
23
|
+
|
24
|
+
# Admin console
|
25
|
+
gem 'administrate', '~> 0.13.0'
|
26
|
+
gem 'administrate-field-active_storage'
|
27
|
+
gem 'administrate-field-enum'
|
28
|
+
|
29
|
+
<%- if options[:s3_storage] %>
|
30
|
+
# Backend storage for S3
|
31
|
+
gem "image_processing"
|
32
|
+
gem 'aws-sdk-s3', '~> 1.60', '>= 1.60.1'
|
33
|
+
gem 'aws-sdk-sns', '~> 1.23'
|
34
|
+
<%- end %>
|
35
|
+
|
36
|
+
group :development do
|
37
|
+
gem 'web-console', '>= 3.3.0'
|
38
|
+
gem 'listen', '>= 3.0.5', '< 3.2'
|
39
|
+
gem 'spring'
|
40
|
+
gem 'spring-watcher-listen', '~> 2.0.0'
|
41
|
+
end
|
42
|
+
|
43
|
+
group :development, :test do
|
44
|
+
gem 'sqlite3'
|
45
|
+
gem 'rspec-rails', '~> 4.0.0'
|
46
|
+
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
47
|
+
gem 'dotenv-rails'
|
48
|
+
gem 'factory_bot_rails'
|
49
|
+
end
|
50
|
+
|
51
|
+
group :production do
|
52
|
+
gem 'pg', '>= 0.18', '< 2.0'
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
web: bundle exec rackup config.ru -p $PORT
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# <%= app_name.humanize %>
|
2
|
+
|
3
|
+
## Prereqs
|
4
|
+
* Ruby >= 2.5.5
|
5
|
+
* Rails >= 6.0.0
|
6
|
+
|
7
|
+
Optional
|
8
|
+
* Heroku toolbelt
|
9
|
+
* Heroku account
|
10
|
+
|
11
|
+
## Getting Started
|
12
|
+
|
13
|
+
After you have cloned this repo, run this setup script to set up your machine
|
14
|
+
with the necessary dependencies to run and test this app:
|
15
|
+
|
16
|
+
% ./bin/setup
|
17
|
+
|
18
|
+
After setting up, you can run the application using [Heroku Local]:
|
19
|
+
|
20
|
+
% heroku local
|
21
|
+
|
22
|
+
[Heroku Local]: https://devcenter.heroku.com/articles/heroku-local
|
@@ -0,0 +1,14 @@
|
|
1
|
+
test:
|
2
|
+
service: Disk
|
3
|
+
root: <%= Rails.root.join("tmp/storage") %>
|
4
|
+
|
5
|
+
local:
|
6
|
+
service: Disk
|
7
|
+
root: <%= Rails.root.join("storage") %>
|
8
|
+
|
9
|
+
amazon:
|
10
|
+
service: S3
|
11
|
+
access_key_id: <%= ENV['AWS_ACCESS_ID'] %>
|
12
|
+
secret_access_key: <%= ENV['AWS_SECRET_KEY'] %>
|
13
|
+
region: <%= ENV['AWS_REGION'] %>
|
14
|
+
bucket: <%= ENV['AWS_BUCKET_NAME'] %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "mobile_workflow/version"
|
2
|
+
|
3
|
+
require "mobile_workflow/cli/app_server_generator"
|
4
|
+
require "mobile_workflow/cli/app_builder"
|
5
|
+
require "mobile_workflow/cli/app_server_cleaner"
|
6
|
+
|
7
|
+
require "mobile_workflow/cli/aws_backend"
|
8
|
+
require "mobile_workflow/cli/heroku_backend"
|
9
|
+
require "mobile_workflow/cli/dokku_backend"
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module MobileWorkflow::Cli
|
2
|
+
class AppBuilder < Rails::AppBuilder
|
3
|
+
def readme
|
4
|
+
template 'README.md.erb', 'README.md'
|
5
|
+
end
|
6
|
+
|
7
|
+
def gemfile
|
8
|
+
template 'Gemfile.erb', 'Gemfile'
|
9
|
+
end
|
10
|
+
|
11
|
+
def procfiles
|
12
|
+
copy_file 'Procfile', 'Procfile'
|
13
|
+
copy_file 'Procfile.dev', 'Procfile.dev'
|
14
|
+
end
|
15
|
+
|
16
|
+
def rspec_generator
|
17
|
+
generate 'rspec:install'
|
18
|
+
end
|
19
|
+
|
20
|
+
def ability_generator
|
21
|
+
copy_file 'ability.rb', 'app/models/ability.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
def active_storage
|
25
|
+
rails_command 'active_storage:install'
|
26
|
+
copy_file 'storage.s3.yml', 'config/storage.yml'
|
27
|
+
gsub_file 'config/environments/production.rb', 'config.active_storage.service = :local', 'config.active_storage.service = :amazon'
|
28
|
+
end
|
29
|
+
|
30
|
+
def mobile_workflow_generator(open_api_spec_path)
|
31
|
+
copy_file open_api_spec_path, 'config/open_api_spec.json'
|
32
|
+
gen_opts = ""
|
33
|
+
gen_opts += "--doorkeeper_oauth" if options[:doorkeeper_oauth]
|
34
|
+
generate "mobile_workflow:install #{gen_opts}"
|
35
|
+
|
36
|
+
# Copy user migrations if needed
|
37
|
+
rails_command 'mobile_workflow:install:migrations' if options[:doorkeeper_oauth]
|
38
|
+
end
|
39
|
+
|
40
|
+
def s3_backend(region)
|
41
|
+
@region = region
|
42
|
+
aws_backend.create
|
43
|
+
aws_backend.write_env
|
44
|
+
|
45
|
+
if options[:heroku]
|
46
|
+
heroku_backend.sync_dotenv
|
47
|
+
sleep 10 # Wait for the server to restart
|
48
|
+
aws_backend.create_topic_subscription(heroku_backend.notifications_endpoint)
|
49
|
+
elsif options[:dokku]
|
50
|
+
dokku_backend.sync_dotenv
|
51
|
+
aws_backend.create_topic_subscription(dokku_backend.notifications_endpoint)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def heroku
|
57
|
+
heroku_backend.create
|
58
|
+
heroku_backend.configure_activestorage if options[:s3_storage]
|
59
|
+
heroku_backend.deploy
|
60
|
+
heroku_backend.sync_dotenv
|
61
|
+
end
|
62
|
+
|
63
|
+
def dokku(dokku_host)
|
64
|
+
@dokku_host = dokku_host
|
65
|
+
dokku_backend.create
|
66
|
+
dokku_backend.configure_activestorage if options[:s3_storage]
|
67
|
+
dokku_backend.deploy
|
68
|
+
dokku_backend.sync_dotenv
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def aws_backend
|
73
|
+
@aws_backend ||= AwsBackend.new(app_name: app_name, region: @region)
|
74
|
+
end
|
75
|
+
|
76
|
+
def dokku_backend
|
77
|
+
@dokku_backend ||= DokkuBackend.new(app_name: app_name, dokku_host: @dokku_host)
|
78
|
+
end
|
79
|
+
|
80
|
+
def heroku_backend
|
81
|
+
@heroku_backend ||= HerokuBackend.new(app_name: app_name)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/app/app_generator'
|
3
|
+
require 'json'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
+
|
6
|
+
module MobileWorkflow::Cli
|
7
|
+
class AppServerCleaner < Thor
|
8
|
+
class_option :version, type: :boolean, aliases: "-v", desc: "Show version number and quit"
|
9
|
+
class_option :help, type: :boolean, aliases: '-h', desc: "Show this help message and quit"
|
10
|
+
|
11
|
+
class_option :heroku, type: :boolean, default: false, desc: "Clean Heroku app"
|
12
|
+
class_option :s3_storage, type: :boolean, default: false, desc: "Clean an s3 backend for attachment upload and storage"
|
13
|
+
class_option :aws_region, type: :string, default: 'us-east-1', desc: "Specify a region to create AWS resources in"
|
14
|
+
|
15
|
+
default_task :clean
|
16
|
+
|
17
|
+
desc "rails destroy:app_server APP_NAME", "Destroy App server"
|
18
|
+
def clean(app_name)
|
19
|
+
`rm -rf #{app_name}`
|
20
|
+
AwsBackend.new(app_name: app_name, region: options[:aws_region]).destroy if options[:s3_storage]
|
21
|
+
HerokuBackend.new(app_name: app_name).destroy if options[:heroku]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/app/app_generator'
|
3
|
+
require 'json'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
+
|
6
|
+
module MobileWorkflow::Cli
|
7
|
+
class AppServerGenerator < Rails::Generators::AppGenerator
|
8
|
+
hide!
|
9
|
+
class_option :skip_test, type: :boolean, default: true, desc: "Skip Test Unit"
|
10
|
+
class_option :force, type: :boolean, default: true, desc: "Force overwrite"
|
11
|
+
class_option :skip_webpack_install, type: :boolean, default: true, desc: "Skip webpacker installation"
|
12
|
+
|
13
|
+
class_option :version, type: :boolean, aliases: "-v", desc: "Show version number and quit"
|
14
|
+
class_option :help, type: :boolean, aliases: '-h', desc: "Show this help message and quit"
|
15
|
+
|
16
|
+
class_option :heroku, type: :boolean, default: false, desc: "Create Heroku app"
|
17
|
+
|
18
|
+
class_option :dokku, type: :boolean, default: false, desc: "Create Dokku app"
|
19
|
+
class_option :dokku_host, type: :string, desc: "Specify the Dokku host machine e.g. 18.131.127.164"
|
20
|
+
|
21
|
+
class_option :s3_storage, type: :boolean, default: false, desc: "Create an s3 backend for attachment upload and storage"
|
22
|
+
class_option :aws_region, type: :string, default: 'us-east-1', desc: "Specify a region to create AWS resources in"
|
23
|
+
|
24
|
+
class_option :doorkeeper_oauth, type: :boolean, default: false, desc: "Use Doorkeeper gem for OAuth login"
|
25
|
+
|
26
|
+
def self.banner
|
27
|
+
"mwf rails create:app_server <directory> <OpenAPI Spec file path> [options]"
|
28
|
+
end
|
29
|
+
|
30
|
+
def finish_template
|
31
|
+
super
|
32
|
+
after_bundle do
|
33
|
+
run "spring stop"
|
34
|
+
build :procfiles
|
35
|
+
build :rspec_generator
|
36
|
+
build :ability_generator
|
37
|
+
build :active_storage if options[:s3_storage]
|
38
|
+
build :mobile_workflow_generator, ARGV[1]
|
39
|
+
setup_db
|
40
|
+
generate_administrate
|
41
|
+
|
42
|
+
generate_dot_env
|
43
|
+
initial_git_commit
|
44
|
+
|
45
|
+
build :heroku if options[:heroku]
|
46
|
+
build :dokku, options[:dokku_host] if options[:dokku]
|
47
|
+
build :s3_backend, options[:aws_region] if options[:s3_storage]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def get_builder_class
|
54
|
+
MobileWorkflowCli::AppBuilder
|
55
|
+
end
|
56
|
+
|
57
|
+
# Todo: MBS - move these methods to the builder class
|
58
|
+
# Ideally override RailsBuilder methods
|
59
|
+
private
|
60
|
+
def generate_administrate
|
61
|
+
generate 'administrate:install'
|
62
|
+
file 'app/assets/config/manifest.js', <<-CODE
|
63
|
+
//= link administrate/application.css
|
64
|
+
//= link administrate/application.js
|
65
|
+
CODE
|
66
|
+
|
67
|
+
file 'app/controllers/admin/application_controller.rb', <<-CODE
|
68
|
+
module Admin
|
69
|
+
class ApplicationController < Administrate::ApplicationController
|
70
|
+
http_basic_authenticate_with(name: ENV["ADMIN_USER"], password: ENV["ADMIN_PASSWORD"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
CODE
|
74
|
+
generate 'administrate:routes'
|
75
|
+
end
|
76
|
+
|
77
|
+
def setup_db
|
78
|
+
rails_command "db:drop"
|
79
|
+
rails_command "db:create"
|
80
|
+
rails_command "db:migrate"
|
81
|
+
end
|
82
|
+
|
83
|
+
def initial_git_commit
|
84
|
+
git add: "."
|
85
|
+
git commit: %Q{ -m 'Initial commit' }
|
86
|
+
end
|
87
|
+
|
88
|
+
def generate_dot_env
|
89
|
+
admin_user = 'admin'
|
90
|
+
admin_password = SecureRandom.base64(12)
|
91
|
+
|
92
|
+
file '.env', <<-CODE
|
93
|
+
ADMIN_USER=#{admin_user}
|
94
|
+
ADMIN_PASSWORD=#{admin_password}
|
95
|
+
CODE
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module MobileWorkflow::Cli
|
4
|
+
class AwsBackend
|
5
|
+
|
6
|
+
attr_accessor :access_id, :secret_key, :region, :bucket_name
|
7
|
+
|
8
|
+
def initialize(app_name:, region:)
|
9
|
+
@app_name = app_name
|
10
|
+
@aws_name = @app_name.gsub("_", "-")
|
11
|
+
@region = region
|
12
|
+
end
|
13
|
+
|
14
|
+
def bucket_name
|
15
|
+
@aws_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
bucket_configuration = ''
|
20
|
+
bucket_configuration += "--create-bucket-configuration LocationConstraint=#{@region}" unless @region.eql? 'us-east-1'
|
21
|
+
aws_command "aws s3api create-bucket --bucket #{@aws_name} --acl private --region #{@region} #{bucket_configuration}"
|
22
|
+
@topic_arn = aws_command("aws sns create-topic --name #{@aws_name} --region #{@region}")["TopicArn"]
|
23
|
+
aws_command "aws iam create-user --user-name #{@aws_name}"
|
24
|
+
aws_command "aws iam put-user-policy --user-name #{@aws_name} --policy-name s3 --policy-document '{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:PutObject\",\"s3:PutObjectAcl\",\"s3:GetObject\", \"s3:DeleteObject\"],\"Resource\":[\"arn:aws:s3:::#{@aws_name}/*\"]}, {\"Effect\": \"Allow\", \"Action\": \"s3:ListBucket\", \"Resource\": \"arn:aws:s3:::#{@aws_name}\"}]}'"
|
25
|
+
aws_command "aws iam put-user-policy --user-name #{@aws_name} --policy-name sns --policy-document '{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"sns:ConfirmSubscription\"],\"Resource\":[\"#{@topic_arn}\"]}]}'"
|
26
|
+
aws_command "aws sns set-topic-attributes --topic-arn #{@topic_arn} --region #{@region} --attribute-name Policy --attribute-value '{\"Version\": \"2012-10-17\", \"Id\": \"s3\", \"Statement\": [{\"Sid\": \"#{@aws_name}-s3-sid\", \"Effect\": \"Allow\", \"Principal\": {\"AWS\": \"*\"}, \"Action\": \"SNS:Publish\", \"Resource\": \"#{@topic_arn}\", \"Condition\": {\"ArnEquals\": {\"aws:SourceArn\": \"arn:aws:s3:::#{@aws_name}\"}}}]}'"
|
27
|
+
aws_command "aws s3api put-bucket-notification-configuration --bucket #{@aws_name} --notification-configuration '{\"TopicConfigurations\": [{\"TopicArn\": \"#{@topic_arn}\", \"Events\": [\"s3:ObjectCreated:*\"]}]}'"
|
28
|
+
aws_credentials_json = aws_command("aws iam create-access-key --user-name #{@aws_name}")["AccessKey"]
|
29
|
+
@access_id, @secret_key = aws_credentials_json["AccessKeyId"], aws_credentials_json["SecretAccessKey"]
|
30
|
+
return @access_id, @secret_key
|
31
|
+
end
|
32
|
+
|
33
|
+
def put_env
|
34
|
+
puts "AWS_ACCESS_ID=#{access_id}"
|
35
|
+
puts "AWS_SECRET_KEY=#{secret_key}"
|
36
|
+
puts "AWS_REGION=#{region}"
|
37
|
+
puts "AWS_BUCKET_NAME=#{bucket_name}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def write_env
|
41
|
+
open('.env', 'a') { |f|
|
42
|
+
f.puts "AWS_ACCESS_ID=#{access_id}"
|
43
|
+
f.puts "AWS_SECRET_KEY=#{secret_key}"
|
44
|
+
f.puts "AWS_REGION=#{region}"
|
45
|
+
f.puts "AWS_BUCKET_NAME=#{bucket_name}"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_topic_subscription(endpoint)
|
50
|
+
aws_command "aws sns subscribe --topic-arn #{@topic_arn} --region #{@region} --protocol https --notification-endpoint #{endpoint}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
aws_command "aws s3api delete-bucket --bucket #{@aws_name} --region #{@region}"
|
55
|
+
|
56
|
+
aws_command("aws sns list-topics")["Topics"].each do |topic|
|
57
|
+
topic_arn = topic["TopicArn"]
|
58
|
+
aws_command "aws sns delete-topic --topic-arn '#{topic_arn}'" if topic_arn.end_with?(@aws_name)
|
59
|
+
end
|
60
|
+
|
61
|
+
aws_command "aws iam delete-user-policy --user-name #{@aws_name} --policy-name s3"
|
62
|
+
aws_command "aws iam delete-user-policy --user-name #{@aws_name} --policy-name sns"
|
63
|
+
aws_command("aws iam list-access-keys --user-name #{@aws_name}")["AccessKeyMetadata"].each do |accessKeyMetadata|
|
64
|
+
aws_command "aws iam delete-access-key --user-name #{@aws_name} --access-key #{accessKeyMetadata["AccessKeyId"]}"
|
65
|
+
end
|
66
|
+
aws_command "aws iam delete-user --user-name #{@aws_name}"
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def aws_command(command)
|
71
|
+
puts "Running: #{command}"
|
72
|
+
output = `#{command}`
|
73
|
+
return nil if output == nil || output.strip == ""
|
74
|
+
|
75
|
+
puts "Output: #{output}"
|
76
|
+
JSON.parse(output)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module MobileWorkflow::Cli
|
2
|
+
class DokkuBackend
|
3
|
+
def initialize(dokku_host:, app_name:)
|
4
|
+
@dokku_host = dokku_host
|
5
|
+
@dokku_app_name = app_name.gsub("_", "-")
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
remote_command "dokku apps:create #{@dokku_app_name}"
|
10
|
+
remote_command "dokku postgres:create #{@dokku_app_name}"
|
11
|
+
remote_command "dokku postgres:link #{@dokku_app_name} #{@dokku_app_name}"
|
12
|
+
remote_command "dokku domains:enable #{@dokku_app_name}"
|
13
|
+
remote_command "dokku letsencrypt #{@dokku_app_name}"
|
14
|
+
|
15
|
+
local_command "git remote add dokku dokku@#{@dokku_host}:#{@dokku_app_name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure_activestorage
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def deploy
|
23
|
+
local_command "git push dokku master"
|
24
|
+
end
|
25
|
+
|
26
|
+
def sync_dotenv
|
27
|
+
env = File.read(".env").split.join(" ")
|
28
|
+
puts "Setting env: #{env}"
|
29
|
+
local_command "dokku config:set #{env}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy
|
33
|
+
remote_command "dokku apps:destroy #{@dokku_app_name}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def dokku_app_host
|
37
|
+
remote_command "dokku url #{@dokku_app_name}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def notifications_endpoint
|
41
|
+
"https://#{dokku_app_host}/sns_notifications"
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def remote_command(command)
|
46
|
+
command = "ssh -t ubuntu@#{@dokku_host} '#{command}'"
|
47
|
+
local_command(command)
|
48
|
+
end
|
49
|
+
|
50
|
+
def local_command(command)
|
51
|
+
puts "Running: #{command}"
|
52
|
+
output = `#{command}`
|
53
|
+
puts "Output: #{output}" unless output.blank?
|
54
|
+
return output
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module MobileWorkflow::Cli
|
2
|
+
class HerokuBackend
|
3
|
+
def initialize(app_name:)
|
4
|
+
@heroku_app_name = app_name.gsub("_", "-")
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
heroku_command "heroku create #{@heroku_app_name}"
|
9
|
+
heroku_command "git push --set-upstream heroku master"
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure_activestorage
|
13
|
+
heroku_command "heroku buildpacks:add -i 1 https://github.com/heroku/heroku-buildpack-activestorage-preview --app #{@heroku_app_name}"
|
14
|
+
heroku_command "heroku labs:enable runtime-dyno-metadata --app #{@heroku_app_name}" # Gives access to heroku variables which can be used to construct URLs
|
15
|
+
|
16
|
+
# Force recompile after buildpacks change
|
17
|
+
heroku_command "git commit --allow-empty -m 'empty commit'"
|
18
|
+
deploy
|
19
|
+
end
|
20
|
+
|
21
|
+
def deploy
|
22
|
+
heroku_command "git push"
|
23
|
+
end
|
24
|
+
|
25
|
+
def sync_dotenv
|
26
|
+
env = File.read(".env").split.join(" ")
|
27
|
+
puts "Setting env: #{env}"
|
28
|
+
heroku_command "heroku config:set #{env} --app #{@heroku_app_name}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
heroku_command "heroku destroy #{@heroku_app_name} --confirm #{@heroku_app_name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def notifications_endpoint
|
36
|
+
"https://#{@heroku_app_name}.herokuapp.com/sns_notifications"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def heroku_command(command)
|
41
|
+
puts "Running: #{command}"
|
42
|
+
output = `#{command}`
|
43
|
+
puts "Output: #{output}"
|
44
|
+
return output
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobile_workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
@@ -14,22 +14,16 @@ dependencies:
|
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0.3
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 6.0.
|
19
|
+
version: 6.0.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 6.0.3
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 6.0.
|
26
|
+
version: 6.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: sqlite3
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,7 +83,8 @@ dependencies:
|
|
89
83
|
description:
|
90
84
|
email:
|
91
85
|
- matt@futureworkshops.com
|
92
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- mwf
|
93
88
|
extensions: []
|
94
89
|
extra_rdoc_files: []
|
95
90
|
files:
|
@@ -106,20 +101,33 @@ files:
|
|
106
101
|
- app/mailers/mobile_workflow/application_mailer.rb
|
107
102
|
- app/models/concerns/mobile_workflow/displayable.rb
|
108
103
|
- app/views/layouts/mobile_workflow/application.html.erb
|
104
|
+
- bin/mwf
|
109
105
|
- config/routes.rb
|
110
106
|
- db/migrate/20200823174210_create_users.rb
|
111
107
|
- lib/generators/mobile_workflow/controller_generator.rb
|
112
108
|
- lib/generators/mobile_workflow/install/install_generator.rb
|
109
|
+
- lib/generators/mobile_workflow/install/templates/Gemfile.erb
|
110
|
+
- lib/generators/mobile_workflow/install/templates/Procfile
|
111
|
+
- lib/generators/mobile_workflow/install/templates/Procfile.dev
|
112
|
+
- lib/generators/mobile_workflow/install/templates/README.md.erb
|
113
|
+
- lib/generators/mobile_workflow/install/templates/ability.rb
|
113
114
|
- lib/generators/mobile_workflow/install/templates/api_controller.rb.erb
|
114
115
|
- lib/generators/mobile_workflow/install/templates/seeds.rb.erb
|
115
116
|
- lib/generators/mobile_workflow/install/templates/sessions_controller.rb.erb
|
117
|
+
- lib/generators/mobile_workflow/install/templates/storage.s3.yml
|
116
118
|
- lib/generators/mobile_workflow/install/templates/user.rb.erb
|
117
119
|
- lib/generators/mobile_workflow/templates/controller.rb.erb
|
118
120
|
- lib/generators/mobile_workflow/templates/controller_spec.rb.erb
|
119
121
|
- lib/mobile_workflow.rb
|
122
|
+
- lib/mobile_workflow/cli.rb
|
123
|
+
- lib/mobile_workflow/cli/app_builder.rb
|
124
|
+
- lib/mobile_workflow/cli/app_server_cleaner.rb
|
125
|
+
- lib/mobile_workflow/cli/app_server_generator.rb
|
126
|
+
- lib/mobile_workflow/cli/aws_backend.rb
|
127
|
+
- lib/mobile_workflow/cli/dokku_backend.rb
|
128
|
+
- lib/mobile_workflow/cli/heroku_backend.rb
|
120
129
|
- lib/mobile_workflow/engine.rb
|
121
130
|
- lib/mobile_workflow/version.rb
|
122
|
-
- lib/tasks/mobile_workflow_tasks.rake
|
123
131
|
- lib/templates/active_record/model/model.rb.erb
|
124
132
|
homepage: https://github.com/futureworkshops/mobile_workflow
|
125
133
|
licenses:
|
@@ -133,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
141
|
requirements:
|
134
142
|
- - ">="
|
135
143
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
144
|
+
version: 2.5.5
|
137
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
146
|
requirements:
|
139
147
|
- - ">="
|