Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
text-generation-inference
Commits
b66b1904
Unverified
Commit
b66b1904
authored
Jul 19, 2023
by
OlivierDehaene
Committed by
GitHub
Jul 19, 2023
Browse files
feat(router): ngrok edge (#642)
parent
fe80f536
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
55 deletions
+29
-55
launcher/src/main.rs
launcher/src/main.rs
+20
-29
router/src/main.rs
router/src/main.rs
+3
-11
router/src/server.rs
router/src/server.rs
+6
-15
No files found.
launcher/src/main.rs
View file @
b66b1904
...
...
@@ -267,17 +267,9 @@ struct Args {
#[clap(long,
env)]
ngrok_authtoken
:
Option
<
String
>
,
/// ngrok
domain name where the axum webserver will be available at
/// ngrok
edge
#[clap(long,
env)]
ngrok_domain
:
Option
<
String
>
,
/// ngrok basic auth username
#[clap(long,
env)]
ngrok_username
:
Option
<
String
>
,
/// ngrok basic auth password
#[clap(long,
env)]
ngrok_password
:
Option
<
String
>
,
ngrok_edge
:
Option
<
String
>
,
/// Display a lot of information about your runtime environment
#[clap(long,
short,
action)]
...
...
@@ -900,26 +892,11 @@ fn spawn_webserver(
// Ngrok
if
args
.ngrok
{
let
authtoken
=
args
.ngrok_authtoken
.ok_or_else
(||
{
tracing
::
error!
(
"`ngrok-authtoken` must be set when using ngrok tunneling"
);
LauncherError
::
WebserverCannotStart
})
?
;
router_args
.push
(
"--ngrok"
.to_string
());
router_args
.push
(
"--ngrok-authtoken"
.to_string
());
router_args
.push
(
authtoken
);
if
let
Some
(
domain
)
=
args
.ngrok_domain
{
router_args
.push
(
"--ngrok-domain"
.to_string
());
router_args
.push
(
domain
);
}
if
let
(
Some
(
username
),
Some
(
password
))
=
(
args
.ngrok_username
,
args
.ngrok_password
)
{
router_args
.push
(
"--ngrok-username"
.to_string
());
router_args
.push
(
username
);
router_args
.push
(
"--ngrok-password"
.to_string
());
router_args
.push
(
password
);
}
router_args
.push
(
args
.ngrok_authtoken
.unwrap
());
router_args
.push
(
"--ngrok-edge"
.to_string
());
router_args
.push
(
args
.ngrok_edge
.unwrap
());
}
// Copy current process env
...
...
@@ -997,7 +974,7 @@ fn terminate(process_name: &str, mut process: Child, timeout: Duration) -> io::R
fn
main
()
->
Result
<
(),
LauncherError
>
{
// Pattern match configuration
let
args
=
Args
::
parse
();
let
args
:
Args
=
Args
::
parse
();
// Filter events with LOG_LEVEL
let
env_filter
=
...
...
@@ -1067,6 +1044,20 @@ fn main() -> Result<(), LauncherError> {
}
}
if
args
.ngrok
{
if
args
.ngrok_authtoken
.is_none
()
{
return
Err
(
LauncherError
::
ArgumentValidation
(
"`ngrok-authtoken` must be set when using ngrok tunneling"
.to_string
(),
));
}
if
args
.ngrok_edge
.is_none
()
{
return
Err
(
LauncherError
::
ArgumentValidation
(
"`ngrok-edge` must be set when using ngrok tunneling"
.to_string
(),
));
}
}
// Signal handler
let
running
=
Arc
::
new
(
AtomicBool
::
new
(
true
));
let
r
=
running
.clone
();
...
...
router/src/main.rs
View file @
b66b1904
...
...
@@ -64,11 +64,7 @@ struct Args {
#[clap(long,
env)]
ngrok_authtoken
:
Option
<
String
>
,
#[clap(long,
env)]
ngrok_domain
:
Option
<
String
>
,
#[clap(long,
env)]
ngrok_username
:
Option
<
String
>
,
#[clap(long,
env)]
ngrok_password
:
Option
<
String
>
,
ngrok_edge
:
Option
<
String
>
,
}
fn
main
()
->
Result
<
(),
RouterError
>
{
...
...
@@ -96,9 +92,7 @@ fn main() -> Result<(), RouterError> {
cors_allow_origin
,
ngrok
,
ngrok_authtoken
,
ngrok_domain
,
ngrok_username
,
ngrok_password
,
ngrok_edge
,
}
=
args
;
// Validate args
...
...
@@ -274,9 +268,7 @@ fn main() -> Result<(), RouterError> {
cors_allow_origin
,
ngrok
,
ngrok_authtoken
,
ngrok_domain
,
ngrok_username
,
ngrok_password
,
ngrok_edge
,
)
.await
?
;
Ok
(())
...
...
router/src/server.rs
View file @
b66b1904
...
...
@@ -524,9 +524,7 @@ pub async fn run(
allow_origin
:
Option
<
AllowOrigin
>
,
ngrok
:
bool
,
ngrok_authtoken
:
Option
<
String
>
,
ngrok_domain
:
Option
<
String
>
,
ngrok_username
:
Option
<
String
>
,
ngrok_password
:
Option
<
String
>
,
ngrok_edge
:
Option
<
String
>
,
)
->
Result
<
(),
axum
::
BoxError
>
{
// OpenAPI documentation
#[derive(OpenApi)]
...
...
@@ -696,32 +694,25 @@ pub async fn run(
#[cfg(feature
=
"ngrok"
)]
{
use
ngrok
::
config
::
TunnelBuilder
;
use
ngrok
::
tunnel
::
UrlTunnel
;
let
_
=
addr
;
let
authtoken
=
ngrok_authtoken
.expect
(
"`ngrok-authtoken` must be set when using ngrok tunneling"
);
let
mut
tunnel
=
ngrok
::
Session
::
builder
()
let
edge
=
ngrok_edge
.expect
(
"`ngrok-edge` must be set when using ngrok tunneling"
);
let
tunnel
=
ngrok
::
Session
::
builder
()
.authtoken
(
authtoken
)
.connect
()
.await
.unwrap
()
.http_endpoint
();
if
let
Some
(
domain
)
=
ngrok_domain
{
tunnel
=
tunnel
.domain
(
domain
);
}
if
let
(
Some
(
username
),
Some
(
password
))
=
(
ngrok_username
,
ngrok_password
)
{
tunnel
=
tunnel
.basic_auth
(
username
,
password
);
}
.labeled_tunnel
()
.label
(
"edge"
,
edge
);
let
listener
=
tunnel
.listen
()
.await
.unwrap
();
// Run server
tracing
::
info!
(
"Ingress URL: {:?}"
,
listener
.url
());
axum
::
Server
::
builder
(
listener
)
.serve
(
app
.into_make_service
())
//Wait until all requests are finished to shut down
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment