Skip to content

Commit e51d62d

Browse files
authored
Merge pull request #13 from smartrecruiters/build-valid-dockerfile-when-parent-version-unknown
Default parent version when unknown
2 parents 8487c85 + ebaa577 commit e51d62d

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
APP_NAME=docker-bakery
2-
VERSION=1.3.1
2+
VERSION=1.3.2
33

44
.DEFAULT_GOAL: all
55

bakery/service/bakery.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,30 @@ func InitConfiguration(configFile, rootDir string, additionalProperties []string
7070
return err
7171
}
7272

73+
updateUnknownParentsVersions(hierarchy)
74+
7375
rootName := fmt.Sprintf("Dockerfiles hierarchy discovered in %s", config.RootDir)
7476
hierarchy.PrintImageHierarchy(rootName)
7577
dependencies = hierarchy.GetImagesWithDependants()
7678

7779
return nil
7880
}
7981

82+
// updateUnknownParentsVersions makes sure that when building an image whose parent x_VERSION from template is unknown,
83+
// we're still able to produce valid Dockerfile with parent image version set to 0.0.0
84+
func updateUnknownParentsVersions(h DockerHierarchy) {
85+
nonExisting := make([]string, 0)
86+
for imageName := range h.GetImages() {
87+
dynamicName := dynamicImageVersionName(imageName)
88+
if _, ok := config.Properties[dynamicName]; !ok {
89+
nonExisting = append(nonExisting, imageName)
90+
}
91+
}
92+
for _, imageName := range nonExisting {
93+
config.setDynamicImageVersionProperty(imageName, "0.0.0")
94+
}
95+
}
96+
8097
// DumpLatestVersions saves images with their latest version in json format to file.
8198
// Optionally it can exclude images from provided directories.
8299
func DumpLatestVersions(fileName, excludeDirsPattern string) error {

bakery/service/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ func (cfg *Config) UpdateVersionProperties(versions map[string]*semver.Version)
7373
// The result of invocation setDynamicImageVersionProperty('redis', '1.0.0')
7474
// would be property REDIS_VERSION = '1.0.0'
7575
func (cfg *Config) setDynamicImageVersionProperty(imgName, version string) {
76+
propertyName := dynamicImageVersionName(imgName)
77+
commons.Debugf("Setting property %s to %s", propertyName, version)
78+
cfg.Properties[propertyName] = version
79+
}
80+
81+
func dynamicImageVersionName(imgName string) string {
7682
imgNameInTmpl := strings.ToUpper(imgName)
7783
imgNameInTmpl = strings.Replace(imgNameInTmpl, "-", "_", -1)
7884
imgNameInTmpl = strings.Replace(imgNameInTmpl, ".", "_", -1)
79-
propertyName := fmt.Sprintf("%s_VERSION", imgNameInTmpl)
80-
commons.Debugf("Setting property %s to %s", propertyName, version)
81-
cfg.Properties[propertyName] = version
85+
return fmt.Sprintf("%s_VERSION", imgNameInTmpl)
8286
}
8387

8488
// setImageVersion sets the IMAGE_VERSION property to the provided version.

0 commit comments

Comments
 (0)