Module: Satorix::CI::Deploy::Flynn
Defined Under Namespace
Modules: EnvironmentVariables, Resources, Routes, Scale
Constant Summary
Constants included
from Satorix
VERSION
Instance Method Summary
collapse
Methods included from Scale
#adjust_scale, #current_scale, #defined_scale, #defined_scale_key, #fc_scale, #scale_options_to_set, #scale_string_to_hash
Methods included from Routes
#add_tls_to_route, #canonical_domain, #canonical_domain_information, #canonical_domain_protocol, #canonical_uri, #canonical_uri?, #configure_routes, #crt_for_ddev_id, #custom_crt_for_ddev_id?, #custom_key_for_ddev_id?, #defined_and_internal_routes, #defined_routes, #display_routing_information, #env_var_crt_prefix, #env_var_domain_prefix, #env_var_key_prefix, #fc_route, #fc_route_add, #fc_route_remove, #fc_route_update, #find_or_create_route, #flynn_internal_routes, #key_for_ddev_id, #only_whitespace, #remove_undefined_routes, #route_ids, #routes, #routes_all_of, #routes_legend, #routes_to_remove, #routes_with_legend, #service_for_route_id, #setup_routes, #urlified_routes, #urlified_routes_for_display, #urlify_route, #urlify_route_for_display, #use_lets_encrypt?, #use_tls?, #user_defined_tls?
Methods included from Resources
#add_resources, #available_resources, #current_resource_provider_names, #desired_resource_provider_names, #remove_resources, #resource, #resource_provider_key, #resources_to_add, #resources_to_remove, #set_resources
#adjust_env_vars, #aeev_key_exists?, #aeev_prefix, #ci_provided_env_vars, #current_flynn_keys, #desired_env_vars, #ensure_required_env_vars_are_defined, #env_set, #env_unset, #env_vars, #env_vars_to_set, #env_vars_to_unset, #exported_aeevs_key
#colorize, #colors, #humanize_time, #log, #log_bench, #log_command, #log_duration, #log_error, #log_error_and_abort, #log_header, #run_command, #source_env_from
Methods included from Satorix
#add_user, #airbrake_configured?, #airbrake_project_id, #airbrake_project_key, #airbrake_start, #app_dir, #available_jobs, #bin_dir, #build_dir, #ci_commit_ref_name, #ci_commit_sha, #ci_job_name, #ci_job_stage, #current_branch, #custom_loader_full_path, #custom_loader_relative_path, #default_jobs, #django_app?, #execute_as_user, #job_class, #load_custom, #paths, #prepare_app_environment, #project_name, #rails_app?, #ruby_gem?, #setup_directories, #skip_buildpack?, #user_exists?, #yarn?, #yarn_lock_file
Instance Method Details
#add_cluster ⇒ Object
45
46
47
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 45
def add_cluster
run_command "flynn cluster add --force --default --tls-pin=#{ tls_pin } #{ cluster_name } #{ domain_for_cluster } #{ key }", filtered_text: [tls_pin, key]
end
|
#add_remote ⇒ Object
50
51
52
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 50
def add_remote
run_command "flynn -a #{ project_name } remote add #{ cluster_name } -y"
end
|
#cluster_name ⇒ Object
55
56
57
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 55
def cluster_name
domain_for_cluster
end
|
60
61
62
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 60
def configure_inactive_slug_releases
run_command 'flynn meta set gc.max_inactive_slug_releases=2'
end
|
#create_project ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 65
def create_project
if project_exists?
log "Skipping - Flynn project '#{ project_name }' already exists."
else
run_command "flynn create --remote=#{ cluster_name } -y #{ project_name }"
end
end
|
#deploy ⇒ Object
74
75
76
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 74
def deploy
run_command "git push #{ cluster_name } HEAD:refs/heads/master"
end
|
#domain_for_cluster ⇒ Object
79
80
81
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 79
def domain_for_cluster
ENV["FLYNN_#{ current_branch }_DOMAIN"]
end
|
#domain_for_web_host ⇒ Object
84
85
86
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 84
def domain_for_web_host
"#{ current_branch.downcase }.#{ hosting_namespace }"
end
|
#go ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 26
def go
log_bench('Adding a local reference to the remote Flynn cluster...') { add_cluster }
log_bench('Creating Flynn project...') { create_project }
log_bench('Adding Flynn remote to CI local git...') { add_remote }
log_bench('Adjusting Flynn environment variables...') { adjust_env_vars }
log_bench('Configuring Flynn inactive slug release count...') { configure_inactive_slug_releases }
log_bench('Setting resources...') { set_resources }
log_bench('Deploying to Flynn...') { deploy }
log_bench('Running Database migrations...') { run_database_migrations } if run_database_migrations?
log_bench('Scaling application processes...') { adjust_scale }
log_bench('Setting up routes...') { setup_routes }
end
|
#hosting_namespace ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 89
def hosting_namespace
if ENV['SATORIX_HOSTING_NAMESPACE'].to_s !~ only_whitespace
ENV['SATORIX_HOSTING_NAMESPACE']
else
log_error_and_abort("Satorix configuration error: Missing SATORIX_HOSTING_NAMESPACE.\n\nPlease contact support.\n")
end
end
|
#key ⇒ Object
99
100
101
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 99
def key
ENV["FLYNN_#{ current_branch }_KEY"]
end
|
#project_exists? ⇒ Boolean
104
105
106
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 104
def project_exists?
`flynn apps`.split(/\R/).map { |a| a.split.last }.include? project_name
end
|
#run_database_migrations ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 114
def run_database_migrations
if desired_resource_provider_names.nil? || desired_resource_provider_names.empty?
log 'Skipping migrations, no database has been defined. Please see the resources section of this log for more information.'
else
run_command('flynn run --enable-log bundle exec rake db:migrate') if rails_app?
run_command('flynn run --enable-log python public/manage.py migrate') if django_app?
end
end
|
#run_database_migrations? ⇒ Boolean
109
110
111
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 109
def run_database_migrations?
[rails_app?, django_app?].any?
end
|
#skip_buildpack ⇒ Object
40
41
42
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 40
def skip_buildpack
true
end
|
#tls_pin ⇒ Object
124
125
126
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 124
def tls_pin
ENV["FLYNN_#{ current_branch }_TLSPIN"]
end
|