@@ -24,6 +24,8 @@ type LsOpts struct {
24
24
HotReloadingPaths []string
25
25
EnableDnsServer string
26
26
LocalstackIP string
27
+ InitLogLevel string
28
+ EdgePort string
27
29
}
28
30
29
31
func GetEnvOrDie (env string ) string {
@@ -36,12 +38,15 @@ func GetEnvOrDie(env string) string {
36
38
37
39
func InitLsOpts () * LsOpts {
38
40
return & LsOpts {
41
+ // required
39
42
RuntimeEndpoint : GetEnvOrDie ("LOCALSTACK_RUNTIME_ENDPOINT" ),
40
43
RuntimeId : GetEnvOrDie ("LOCALSTACK_RUNTIME_ID" ),
41
44
// optional with default
42
45
InteropPort : GetenvWithDefault ("LOCALSTACK_INTEROP_PORT" , "9563" ),
43
46
InitTracingPort : GetenvWithDefault ("LOCALSTACK_RUNTIME_TRACING_PORT" , "9564" ),
44
47
User : GetenvWithDefault ("LOCALSTACK_USER" , "sbx_user1051" ),
48
+ InitLogLevel : GetenvWithDefault ("LOCALSTACK_INIT_LOG_LEVEL" , "debug" ),
49
+ EdgePort : GetenvWithDefault ("EDGE_PORT" , "4566" ),
45
50
// optional or empty
46
51
CodeArchives : os .Getenv ("LOCALSTACK_CODE_ARCHIVES" ),
47
52
HotReloadingPaths : strings .Split (GetenvWithDefault ("LOCALSTACK_HOT_RELOADING_PATHS" , "" ), "," ),
@@ -62,6 +67,7 @@ func UnsetLsEnvs() {
62
67
"LOCALSTACK_CODE_ARCHIVES" ,
63
68
"LOCALSTACK_HOT_RELOADING_PATHS" ,
64
69
"LOCALSTACK_ENABLE_DNS_SERVER" ,
70
+ "LOCALSTACK_INIT_LOG_LEVEL" ,
65
71
// Docker container ID
66
72
"HOSTNAME" ,
67
73
// User
@@ -78,22 +84,33 @@ func main() {
78
84
// we're setting this to the same value as in the official RIE
79
85
debug .SetGCPercent (33 )
80
86
87
+ // configuration parsing
81
88
lsOpts := InitLsOpts ()
82
89
UnsetLsEnvs ()
83
90
84
- // set up logging (logrus)
85
- //log.SetFormatter(&log.JSONFormatter{})
86
- //log.SetLevel(log.TraceLevel)
87
- log .SetLevel (log .DebugLevel )
91
+ // set up logging
88
92
log .SetReportCaller (true )
93
+ switch lsOpts .InitLogLevel {
94
+ case "debug" :
95
+ log .SetLevel (log .DebugLevel )
96
+ case "trace" :
97
+ log .SetFormatter (& log.JSONFormatter {})
98
+ log .SetLevel (log .TraceLevel )
99
+ default :
100
+ log .Fatal ("Invalid value for LOCALSTACK_INIT_LOG_LEVEL" )
101
+ }
102
+
103
+ // enable dns server
104
+ dnsServerContext , stopDnsServer := context .WithCancel (context .Background ())
105
+ go RunDNSRewriter (lsOpts , dnsServerContext )
89
106
90
107
// download code archive if env variable is set
91
108
if err := DownloadCodeArchives (lsOpts .CodeArchives ); err != nil {
92
109
log .Fatal ("Failed to download code archives" )
93
110
}
94
- // enable dns server
95
- dnsServerContext , stopDnsServer := context . WithCancel ( context . Background ())
96
- go RunDNSRewriter ( lsOpts , dnsServerContext )
111
+
112
+ // parse CLI args
113
+ bootstrap , handler := getBootstrap ( os . Args )
97
114
98
115
// Switch to non-root user and drop root privileges
99
116
if IsRootUser () && lsOpts .User != "" {
@@ -108,23 +125,36 @@ func main() {
108
125
UserLogger ().Debugln ("Process running as non-root user." )
109
126
}
110
127
111
- // parse CLI args
112
- opts , args := getCLIArgs ()
113
- bootstrap , handler := getBootstrap (args , opts )
114
128
logCollector := NewLogCollector ()
129
+
130
+ // file watcher for hot-reloading
115
131
fileWatcherContext , cancelFileWatcher := context .WithCancel (context .Background ())
132
+
133
+ // build sandbox
116
134
sandbox := rapidcore .
117
135
NewSandboxBuilder (bootstrap ).
136
+ //SetTracer(tracer).
118
137
AddShutdownFunc (func () {
119
- log .Debugln ("Closing contexts " )
138
+ log .Debugln ("Stopping file watcher " )
120
139
cancelFileWatcher ()
140
+ log .Debugln ("Stopping DNS server" )
121
141
stopDnsServer ()
122
142
}).
123
- AddShutdownFunc (func () { os .Exit (0 ) }).
124
143
SetExtensionsFlag (true ).
125
144
SetInitCachingFlag (true ).
126
145
SetTailLogOutput (logCollector )
127
146
147
+ // xray daemon
148
+ xrayConfig := initConfig ("http://" + lsOpts .LocalstackIP + ":" + lsOpts .EdgePort )
149
+ d := initDaemon (xrayConfig )
150
+ sandbox .AddShutdownFunc (func () {
151
+ log .Debugln ("Shutting down xray daemon" )
152
+ d .stop ()
153
+ log .Debugln ("Flushing segments in xray daemon" )
154
+ d .close ()
155
+ })
156
+ runDaemon (d ) // async
157
+
128
158
defaultInterop := sandbox .InteropServer ()
129
159
interopServer := NewCustomInteropServer (lsOpts , defaultInterop , logCollector )
130
160
sandbox .SetInteropServer (interopServer )
@@ -136,7 +166,7 @@ func main() {
136
166
go sandbox .Create ()
137
167
138
168
// get timeout
139
- invokeTimeoutEnv := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_TIMEOUT" )
169
+ invokeTimeoutEnv := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_TIMEOUT" ) // TODO: collect all AWS_* env parsing
140
170
invokeTimeoutSeconds , err := strconv .Atoi (invokeTimeoutEnv )
141
171
if err != nil {
142
172
log .Fatalln (err )
0 commit comments