80
80
%$template_urls ,
81
81
lenient => $Opts -> {lenient },
82
82
force => $Opts -> {reload_template },
83
- abs_urls => $ Opts-> {doc }
83
+ abs_urls => ! $running_in_standard_docker && $ Opts-> {doc },
84
84
);
85
85
86
86
$Opts -> {doc } ? build_local( $Opts -> {doc } )
@@ -124,72 +124,8 @@ sub build_local {
124
124
my $html = $dir -> file(' index.html' );
125
125
126
126
if ( $Opts -> {open } ) {
127
- if ( my $pid = fork ) {
128
- # parent
129
- $SIG {INT } = sub {
130
- kill -9, $pid ;
131
- };
132
- if ( $Opts -> {open } && not $running_in_standard_docker ) {
133
- sleep 1;
134
- say " Opening: " . $html ;
135
- say " Press Ctrl-C to exit the web server" ;
136
- open_browser(' http://localhost:8000/index.html' );
137
- }
138
-
139
- wait ;
140
- say " \n Exiting" ;
141
- exit ;
142
- }
143
- else {
144
- if ( $running_in_standard_docker ) {
145
- # We use nginx to serve files instead of the python built in web server
146
- # when we're running inside docker because the python web server performs
147
- # badly there. nginx is fine.
148
- open (my $nginx_conf , ' >' , ' /tmp/docs.conf' ) or dir(" Couldn't write nginx conf to /tmp/docs/.conf" );
149
- print $nginx_conf <<"CONF" ;
150
- daemon off;
151
- error_log /dev/stdout info;
152
- pid /run/nginx/nginx.pid;
153
-
154
- events {
155
- worker_connections 64;
156
- }
157
-
158
- http {
159
- error_log /dev/stdout crit;
160
- log_format short '[\$ time_local] "\$ request" \$ status';
161
- access_log /dev/stdout short;
162
- server {
163
- listen 8000;
164
- location / {
165
- root $dir ;
166
- add_header 'Access-Control-Allow-Origin' '*';
167
- if (\$ request_method = 'OPTIONS') {
168
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
169
- add_header 'Access-Control-Allow-Headers' 'kbn-xsrf-token';
170
- }
171
- }
172
- types {
173
- text/html html;
174
- application/javascript js;
175
- text/css css;
176
- }
177
- }
178
- }
179
- CONF
180
- close $nginx_conf ;
181
- close STDIN ;
182
- open ( STDIN , " </dev/null" );
183
- chdir $dir ;
184
- exec ( ' nginx' , ' -c' , ' /tmp/docs.conf' );
185
- } else {
186
- my $http = dir( ' resources' , ' http.py' )-> absolute;
187
- close STDIN ;
188
- open ( STDIN , " </dev/null" );
189
- chdir $dir ;
190
- exec ( $http ' 8000' );
191
- }
192
- }
127
+ say " Opening: " . $html ;
128
+ serve_and_open_browser( $dir , ' index.html' );
193
129
}
194
130
else {
195
131
say " See: $html " ;
@@ -282,6 +218,7 @@ sub build_all {
282
218
check_links($build_dir );
283
219
}
284
220
push_changes($build_dir , $target_repo , $target_repo_checkout ) if $Opts -> {push };
221
+ serve_and_open_browser( $build_dir , ' /' ) if $Opts -> {open };
285
222
286
223
$temp_dir -> rmtree;
287
224
}
@@ -733,6 +670,82 @@ sub pick_conf {
733
670
die $Opts -> {conf } . " doesn't exist" ;
734
671
}
735
672
673
+ # ===================================
674
+ sub serve_and_open_browser {
675
+ # ===================================
676
+ my ( $dir , $open_path ) = @_ ;
677
+
678
+ if ( my $pid = fork ) {
679
+ # parent
680
+ $SIG {INT } = sub {
681
+ kill -9, $pid ;
682
+ };
683
+ if ( not $running_in_standard_docker ) {
684
+ sleep 1;
685
+ say " Press Ctrl-C to exit the web server" ;
686
+ open_browser(" http://localhost:8000/$open_path " );
687
+ }
688
+
689
+ wait ;
690
+ say " \n Exiting" ;
691
+ exit ;
692
+ }
693
+ else {
694
+ if ( $running_in_standard_docker ) {
695
+ # We use nginx to serve files instead of the python built in web server
696
+ # when we're running inside docker because the python web server performs
697
+ # badly there. nginx is fine.
698
+ open (my $nginx_conf , ' >' , ' /tmp/docs.conf' ) or dir(" Couldn't write nginx conf to /tmp/docs/.conf" );
699
+ print $nginx_conf <<"CONF" ;
700
+ daemon off;
701
+ error_log /dev/stdout info;
702
+ pid /run/nginx/nginx.pid;
703
+
704
+ events {
705
+ worker_connections 64;
706
+ }
707
+
708
+ http {
709
+ error_log /dev/stdout crit;
710
+ log_format short '[\$ time_local] "\$ request" \$ status';
711
+ access_log /dev/stdout short;
712
+ server {
713
+ listen 8000;
714
+ location / {
715
+ root $dir ;
716
+ add_header 'Access-Control-Allow-Origin' '*';
717
+ if (\$ request_method = 'OPTIONS') {
718
+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
719
+ add_header 'Access-Control-Allow-Headers' 'kbn-xsrf-token';
720
+ }
721
+ }
722
+ types {
723
+ text/html html;
724
+ application/javascript js;
725
+ text/css css;
726
+ }
727
+ rewrite ^/android-chrome-(.+)\$ https://www.elastic.co/android-chrome-\$ 1 permanent;
728
+ rewrite ^/assets/(.+)\$ https://www.elastic.co/assets/\$ 1 permanent;
729
+ rewrite ^/favicon(.+)\$ https://www.elastic.co/favicon\$ 1 permanent;
730
+ rewrite ^/gdpr-data\$ https://www.elastic.co/gdpr-data permanent;
731
+ rewrite ^/static/(.+)\$ https://www.elastic.co/static/\$ 1 permanent;
732
+ }
733
+ }
734
+ CONF
735
+ close $nginx_conf ;
736
+ close STDIN ;
737
+ open ( STDIN , " </dev/null" );
738
+ exec ( ' nginx' , ' -c' , ' /tmp/docs.conf' );
739
+ } else {
740
+ my $http = dir( ' resources' , ' http.py' )-> absolute;
741
+ close STDIN ;
742
+ open ( STDIN , " </dev/null" );
743
+ chdir $dir ;
744
+ exec ( $http ' 8000' );
745
+ }
746
+ }
747
+ }
748
+
736
749
# ===================================
737
750
sub usage {
738
751
# ===================================
@@ -750,7 +763,6 @@ sub usage {
750
763
--toc Include a TOC at the beginning of the page.
751
764
--out dest/dir/ Defaults to ./html_docs.
752
765
--chunk 1 Also chunk sections into separate files
753
- --open Open the docs in a browser once built.
754
766
--lenient Ignore linking errors
755
767
--lang Defaults to 'en'
756
768
--resource Path to image dir - may be repeated
@@ -780,6 +792,7 @@ sub usage {
780
792
--in_standard_docker
781
793
Specified by build_docs when running in its container
782
794
--conf <ymlfile> Use your own configuration file, defaults to the bundled conf.yaml
795
+ --open Open the docs in a browser once built.
783
796
784
797
USAGE
785
798
if ( $Opts -> {in_standard_docker } ) {
0 commit comments