-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-cache-bake.hcl
65 lines (61 loc) · 1.56 KB
/
github-cache-bake.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
variable "HOSTNAME" {
default = ""
}
// HOST for OS compatibility
variable "HOST" {
default = "${HOSTNAME}"
}
variable "GITHUB_REF_PROTECTED" {
default = "false"
}
variable "GITHUB_REF_TYPE" {
// Assume CI contexts are for branches
default = "branch"
}
variable "GITHUB_SHA" {
// If not running in CI, assume local
default = "local"
}
variable "GITHUB_REF_NAME" {
// If not executing in GitHub Actions, use a local, host-specific ref
default = "local-${HOST}"
}
variable "VERSION" {
// Default the version to the ref from CI, sanitized
// Replace any non-alphanumeric, underscore, or dot characters in the ref with dashes
default = regex_replace(GITHUB_REF_NAME, "[^a-zA-Z0-9_.]", "-")
}
variable "IMAGE_NAME" {
default = ""
}
variable "REGISTRY" {
default = "ghcr.io/"
}
variable "IMAGE_REF" {
default = format(
"%s/%s",
trimsuffix(REGISTRY, "/"),
IMAGE_NAME
)
}
target "default" {
dockerfile = "cwd://Dockerfile"
context = BAKE_CMD_CONTEXT
cache-from = [
// Always pull cache from main
"type=registry,ref=${IMAGE_REF}-cache:main",
"type=registry,ref=${IMAGE_REF}-cache:${VERSION}"
]
cache-to = [
"type=registry,rewrite-timestamp=true,mode=max,ref=${IMAGE_REF}-cache:${VERSION}"
]
output = [
"type=docker,name=${IMAGE_NAME}",
// If running for an unprotected ref (e.g. PRs), append the commit SHA
(
("${GITHUB_REF_PROTECTED}" == "true" || "${GITHUB_REF_TYPE}" == "tag" )
? "type=registry,name=${IMAGE_REF}:${VERSION}"
: "type=registry,name=${IMAGE_REF}:${VERSION}-${GITHUB_SHA}"
)
]
}