File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323 - run : npm ci
2424 - run : npm run check
2525 - run : npm run build
26+ - name : Validate Docker proxy target
27+ run : npm run proxy:target-check
2628 - name : Validate npmctl desired state
2729 run : npmctl validate desired-state
2830 - run : npm run docker:build
Original file line number Diff line number Diff line change 3131 - run : npm ci
3232 - run : npm run check
3333 - run : npm run build
34+ - name : Validate Docker proxy target
35+ run : npm run proxy:target-check
3436 - name : Validate npmctl proxy desired state
3537 run : npmctl validate desired-state/proxy.yaml
3638 - name : Check Nginx Proxy Manager API schema
Original file line number Diff line number Diff line change 1818 "dns:doctor" : " npmctl dns doctor --provider namecheap" ,
1919 "proxy:validate" : " npmctl validate desired-state/proxy.yaml" ,
2020 "proxy:plan" : " npmctl plan desired-state/proxy.yaml --owner npmctl-com" ,
21- "proxy:apply" : " npmctl apply desired-state/proxy.yaml --owner npmctl-com"
21+ "proxy:apply" : " npmctl apply desired-state/proxy.yaml --owner npmctl-com" ,
22+ "proxy:target-check" : " node scripts/validate-proxy-target.mjs"
2223 },
2324 "dependencies" : {
2425 "@mdwrk/lander-core" : " ^0.1.2" ,
Original file line number Diff line number Diff line change 1+ import fs from "node:fs" ;
2+
3+ const compose = fs . readFileSync ( "docker-compose.yaml" , "utf8" ) ;
4+ const proxy = fs . readFileSync ( "desired-state/proxy.yaml" , "utf8" ) ;
5+
6+ const containerMatch = compose . match ( / ^ [ \t ] * c o n t a i n e r _ n a m e : [ \t ] * ( [ ^ \r \n # ] + ) / m) ;
7+ if ( ! containerMatch ) {
8+ throw new Error ( "docker-compose.yaml must define an explicit container_name for the site service" ) ;
9+ }
10+
11+ const containerName = containerMatch [ 1 ] . trim ( ) ;
12+ const forwardMatches = [ ...proxy . matchAll ( / ^ [ \t ] * f o r w a r d _ h o s t : [ \t ] * ( [ ^ \r \n # ] + ) / gm) ] . map ( ( match ) => match [ 1 ] . trim ( ) ) ;
13+ if ( forwardMatches . length === 0 ) {
14+ throw new Error ( "desired-state/proxy.yaml must define at least one forward_host" ) ;
15+ }
16+
17+ const ipLiteral = / ^ (?: \d { 1 , 3 } \. ) { 3 } \d { 1 , 3 } $ / ;
18+ for ( const forwardHost of forwardMatches ) {
19+ if ( ipLiteral . test ( forwardHost ) ) {
20+ throw new Error ( `forward_host must be the Docker container name, not an IP literal: ${ forwardHost } ` ) ;
21+ }
22+ if ( forwardHost !== containerName ) {
23+ throw new Error ( `forward_host "${ forwardHost } " must match docker-compose container_name "${ containerName } "` ) ;
24+ }
25+ }
26+
27+ console . log ( `proxy target ok: ${ containerName } ` ) ;
You can’t perform that action at this time.
0 commit comments