@@ -36,9 +36,11 @@ function about(): void
3636 io ()->section ('Available URLs for this project: ' );
3737 $ urls = [variable ('root_domain ' ), ...variable ('extra_domains ' )];
3838
39+ $ adminPort = get_worktree_ports (variable ('worktree_name ' ))['admin ' ];
40+
3941 try {
4042 $ routers = http_client ()
41- ->request ('GET ' , \sprintf ('http://%s:8080 /api/http/routers ' , variable ('root_domain ' )))
43+ ->request ('GET ' , \sprintf ('http://%s:%d /api/http/routers ' , variable ('root_domain ' ), $ adminPort ))
4244 ->toArray ()
4345 ;
4446 $ projectName = variable ('project_name ' );
@@ -58,7 +60,13 @@ function about(): void
5860 } catch (HttpExceptionInterface ) {
5961 }
6062
61- io ()->listing (array_map (static fn ($ url ) => "https:// {$ url }" , array_unique ($ urls )));
63+ $ worktreeName = get_worktree_name ();
64+ $ httpsPort = null !== $ worktreeName ? get_worktree_ports ($ worktreeName )['https ' ] : null ;
65+ $ formatUrl = static function (string $ host ) use ($ httpsPort ): string {
66+ return null !== $ httpsPort ? "https:// {$ host }: {$ httpsPort }" : "https:// {$ host }" ;
67+ };
68+
69+ io ()->listing (array_map ($ formatUrl , array_unique ($ urls )));
6270}
6371
6472#[AsTask(description: 'Opens the project in your browser ' , namespace: '' , aliases: ['open ' ])]
@@ -379,6 +387,15 @@ function docker_compose(array $subCommand, ?Context $c = null, array $profiles =
379387 'REGISTRY ' => $ c ['registry ' ] ?? '' ,
380388 ]);
381389
390+ if ($ c ['worktree_name ' ]) {
391+ $ ports = get_worktree_ports ($ c ['worktree_name ' ]);
392+ $ portsEnv = [];
393+ foreach (get_port_specs () as $ key => $ spec ) {
394+ $ portsEnv [$ spec ['env ' ]] = (string ) $ ports [$ key ];
395+ }
396+ $ c = $ c ->withEnvironment ($ portsEnv );
397+ }
398+
382399 if ($ c ['APP_ENV ' ] ?? false ) {
383400 $ c = $ c ->withEnvironment ([
384401 'APP_ENV ' => $ c ['APP_ENV ' ] ?? '' ,
@@ -608,3 +625,26 @@ function get_service_names(?string $profile = null): array
608625{
609626 return array_keys (get_services ($ profile ));
610627}
628+
629+ #[AsTask(description: 'Displays the ports allocated for the current project ' , namespace: 'docker ' )]
630+ function ports (): void
631+ {
632+ $ project = variable ('project_name ' );
633+ $ domain = variable ('root_domain ' );
634+ $ name = get_worktree_name ();
635+ $ ports = get_worktree_ports ($ name );
636+
637+ io ()->title ('Ports ' );
638+ $ list = [['Project ' => $ project ]];
639+ foreach (get_port_specs () as $ key => $ spec ) {
640+ $ scheme = 'admin ' === $ key ? 'http ' : $ key ;
641+ $ host = 'admin ' === $ key ? 'localhost ' : $ domain ;
642+ $ list [] = [$ spec ['label ' ] => "{$ scheme }:// {$ host }: {$ ports [$ key ]}" ];
643+ }
644+
645+ if ($ name ) {
646+ array_unshift ($ list , ['Worktree ' => $ name ]);
647+ }
648+
649+ io ()->definitionList (...$ list );
650+ }
0 commit comments