fix(server): Do not invoke layer build if no layers are missing

This previously invoked a Nix derivation that spent a few seconds on
making an empty object in JSON ...
This commit is contained in:
Vincent Ambo 2019-10-03 13:08:23 +01:00 committed by Vincent Ambo
parent feba42e409
commit 1124b8c236

View file

@ -277,6 +277,11 @@ func prepareLayers(ctx context.Context, s *State, image *Image, result *ImageRes
// Builds remaining layers (those not already cached) via Nix. // Builds remaining layers (those not already cached) via Nix.
func buildLayers(s *State, image *Image, grouped []layers.Layer) (map[string]string, error) { func buildLayers(s *State, image *Image, grouped []layers.Layer) (map[string]string, error) {
result := make(map[string]string)
if len(grouped) == 0 {
return result, nil
}
srcType, srcArgs := s.Cfg.Pkgs.Render(image.Tag) srcType, srcArgs := s.Cfg.Pkgs.Render(image.Tag)
args := []string{ args := []string{
"--argstr", "srcType", srcType, "--argstr", "srcType", srcType,
@ -312,7 +317,6 @@ func buildLayers(s *State, image *Image, grouped []layers.Layer) (map[string]str
} }
log.Printf("Finished layer preparation for '%s' via Nix\n", image.Name) log.Printf("Finished layer preparation for '%s' via Nix\n", image.Name)
result := make(map[string]string)
err = json.Unmarshal(output, &result) err = json.Unmarshal(output, &result)
if err != nil { if err != nil {
return nil, err return nil, err