@@ -33,7 +33,7 @@ export class HostPortCheck implements PortCheck {
3333
3434export class InternalPortCheck implements PortCheck {
3535 private isDistroless = false ;
36- private commandOutputs = new Set < string > ( ) ;
36+ private readonly commandOutputs = new Set < string > ( ) ;
3737
3838 constructor (
3939 private readonly client : ContainerRuntimeClient ,
@@ -53,28 +53,29 @@ export class InternalPortCheck implements PortCheck {
5353 ) ;
5454 const isBound = commandResults . some ( ( result ) => result . exitCode === 0 ) ;
5555
56+ // https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
57+ // If a command is not found, the child process created to execute it returns a status of 127.
58+ // If a command is found but is not executable, the return status is 126.
59+ const shellExists = commandResults . some ( ( result ) => result . exitCode !== 126 && result . exitCode !== 127 ) ;
60+ if ( ! isBound && ! shellExists && ! this . isDistroless ) {
61+ this . isDistroless = true ;
62+ log . error ( `The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy` , {
63+ containerId : this . container . id ,
64+ } ) ;
65+ }
66+
5667 if ( ! isBound && log . enabled ( ) ) {
57- const shellExists = commandResults . some ( ( result ) => result . exitCode !== 126 ) ;
58- if ( ! shellExists ) {
59- if ( ! this . isDistroless ) {
60- this . isDistroless = true ;
61- log . error ( `The HostPortWaitStrategy will not work on a distroless image, use an alternate wait strategy` , {
62- containerId : this . container . id ,
63- } ) ;
64- }
65- } else {
66- commandResults
67- . map ( ( result ) => ( { ...result , output : result . output . trim ( ) } ) )
68- . filter ( ( result ) => result . exitCode !== 126 && result . output . length > 0 )
69- . forEach ( ( result ) => {
70- if ( ! this . commandOutputs . has ( this . commandOutputsKey ( result . output ) ) ) {
71- log . trace ( `Port check result exit code ${ result . exitCode } : ${ result . output } ` , {
72- containerId : this . container . id ,
73- } ) ;
74- this . commandOutputs . add ( this . commandOutputsKey ( result . output ) ) ;
75- }
76- } ) ;
77- }
68+ commandResults
69+ . map ( ( result ) => ( { ...result , output : result . output . trim ( ) } ) )
70+ . filter ( ( result ) => result . exitCode !== 126 && result . output . length > 0 )
71+ . forEach ( ( result ) => {
72+ if ( ! this . commandOutputs . has ( this . commandOutputsKey ( result . output ) ) ) {
73+ log . trace ( `Port check result exit code ${ result . exitCode } : ${ result . output } ` , {
74+ containerId : this . container . id ,
75+ } ) ;
76+ this . commandOutputs . add ( this . commandOutputsKey ( result . output ) ) ;
77+ }
78+ } ) ;
7879 }
7980
8081 return isBound ;
0 commit comments