@@ -5,6 +5,26 @@ public class DockerStartupException : Exception
55 public DockerStartupException ( string message ) : base ( message )
66 {
77 }
8+
9+ public static bool DockerStartupCompleted { get ; private set ; }
10+ public static Exception ? DockerStartupError { get ; private set ; }
11+
12+ public static void ResetStartupState ( )
13+ {
14+ DockerStartupCompleted = false ;
15+ DockerStartupError = null ;
16+ }
17+
18+ public static void MarkStartupCompleted ( )
19+ {
20+ DockerStartupCompleted = true ;
21+ }
22+
23+ public static void MarkStartupFailed ( Exception ex )
24+ {
25+ DockerStartupError = ex ;
26+ DockerStartupCompleted = false ;
27+ }
828}
929
1030public class DockerStartupHostedService : IHostedService
@@ -24,33 +44,45 @@ public DockerStartupHostedService(ILogger<DockerStartupHostedService> logger, IW
2444
2545 public async Task StartAsync ( CancellationToken cancellationToken )
2646 {
47+ DockerStartupException . ResetStartupState ( ) ;
48+
2749 var skipBuildValue = Environment . GetEnvironmentVariable ( SkipBuildEnvVar ) ;
2850 var skipBuild = string . Equals ( skipBuildValue , "1" , StringComparison . OrdinalIgnoreCase ) ||
2951 string . Equals ( skipBuildValue , "true" , StringComparison . OrdinalIgnoreCase ) ;
3052
3153 if ( skipBuild )
3254 {
3355 Logger . LogInformation ( "Skipping docker image build because {SkipBuildEnvVar}=true" , SkipBuildEnvVar ) ;
56+ DockerStartupException . MarkStartupCompleted ( ) ;
3457 return ;
3558 }
3659
37- Logger . LogInformation ( "Building the PluginBuilder docker image" ) ;
38-
39- var buildResult = await ProcessRunner . RunAsync ( new ProcessSpec
60+ try
4061 {
41- Executable = "docker" ,
42- EnvironmentVariables =
62+ Logger . LogInformation ( "Building the PluginBuilder docker image" ) ;
63+
64+ var buildResult = await ProcessRunner . RunAsync ( new ProcessSpec
4365 {
44- // Somehow we get permission problem when buildkit isn't used
45- [ "DOCKER_BUILDKIT" ] = "1"
46- } ,
47- Arguments = new [ ] { "build" , "-f" , "PluginBuilder.Dockerfile" , "-t" , "plugin-builder" , "." } ,
48- WorkingDirectory = ContentRootPath
49- } , cancellationToken ) ;
50- if ( buildResult != 0 )
51- throw new DockerStartupException ( "The build of PluginBuilder.Dockerfile failed" ) ;
52-
53- await CleanupDanglingBuildVolumes ( cancellationToken ) ;
66+ Executable = "docker" ,
67+ EnvironmentVariables =
68+ {
69+ // Somehow we get permission problem when buildkit isn't used
70+ [ "DOCKER_BUILDKIT" ] = "1"
71+ } ,
72+ Arguments = new [ ] { "build" , "-f" , "PluginBuilder.Dockerfile" , "-t" , "plugin-builder" , "." } ,
73+ WorkingDirectory = ContentRootPath
74+ } , cancellationToken ) ;
75+ if ( buildResult != 0 )
76+ throw new DockerStartupException ( "The build of PluginBuilder.Dockerfile failed" ) ;
77+
78+ await CleanupDanglingBuildVolumes ( cancellationToken ) ;
79+ DockerStartupException . MarkStartupCompleted ( ) ;
80+ }
81+ catch ( Exception ex )
82+ {
83+ DockerStartupException . MarkStartupFailed ( ex ) ;
84+ throw ;
85+ }
5486 }
5587
5688 public Task StopAsync ( CancellationToken cancellationToken )
0 commit comments