Skip to content

Commit b9b9baf

Browse files
authored
Merge pull request #71 from IBM-Swift/remote-debugging
Remote debugging
2 parents be574e0 + 47f1fbf commit b9b9baf

File tree

8 files changed

+179
-4
lines changed

8 files changed

+179
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"public": true,
3-
"proxy_required": false,
3+
"proxy_required": true,
44
"background": false
55
}

app_management/initial_startup.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def start_runtime(app_dir)
4040
end
4141

4242
def start_proxy(app_dir)
43-
raise 'start_proxy is not implemented yet!'
44-
#exec('.app-management/bin/proxyAgent', chdir: app_dir)
43+
Utils::SimpleLogger.info("Starting proxy agent")
44+
exec('.app-management/bin/proxyAgent', chdir: app_dir)
4545
end
4646

4747
def run(app_dir, handlers, background)
3.02 MB
Binary file not shown.

bin/compile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ PACKAGES_DIR="Packages"
3636
# If leveraging CACHE_DIR for tar files, then we'd need CACHED_ITEMS
3737
#CACHED_ITEMS=()
3838

39+
# Apply Bluemix-specific environment configuration profile
40+
$BP_DIR/lib/apply_env_profile.rb $BUILD_DIR
41+
3942
source $BP_DIR/compile-extensions/lib/common
4043
# Check environment support
4144
$BP_DIR/compile-extensions/bin/check_stack_support

config/env.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
"ibm:yf:us-south":
3+
MANAGEMENT_SERVER_URL: https://rtmgmt.fabric.ng.bluemix.net
4+
cloud_controller_url: https://api.fabric.ng.bluemix.net
5+
authorization_endpoint: https://login.fabric.ng.bluemix.net/UAALoginServerWAR
6+
7+
"ibm:ys0:us-south":
8+
MANAGEMENT_SERVER_URL: https://rtmgmt.stage0.ng.bluemix.net
9+
cloud_controller_url: https://api.stage0.ng.bluemix.net
10+
authorization_endpoint: https://login.stage0.ng.bluemix.net/UAALoginServerWAR
11+
12+
"ibm:ys1:us-south":
13+
MANAGEMENT_SERVER_URL: https://rtmgmt.stage1.ng.bluemix.net
14+
cloud_controller_url: https://api.stage1.ng.bluemix.net
15+
authorization_endpoint: https://login.stage1.ng.bluemix.net/UAALoginServerWAR
16+
17+
"ibm:yp:us-south":
18+
MANAGEMENT_SERVER_URL: https://rtmgmt.ng.bluemix.net
19+
cloud_controller_url: https://api.ng.bluemix.net
20+
authorization_endpoint: https://login.ng.bluemix.net/UAALoginServerWAR
21+
22+
"ibm:ys1:eu-gb":
23+
MANAGEMENT_SERVER_URL: https://rtmgmt.stage1.eu-gb.bluemix.net
24+
cloud_controller_url: https://api.stage1.eu-gb.bluemix.net
25+
authorization_endpoint: https://login.stage1.eu-gb.bluemix.net/UAALoginServerWAR
26+
27+
"ibm:yp:eu-gb":
28+
MANAGEMENT_SERVER_URL: https://rtmgmt.eu-gb.bluemix.net
29+
cloud_controller_url: https://api.eu-gb.bluemix.net
30+
authorization_endpoint: https://login.eu-gb.bluemix.net/UAALoginServerWAR
31+
32+
"ibm:yp:au-syd":
33+
MANAGEMENT_SERVER_URL: https://rtmgmt.au-syd.bluemix.net
34+
cloud_controller_url: https://api.au-syd.bluemix.net
35+
authorization_endpoint: https://login.au-syd.bluemix.net/UAALoginServerWAR

lib/app_management.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function installAgent() {
2828
cp $BP_DIR/app_management/initial_startup.rb $BUILD_DIR/.app-management
2929
cp $BP_DIR/app_management/env.json $BUILD_DIR/.app-management
3030

31+
unzip $BP_DIR/app_management/proxy-agent/proxy-agent -d $BUILD_DIR/.app-management/bin > /dev/null
32+
3133
chmod +x $BUILD_DIR/.app-management/utils/*
3234
chmod +x $BUILD_DIR/.app-management/scripts/*
3335
chmod -R +x $BUILD_DIR/.app-management/handlers/
@@ -72,6 +74,23 @@ function removeDebugDEBs() {
7274
done
7375
}
7476

77+
function generateAppMgmtInfo() {
78+
local CONTAINER="garden"
79+
local SSH_ENABLED="false"
80+
local PROXY_SUPPORTED='["v1", "v2"]'
81+
82+
# Generate app management info file. proxy_enabled is set during startup.
83+
cat > $BUILD_DIR/.app-management/app_mgmt_info.json << EOL
84+
{
85+
"container": "$CONTAINER",
86+
"ssh_enabled": $SSH_ENABLED,
87+
"proxy_enabled": false,
88+
"proxy_supported_version": $PROXY_SUPPORTED
89+
}
90+
EOL
91+
92+
}
93+
7594
function installAppManagement() {
7695
# Find boot script file
7796
start_cmd=$($BP_DIR/lib/find_start_cmd.rb $BUILD_DIR)
@@ -83,7 +102,7 @@ function installAppManagement() {
83102
status "WARNING: To install App Management utilities, specify a start command for your Swift application in a 'Procfile'."
84103
else
85104
# Install development mode utilities
86-
installAgent && updateStartCommands && copyLLDBServer && copyDebugDEBs
105+
installAgent && updateStartCommands && copyLLDBServer && copyDebugDEBs && generateAppMgmtInfo
87106
fi
88107
}
89108

lib/apply_env_profile.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env ruby
2+
# Copyright IBM Corporation 2017
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
##
16+
17+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
18+
19+
require 'env_profile_applier'
20+
21+
begin
22+
build_dir = ARGV[0]
23+
build_dir += '/' if build_dir[-1] != '/'
24+
if !ENV['BP_LOG'].nil? && 'true'.casecmp(ENV['BP_LOG']) == 0
25+
log_env = true
26+
else
27+
log_env = false
28+
end
29+
EnvProfileApplier.new(build_dir, log_env).apply_env_profile
30+
rescue => e
31+
puts "-----> WARN: Failed to apply Bluemix environment profiles"
32+
end

lib/env_profile_applier.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env ruby
2+
# Copyright IBM Corporation 2017
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
##
16+
17+
require 'yaml'
18+
require 'fileutils'
19+
20+
class EnvProfileApplier
21+
def initialize(app_dir, log_env = false)
22+
@app_dir = app_dir
23+
@log_env = log_env
24+
@bp_dir = File.expand_path(File.join('..','..'), __FILE__)
25+
end
26+
27+
def apply_env_profile
28+
profiled_dir = File.join(@app_dir, '.profile.d')
29+
30+
# load config file
31+
config = YAML.load_file(File.join(@bp_dir, "config", "env.yml"))
32+
variables = {}
33+
# apply default variables
34+
copy_variables(variables, config)
35+
36+
# apply profiles
37+
profiles.each do | profile |
38+
profile = profile.strip
39+
profile_variables = config[profile]
40+
copy_variables(variables, profile_variables) unless profile_variables.nil?
41+
end
42+
43+
# create bluemix_env.sh file in app's '.profile.d' folder
44+
FileUtils.mkdir_p(profiled_dir)
45+
env_file_name = File.join(profiled_dir, 'bluemix_env.sh')
46+
env_file = File.new(env_file_name, 'w')
47+
variables.each do | key, value |
48+
env_file.puts("export #{key}=\"#{value}\"")
49+
end
50+
env_file.close
51+
52+
log_env(env_file_name) if @log_env
53+
end
54+
55+
private
56+
57+
def log_env(env_file_name)
58+
if profiles.empty?
59+
puts "-----> No configuration profiles applied"
60+
else
61+
puts "-----> Applied configuration profiles: #{profiles}"
62+
if File.exist?(env_file_name)
63+
env_contents = File.open(env_file_name) { |file| file.read }
64+
puts "-----> Generated 'bluemix_env.sh' in application's '.profile.d' folder"
65+
puts "'bluemix_env.sh' contents:\n#{env_contents}"
66+
end
67+
end
68+
end
69+
70+
def copy_variables(variables, configuration)
71+
configuration.each do | key, value |
72+
key = key.strip
73+
variables[key] = value unless value.is_a?(Hash) || value.is_a?(Array) || key.empty?
74+
end
75+
end
76+
77+
def profiles
78+
profiles_var = ENV['IBM_ENV_PROFILE']
79+
if profiles_var.nil?
80+
region = ENV['BLUEMIX_REGION']
81+
region.nil? ? [] : [region]
82+
else
83+
profiles_var.split(',')
84+
end
85+
end
86+
end

0 commit comments

Comments
 (0)