@@ -28,7 +28,7 @@ public function configure(string $lang, array $args): int
2828 return 1 ;
2929 }
3030
31- return $ this ->dockerRun ($ lang , array_merge (['php ' , 'doc-base/configure.php ' ], $ args ));
31+ return $ this ->dockerRun ($ this -> mounts ( $ lang) , array_merge (['php ' , 'doc-base/configure.php ' ], $ args ));
3232 }
3333
3434 public function render (string $ lang , string $ docbook , string $ format ): int
@@ -37,7 +37,7 @@ public function render(string $lang, string $docbook, string $format): int
3737 return 1 ;
3838 }
3939
40- return $ this ->dockerRun ($ lang , [
40+ return $ this ->dockerRun ($ this -> mounts ( $ lang) , [
4141 'php ' ,
4242 'phd/render.php ' ,
4343 '--docbook ' ,
@@ -57,16 +57,9 @@ public function lint(string $lang, array $args): int
5757 }
5858
5959 return $ this ->dockerRun (
60- $ lang ,
60+ $ this -> mounts ( $ lang) ,
6161 array_merge (['php ' , '/var/www/docbook-cs/bin/docbook-cs ' ], $ args ),
62- [
63- '-e ' ,
64- 'GIT_CONFIG_COUNT=1 ' ,
65- '-e ' ,
66- 'GIT_CONFIG_KEY_0=safe.directory ' ,
67- '-e ' ,
68- 'GIT_CONFIG_VALUE_0=* ' ,
69- ],
62+ $ this ->gitSafeDirectoryEnv (),
7063 "/var/www/ $ lang "
7164 );
7265 }
@@ -80,19 +73,63 @@ public function serve(string $lang, int $port, string $subdir): int
8073 // Inside the container the server must bind 0.0.0.0 to be reachable
8174 // through the published port; the host side stays localhost-only.
8275 return $ this ->dockerRun (
83- $ lang ,
76+ $ this -> mounts ( $ lang) ,
8477 ['php ' , '-S ' , "0.0.0.0: $ port " , '-t ' , "/var/www/ $ lang/output $ subdir " ],
8578 ['-p ' , "127.0.0.1: $ port: $ port " ]
8679 );
8780 }
8881
82+ public function serveWebDoc (int $ port ): int
83+ {
84+ if (!$ this ->ensureImage ()) {
85+ return 1 ;
86+ }
87+
88+ // The site shells out to git inside the mounted checkouts at
89+ // request time, hence the safe.directory override while serving.
90+ return $ this ->dockerRun (
91+ $ this ->webDocMounts (),
92+ ['php ' , '-S ' , "0.0.0.0: $ port " , 'router.php ' ],
93+ array_merge (
94+ [
95+ '-p ' ,
96+ "127.0.0.1: $ port: $ port " ,
97+ '-e ' ,
98+ 'PHPDOC_GIT_DIR=/var/www ' ,
99+ '-e ' ,
100+ 'SQLITE_DIR=/var/www/web-doc/sqlite ' ,
101+ '-e ' ,
102+ 'BASE_DOCS_PATH=/var/www/doc-base/docs ' ,
103+ ],
104+ $ this ->gitSafeDirectoryEnv ()
105+ ),
106+ '/var/www/web-doc '
107+ );
108+ }
109+
110+ public function generateRevisionDb (array $ langs ): int
111+ {
112+ if (!$ this ->ensureImage ()) {
113+ return 1 ;
114+ }
115+
116+ return $ this ->dockerRun (
117+ $ this ->webDocMounts (),
118+ array_merge (
119+ ['php ' , 'doc-base/scripts/translation/genrevdb.php ' , 'web-doc/sqlite/status.sqlite.new ' ],
120+ $ langs
121+ ),
122+ $ this ->gitSafeDirectoryEnv ()
123+ );
124+ }
125+
89126 public function shell (string $ lang ): int
90127 {
91128 if (!$ this ->ensureImage ()) {
92129 return 1 ;
93130 }
94131
95- return $ this ->dockerRun ($ lang , ['bash ' ], ['-it ' ]);
132+ return $ this ->dockerRun ($ this -> mounts ( $ lang) , ['bash ' ], ['-it ' ]);
96133 }
97134
98135 public function buildImage (): int
@@ -157,17 +194,48 @@ private function mounts(string $lang): array
157194 return $ mounts ;
158195 }
159196
197+ private function webDocMounts (): array
198+ {
199+ $ mounts = [
200+ realpath ($ this ->workspace ->basedir ()) => '/var/www/doc-base ' ,
201+ $ this ->workspace ->webDocDir () => '/var/www/web-doc ' ,
202+ $ this ->workspace ->langDir ('en ' ) => '/var/www/en ' ,
203+ ];
204+
205+ // Mount every translation checkout so PHPDOC_GIT_DIR=/var/www looks
206+ // like a full doc.php.net workspace to the site.
207+ foreach ($ this ->workspace ->translationCheckouts () as $ lang => $ dir ) {
208+ $ mounts [$ dir ] = "/var/www/ $ lang " ;
209+ }
210+
211+ return $ mounts ;
212+ }
213+
214+ /** @return list<string> */
215+ private function gitSafeDirectoryEnv (): array
216+ {
217+ return [
218+ '-e ' ,
219+ 'GIT_CONFIG_COUNT=1 ' ,
220+ '-e ' ,
221+ 'GIT_CONFIG_KEY_0=safe.directory ' ,
222+ '-e ' ,
223+ 'GIT_CONFIG_VALUE_0=* ' ,
224+ ];
225+ }
226+
160227 /**
228+ * @param array<string, string> $mounts Host path => container path.
161229 * @param list<string> $inner Command to run inside the container.
162230 * @param list<string> $extra Extra docker run arguments.
163231 */
164- private function dockerRun (string $ lang , array $ inner , array $ extra = [], string $ workdir = '/var/www ' ): int
232+ private function dockerRun (array $ mounts , array $ inner , array $ extra = [], string $ workdir = '/var/www ' ): int
165233 {
166234 // --init: without it the command runs as PID 1, which ignores
167235 // SIGINT, so Ctrl-C would leave the container running forever.
168236 $ cmd = ['docker ' , 'run ' , '--rm ' , '--init ' ];
169237
170- foreach ($ this -> mounts ( $ lang ) as $ host => $ container ) {
238+ foreach ($ mounts as $ host => $ container ) {
171239 array_push ($ cmd , '-v ' , "$ host: $ container " );
172240 }
173241
0 commit comments