Skip to content

Commit

Permalink
adds API_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Hatcher committed Oct 30, 2021
1 parent 37c9b25 commit e31f805
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"args": ["compose", "template", "up"]
"program": "${workspaceFolder}/cmd/build_test.go",
// "args": ["build"]
}
]
}
13 changes: 12 additions & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"html/template"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -228,12 +229,22 @@ func generateDockerfileTemplate(wr io.Writer, filename string) {

}

func getApiVersion(filename string) string {

content, err := ioutil.ReadFile(filepath.Dir(filename) + "/API_VERSION")
if err != nil {
return ""
} else {
return string(content) + "-"
}
}

// getTag determines the string used for the docker image tag that gets referenced in the registry.
// This is typically just the directory name the dockerfile resides in, but can be modified by either
// using a variant in the filename (detailed below) or by using a git branch other than the default
func getTag(filename string) string {

var tag string = filepath.Base(filepath.Dir(filename)) + getVariant(filename)
var tag string = getApiVersion(filename) + filepath.Base(filepath.Dir(filename)) + getVariant(filename)

if DockerRegistry != "" {
return DockerRegistry + ":" + tag
Expand Down
8 changes: 4 additions & 4 deletions cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func Test_buildCmdOneArgWithImagesOutputOnlyWithTagReal(t *testing.T) {

var actual = buildImage("../examples/images/example/Dockerfile")

if actual != "superterran/mach:example" {
if actual != "superterran/mach:v1-example" {
assert.FailNowf(t, "mach tag returned as expected, %s", actual)
}
}
Expand All @@ -196,7 +196,7 @@ func Test_buildCmdOneArgWithImagesOutputOnlyWithTagRealTemplate(t *testing.T) {

var actual = buildImage("../examples/images/example/Dockerfile-template.tpl")

if actual != "superterran/mach:example-template" {
if actual != "superterran/mach:v1-example-template" {
assert.FailNowf(t, "mach tag returned as expected, %s", actual)
}
}
Expand All @@ -208,7 +208,7 @@ func Test_buildCmdOneArgWithImagesOutputOnlyWithTagRealOutputOnly(t *testing.T)

var actual = buildImage("../examples/images/example/Dockerfile")

if actual != "superterran/mach:example" {
if actual != "superterran/mach:v1-example" {
assert.FailNowf(t, "mach tag returned as expected, %s", actual)
}
}
Expand All @@ -220,7 +220,7 @@ func Test_buildCmdOneArgWithImagesOutputOnlyWithTagRealTemplateOutputOnly(t *tes

var actual = buildImage("../examples/images/example/Dockerfile-template.tpl")

if actual != "superterran/mach:example-template" {
if actual != "superterran/mach:v1-example-template" {
assert.FailNowf(t, "mach tag returned as expected, %s", actual)
}
}
1 change: 1 addition & 0 deletions examples/images/example/API_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1

0 comments on commit e31f805

Please sign in to comment.