Created
April 14, 2015 22:28
-
-
Save onyxrev/3120db44566d302c3cb6 to your computer and use it in GitHub Desktop.
Crazy SSH forwarding for Centurion through gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
SERVERS_CONFIG = YAML::load( File.open( './config/servers.yml' ) ) | |
CREDENTIALS_CONFIG = YAML::load( File.open( './config/credentials.yml') ) | |
module DittachDeployDsl | |
def build_status_endpoints(servers, path) | |
servers.reduce({}) do |memo, server| | |
memo.merge Hash[ | |
"localhost:#{server["docker_redirect_port"]}", "http://localhost:#{server['status_redirect_port']}#{path}" | |
] | |
end | |
end | |
def set_environment_for_service(environment, service) | |
set_current_environment(environment) | |
env_vars NODE_ENV: environment.to_s | |
servers = SERVERS_CONFIG[environment.to_s][service.to_s] | |
set_servers(servers) | |
return [ | |
servers, | |
credentials_for_environment(environment.to_s) | |
] | |
end | |
def set_servers(servers) | |
servers.each do |server| | |
host "localhost:#{server["docker_redirect_port"]}" | |
end | |
end | |
def credentials_for_environment(environment) | |
CREDENTIALS_CONFIG["staging"] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './lib/dittach_deploy_dsl' | |
namespace :environment do | |
include DittachDeployDsl | |
task :common do | |
set :tls, false | |
set :image, 'dittach/rest_api' | |
host_port 3000, container_port: 3000 | |
end | |
desc 'Staging environment' | |
task :staging => :common do | |
servers, credentials = set_environment_for_service(:staging, :external_api) | |
set :status_endpoints, build_status_endpoints(servers, "/status") | |
set_environment_variables(credentials) | |
end | |
desc 'Production environment' | |
task :production => :common do | |
servers, credentials = set_environment_for_service(:production, :external_api) | |
set :status_endpoints, build_status_endpoints(servers, "/status") | |
set_environment_variables(credentials) | |
end | |
def set_environment_variables(credentials) | |
env_vars DITTACH_API_HOST: '0.0.0.0' | |
env_vars DITTACH_GOOGLE_CLIENT_ID: credentials['dittach_google_client_id'] | |
env_vars DITTACH_GOOGLE_CLIENT_SECRET: credentials['dittach_google_client_secret'] | |
env_vars DITTACH_AMQP_PASSWORD: credentials['dittach_amqp_password'] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
task :deploy do | |
servers_config = YAML::load( File.open( './config/servers.yml' ) ) | |
task :staging do | |
servers = servers_config["staging"].values.flatten | |
# forward the docker port for each server to localhost | |
port_forwards = [] | |
servers.each do |server| | |
port_forwards << "-L #{server['docker_redirect_port']}:#{server['host']}:2375" | |
unless server["status_redirect_port"].nil? | |
port_forwards << "-L #{server['status_redirect_port']}:#{server['host']}:#{server['status_remote_port']}" | |
end | |
end | |
ssh_command = "ssh #{port_forwards.join(" ")} [email protected]" | |
puts ssh_command | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
staging: | |
amqp: | |
- host: amqp.local.staging.dittach.com | |
docker_redirect_port: 11222 | |
status_redirect_port: 21222 | |
status_remote_port: 15672 | |
riak: | |
- host: riak1.local.staging.dittach.com | |
docker_redirect_port: 11223 | |
status_redirect_port: 21223 | |
status_remote_port: 8098 | |
mongodb: | |
- host: mongodb1.local.staging.dittach.com | |
docker_redirect_port: 11224 | |
external_api: | |
- host: api1.local.staging.dittach.com | |
docker_redirect_port: 11225 | |
status_redirect_port: 21225 | |
status_remote_port: 3000 | |
realtime_api: | |
- host: api1.local.staging.dittach.com | |
docker_redirect_port: 11226 | |
status_redirect_port: 21226 | |
status_remote_port: 3002 | |
preview_api: | |
- host: api1.local.staging.dittach.com | |
docker_redirect_port: 11227 | |
status_redirect_port: 21227 | |
status_remote_port: 3003 | |
dashboard: | |
- host: api1.local.staging.dittach.com | |
docker_redirect_port: 11228 | |
status_redirect_port: 21228 | |
status_remote_port: 3004 | |
mailservice: | |
- host: mailservice1.local.staging.dittach.com | |
docker_redirect_port: 11229 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment