99 "log"
1010 "os"
1111 "path/filepath"
12+ "sync"
1213
1314 "github.com/jumppad-labs/hclconfig"
1415 hclerrors "github.com/jumppad-labs/hclconfig/errors"
@@ -43,18 +44,20 @@ type Engine interface {
4344
4445// EngineImpl is responsible for creating and destroying resources
4546type EngineImpl struct {
46- providers config.Providers
47- log logger.Logger
48- config * hclconfig.Config
49- ctx context.Context
50- force bool
47+ providers config.Providers
48+ log logger.Logger
49+ config * hclconfig.Config
50+ ctx context.Context
51+ force bool
52+ cacheMutex sync.Mutex
5153}
5254
5355// New creates a new Jumppad engine
5456func New (p config.Providers , l logger.Logger ) (Engine , error ) {
5557 e := & EngineImpl {}
5658 e .log = l
5759 e .providers = p
60+ e .cacheMutex = sync.Mutex {}
5861
5962 // Set the standard writer to our logger as the DAG uses the standard library log.
6063 log .SetOutput (l .StandardWriter ())
@@ -534,6 +537,7 @@ func (e *EngineImpl) createCallback(r types.Resource) error {
534537 // to the network and set the dependency
535538 if r .Metadata ().Type == network .TypeNetwork && r .Metadata ().Properties [constants .PropertyStatus ] == constants .StatusCreated {
536539 // get the image cache
540+ e .cacheMutex .Lock ()
537541 ic , err := e .config .FindResource ("resource.image_cache.default" )
538542 if err == nil {
539543 e .log .Debug ("Attaching image cache to network" , "network" , ic .Metadata ().ID )
@@ -545,10 +549,12 @@ func (e *EngineImpl) createCallback(r types.Resource) error {
545549 } else {
546550 e .log .Error ("Unable to find Image Cache" , "error" , err )
547551 }
552+ e .cacheMutex .Unlock ()
548553 }
549554
550555 if r .Metadata ().Type == cache .TypeRegistry && r .Metadata ().Properties [constants .PropertyStatus ] == constants .StatusCreated {
551556 // get the image cache
557+ e .cacheMutex .Lock ()
552558 ic , err := e .config .FindResource ("resource.image_cache.default" )
553559 if err == nil {
554560 // append the registry if not all ready present and not in the default list
@@ -570,11 +576,13 @@ func (e *EngineImpl) createCallback(r types.Resource) error {
570576 ic .(* cache.ImageCache ).Registries = append (ic .(* cache.ImageCache ).Registries , * r .(* cache.Registry ))
571577 }
572578
573- e .log .Debug ("Adding registy to image cache" , "registry" , r .(* cache.Registry ).Hostname )
579+ e .log .Debug ("Adding registry to image cache" , "registry" , r .(* cache.Registry ).Hostname )
574580
575581 // we now need to stop and restart the container to pick up the new registry changes
576582 np := e .providers .GetProvider (ic )
577583
584+ e .cacheMutex .Unlock ()
585+
578586 err := np .Destroy (e .ctx , e .force )
579587 if err != nil {
580588 e .log .Error ("Unable to destroy Image Cache" , "error" , err )
0 commit comments