Skip to content

Commit

Permalink
chore: use tags as caches as well
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-svensson committed Apr 22, 2022
1 parent 9b727f1 commit fad6776
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 40 deletions.
6 changes: 3 additions & 3 deletions cmd/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ COPY --from=build /test/testfile testfile
"debug: Authenticating against registry <green>No docker registry</green>\n",
"debug: Authentication <yellow>not supported</yellow> for registry <green>No docker registry</green>\n",
fmt.Sprintf("debug: Using build variables commit <green>%s</green> on branch <green>master</green>\n", hash),
fmt.Sprintf("debug: performing docker build with options (auths removed):\ntags:\n - noregistry/%[1]s:build\nsuppressoutput: false\nremotecontext: client-session\nnocache: false\nremove: true\nforceremove: false\npullparent: true\nisolation: \"\"\ncpusetcpus: \"\"\ncpusetmems: \"\"\ncpushares: 0\ncpuquota: 0\ncpuperiod: 0\nmemory: 0\nmemoryswap: -1\ncgroupparent: \"\"\nnetworkmode: \"\"\nshmsize: 268435456\ndockerfile: Dockerfile\nulimits: []\nbuildargs:\n BUILDKIT_INLINE_CACHE: \"1\"\n CI_BRANCH: master\n CI_COMMIT: %[2]s\nauthconfigs: {}\ncontext: null\nlabels: {}\nsquash: false\ncachefrom:\n - noregistry/%[1]s:build\nsecurityopt: []\nextrahosts: []\ntarget: build\nsessionid: \"\"\nplatform: \"\"\nversion: \"2\"\nbuildid: \"\"\noutputs: []\n\n", base, hash),
fmt.Sprintf("debug: performing docker build with options (auths removed):\ntags:\n - noregistry/%[1]s:build\nsuppressoutput: false\nremotecontext: client-session\nnocache: false\nremove: true\nforceremove: false\npullparent: true\nisolation: \"\"\ncpusetcpus: \"\"\ncpusetmems: \"\"\ncpushares: 0\ncpuquota: 0\ncpuperiod: 0\nmemory: 0\nmemoryswap: -1\ncgroupparent: \"\"\nnetworkmode: \"\"\nshmsize: 268435456\ndockerfile: Dockerfile\nulimits: []\nbuildargs:\n BUILDKIT_INLINE_CACHE: \"1\"\n CI_BRANCH: master\n CI_COMMIT: %[2]s\nauthconfigs: {}\ncontext: null\nlabels: {}\nsquash: false\ncachefrom:\n - noregistry/001:build\n - noregistry/001:master\n - noregistry/001:latest\nsecurityopt: []\nextrahosts: []\ntarget: build\nsessionid: \"\"\nplatform: \"\"\nversion: \"2\"\nbuildid: \"\"\noutputs: []\n\n", base, hash),
"info: Successfully tagged noregistry/001:build\n",
fmt.Sprintf("debug: performing docker build with options (auths removed):\ntags:\n - noregistry/%[1]s:export\nsuppressoutput: false\nremotecontext: client-session\nnocache: false\nremove: true\nforceremove: false\npullparent: true\nisolation: \"\"\ncpusetcpus: \"\"\ncpusetmems: \"\"\ncpushares: 0\ncpuquota: 0\ncpuperiod: 0\nmemory: 0\nmemoryswap: -1\ncgroupparent: \"\"\nnetworkmode: \"\"\nshmsize: 268435456\ndockerfile: Dockerfile\nulimits: []\nbuildargs:\n BUILDKIT_INLINE_CACHE: \"1\"\n CI_BRANCH: master\n CI_COMMIT: %[2]s\nauthconfigs: {}\ncontext: null\nlabels: {}\nsquash: false\ncachefrom:\n - noregistry/%[1]s:export\n - noregistry/%[1]s:build\nsecurityopt: []\nextrahosts: []\ntarget: export\nsessionid: \"\"\nplatform: \"\"\nversion: \"2\"\nbuildid: \"\"\noutputs:\n - type: local\n attrs: {}\n\n", base, hash),
fmt.Sprintf("debug: performing docker build with options (auths removed):\ntags:\n - noregistry/%[1]s:export\nsuppressoutput: false\nremotecontext: client-session\nnocache: false\nremove: true\nforceremove: false\npullparent: true\nisolation: \"\"\ncpusetcpus: \"\"\ncpusetmems: \"\"\ncpushares: 0\ncpuquota: 0\ncpuperiod: 0\nmemory: 0\nmemoryswap: -1\ncgroupparent: \"\"\nnetworkmode: \"\"\nshmsize: 268435456\ndockerfile: Dockerfile\nulimits: []\nbuildargs:\n BUILDKIT_INLINE_CACHE: \"1\"\n CI_BRANCH: master\n CI_COMMIT: %[2]s\nauthconfigs: {}\ncontext: null\nlabels: {}\nsquash: false\ncachefrom:\n - noregistry/001:export\n - noregistry/001:build\n - noregistry/001:master\n - noregistry/001:latest\nsecurityopt: []\nextrahosts: []\ntarget: export\nsessionid: \"\"\nplatform: \"\"\nversion: \"2\"\nbuildid: \"\"\noutputs:\n - type: local\n attrs: {}\n\n", base, hash),
"info: ",
fmt.Sprintf("debug: performing docker build with options (auths removed):\ntags:\n - noregistry/%[1]s:%[2]s\n - noregistry/%[1]s:master\n - noregistry/%[1]s:latest\nsuppressoutput: false\nremotecontext: client-session\nnocache: false\nremove: true\nforceremove: false\npullparent: true\nisolation: \"\"\ncpusetcpus: \"\"\ncpusetmems: \"\"\ncpushares: 0\ncpuquota: 0\ncpuperiod: 0\nmemory: 0\nmemoryswap: -1\ncgroupparent: \"\"\nnetworkmode: \"\"\nshmsize: 268435456\ndockerfile: Dockerfile\nulimits: []\nbuildargs:\n BUILDKIT_INLINE_CACHE: \"1\"\n CI_BRANCH: master\n CI_COMMIT: %[2]s\nauthconfigs: {}\ncontext: null\nlabels: {}\nsquash: false\ncachefrom:\n - noregistry/%[1]s:master\n - noregistry/%[1]s:latest\n - noregistry/001:export\n - noregistry/001:build\nsecurityopt: []\nextrahosts: []\ntarget: \"\"\nsessionid: \"\"\nplatform: \"\"\nversion: \"2\"\nbuildid: \"\"\noutputs: []\n\n", base, hash),
fmt.Sprintf("debug: performing docker build with options (auths removed):\ntags:\n - noregistry/%[1]s:%[2]s\n - noregistry/%[1]s:master\n - noregistry/%[1]s:latest\nsuppressoutput: false\nremotecontext: client-session\nnocache: false\nremove: true\nforceremove: false\npullparent: true\nisolation: \"\"\ncpusetcpus: \"\"\ncpusetmems: \"\"\ncpushares: 0\ncpuquota: 0\ncpuperiod: 0\nmemory: 0\nmemoryswap: -1\ncgroupparent: \"\"\nnetworkmode: \"\"\nshmsize: 268435456\ndockerfile: Dockerfile\nulimits: []\nbuildargs:\n BUILDKIT_INLINE_CACHE: \"1\"\n CI_BRANCH: master\n CI_COMMIT: %[2]s\nauthconfigs: {}\ncontext: null\nlabels: {}\nsquash: false\ncachefrom:\n - noregistry/001:export\n - noregistry/001:build\n - noregistry/001:master\n - noregistry/001:latest\nsecurityopt: []\nextrahosts: []\ntarget: \"\"\nsessionid: \"\"\nplatform: \"\"\nversion: \"2\"\nbuildid: \"\"\noutputs: []\n\n", base, hash),
fmt.Sprintf("info: Successfully tagged noregistry/%[1]s:%[2]s\nSuccessfully tagged noregistry/%[1]s:master\nSuccessfully tagged noregistry/%[1]s:latest\n", base, hash),
})
}
25 changes: 12 additions & 13 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,18 @@ func build(client docker.Client, dir string, buildVars Args) error {
commit := currentCI.Commit()
branch := currentCI.BranchReplaceSlash()
log.Debugf("Using build variables commit <green>%s</green> on branch <green>%s</green>\n", commit, branch)
var caches []string
var tags []string
branchTag := docker.Tag(currentRegistry.RegistryUrl(), currentCI.BuildName(), branch)
latestTag := docker.Tag(currentRegistry.RegistryUrl(), currentCI.BuildName(), "latest")
tags = append(tags, []string{
docker.Tag(currentRegistry.RegistryUrl(), currentCI.BuildName(), commit),
branchTag,
}...)
if currentCI.Branch() == "master" || currentCI.Branch() == "main" {
tags = append(tags, latestTag)
}

caches := []string{branchTag, latestTag}

buildArgs := map[string]*string{
"BUILDKIT_INLINE_CACHE": aws.String("1"),
Expand Down Expand Up @@ -152,18 +163,6 @@ func build(client docker.Client, dir string, buildVars Args) error {
}
}

var tags []string
branchTag := docker.Tag(currentRegistry.RegistryUrl(), currentCI.BuildName(), branch)
latestTag := docker.Tag(currentRegistry.RegistryUrl(), currentCI.BuildName(), "latest")
tags = append(tags, []string{
docker.Tag(currentRegistry.RegistryUrl(), currentCI.BuildName(), commit),
branchTag,
}...)
if currentCI.Branch() == "master" || currentCI.Branch() == "main" {
tags = append(tags, latestTag)
}

caches = append([]string{branchTag, latestTag}, caches...)
return buildStage(client, dir, buildVars, buildArgs, tags, caches, "", authenticator)
}

Expand Down
Loading

0 comments on commit fad6776

Please sign in to comment.