Skip to content

Commit

Permalink
ci: ensure separate caches
Browse files Browse the repository at this point in the history
By default, all images get cached to the same "scope" in github. This means
that while we build the images concurrently, they all compete for the same
cache location.

This means that our cache only applies to (at most) one image, making it
not that useful. To solve this, we have to provide separate "scopes" for
all images.

Signed-off-by: Moritz Wanzenböck <[email protected]>
  • Loading branch information
WanzenBug authored and rck committed Jun 24, 2024
1 parent c662086 commit be4b964
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ jobs:
provenance: true
sbom: true
push: ${{ github.event_name != 'pull_request' }}
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
env:
GIT_COMMIT: ${{ github.sha }}
CACHE: true
25 changes: 25 additions & 0 deletions dockerfiles/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ variable "LATEST" {
default = "true"
}

variable "CACHE" {
default = false
}

variable VERSIONS {
default = {
DRBD = ["9.2.10", "9.1.21"]
Expand Down Expand Up @@ -51,6 +55,19 @@ function "tags" {
])
}

# Generate a cache-to configuration
function "cache-to" {
params = [name]
result = CACHE ? ["type=gha,scope=${name},mode=max"] : []
}


# Generate a cache-from configuration
function "cache-from" {
params = [name]
result = CACHE ? ["type=gha,scope=${name}"] : []
}

group "default" {
targets = [
"drbd-reactor",
Expand All @@ -67,6 +84,8 @@ target "base" {
target "piraeus-server" {
inherits = ["base"]
tags = tags("piraeus-server", VERSIONS["LINSTOR"])
cache-from = cache-from("piraeus-server")
cache-to = cache-to("piraeus-server")
context = "piraeus-server"
args = {
DISTRO = DISTRO
Expand All @@ -78,6 +97,8 @@ target "piraeus-server" {
target "ktls-utils" {
inherits = ["base"]
tags = tags("ktls-utils", VERSIONS["KTLS_UTILS"])
cache-from = cache-from("ktls-utils")
cache-to = cache-to("ktls-utils")
context = "ktls-utils"
args = {
DISTRO = DISTRO
Expand All @@ -88,6 +109,8 @@ target "ktls-utils" {
target "drbd-reactor" {
inherits = ["base"]
tags = tags("drbd-reactor", VERSIONS["DRBD_REACTOR"])
cache-from = cache-from("drbd-reactor")
cache-to = cache-to("drbd-reactor")
context = "drbd-reactor"
args = {
DISTRO = DISTRO
Expand All @@ -99,6 +122,8 @@ target "drbd-driver-loader" {
name = "drbd-driver-loader-${distro}-${escape(drbd_version)}"
inherits = ["base"]
tags = tags("drbd9-${distro}", drbd_version)
cache-from = cache-from("drbd9-${distro}")
cache-to = cache-to("drbd9-${distro}")
context = "drbd-driver-loader"
dockerfile = "Dockerfile.${distro}"
matrix = {
Expand Down

0 comments on commit be4b964

Please sign in to comment.