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
43
44
45
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 43
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
48
49
50
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 48
def add_remote
run_command(['flynn', '-a', project_name, 'remote', 'add', cluster_name, '-y'])
end
|
#cluster_name ⇒ Object
53
54
55
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 53
def cluster_name
domain_for_cluster
end
|
58
59
60
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 58
def configure_inactive_slug_releases
run_command(%w[flynn meta set gc.max_inactive_slug_releases=2])
end
|
#create_project ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 63
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
72
73
74
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 72
def deploy
run_command(['git', 'push', cluster_name, 'HEAD:refs/heads/master'])
end
|
#domain_for_cluster ⇒ Object
77
78
79
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 77
def domain_for_cluster
ENV["FLYNN_#{ current_branch }_DOMAIN"]
end
|
#domain_for_web_host ⇒ Object
82
83
84
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 82
def domain_for_web_host
"#{ current_branch.downcase }.#{ hosting_namespace }"
end
|
#go ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 24
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
87
88
89
90
91
92
93
94
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 87
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
97
98
99
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 97
def key
ENV["FLYNN_#{ current_branch }_KEY"]
end
|
#project_exists? ⇒ Boolean
102
103
104
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 102
def project_exists?
run_command(%w[flynn apps], quiet: true).split(/\R/).map { |a| a.split.last }.include? project_name
end
|
#run_database_migrations ⇒ Object
112
113
114
115
116
117
118
119
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 112
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(%w[flynn run --enable-log bundle exec rake db:migrate]) if rails_app?
run_command(%w[flynn run --enable-log python public/manage.py migrate]) if django_app?
end
end
|
#run_database_migrations? ⇒ Boolean
107
108
109
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 107
def run_database_migrations?
[rails_app?, django_app?].any?
end
|
#skip_buildpack ⇒ Object
38
39
40
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 38
def skip_buildpack
true
end
|
#tls_pin ⇒ Object
122
123
124
|
# File 'lib/satorix/CI/deploy/flynn.rb', line 122
def tls_pin
ENV["FLYNN_#{ current_branch }_TLSPIN"]
end
|