Skip to content

Commit

Permalink
feat(k8s/amour): use structured image
Browse files Browse the repository at this point in the history
should allow renovate to update digests, and should be a bit more clear.
  • Loading branch information
uhthomas committed Jan 11, 2024
1 parent 97e93cb commit 92c7d3b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 5 deletions.
6 changes: 3 additions & 3 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def dependencies():
)
http_archive(
name = "com_github_tnarg_rules_cue",
sha256 = "88a52126d169ba7090335f872f6b42b9c8d625d5b362bf781d82efc553e37af3",
strip_prefix = "rules_cue-d7360f88423830afe3b4f2e334e9a6456d58f994",
urls = ["https://github.com/uhthomas/rules_cue/archive/d7360f88423830afe3b4f2e334e9a6456d58f994.tar.gz"],
sha256 = "f0869e8a8fe99a3cc0e967a4506c2c237f668a61a346211184ae576bc46b83cc",
strip_prefix = "rules_cue-a687771e1b85f7552f9f128f5231fe0e27ec97df",
urls = ["https://github.com/uhthomas/rules_cue/archive/a687771e1b85f7552f9f128f5231fe0e27ec97df.tar.gz"],
)
http_archive(
name = "rules_proto",
Expand Down
1 change: 1 addition & 0 deletions k8s/amour/karma/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ cue_library(
"//cue.mod/gen/k8s.io/api/apps/v1:cue_v1_library",
"//cue.mod/gen/k8s.io/api/core/v1:cue_v1_library",
"//cue.mod/gen/k8s.io/api/networking/v1:cue_v1_library",
"//tools:cue_tools_library",
],
)
2 changes: 1 addition & 1 deletion k8s/amour/karma/deployment_list.cue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
spec: {
containers: [{
name: "karma"
image: "ghcr.io/prymitive/karma:v\(#Version)"
image: _image.reference
ports: [{
name: "http"
containerPort: 8080
Expand Down
10 changes: 10 additions & 0 deletions k8s/amour/karma/list.cue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"list"

"k8s.io/api/core/v1"

"github.com/uhthomas/automata/tools"
)

#Name: "karma"
Expand All @@ -12,6 +14,14 @@ import (
// renovate: datasource=github-releases depName=prymitive/karma extractVersion=^v(?<version>.*)$
#Version: "0.116"

_image: tools.#Image & {
name: "ghcr.io/prymitive/karma"
tag: "0.116"
digest: "sha256:ddfb0a874d24ca314457a74db351d59db1b9609206f4c01fc272b59a6867d374"
}

_image: tag: #Version

#List: v1.#List & {
apiVersion: "v1"
kind: "List"
Expand Down
4 changes: 3 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
],
"matchStrings": [
"image:\\s*\"(?<depName>[\\w\\/.-]*?):(?<currentValue>[\\w\\/.-]*?)\"",
"image:\\s*\"(?<depName>[\\w\\/.-]*?):(?<currentValue>[\\w\\/.-]*?)\"@(?<currentDigest>sha256:[a-f0-9]+)\""
"image:\\s*\"(?<depName>[\\w\\/.-]*?):(?<currentValue>[\\w\\/.-]*?)@(?<currentDigest>sha256:[a-f0-9]+)\"",
"name:\\s*\"(?<depName>[\\w\\/.-]*?)\"\\s*tag:\\s*\"(?<currentValue>[\\w\\/.-]*?)\"",
"name:\\s*\"(?<depName>[\\w\\/.-]*?)\"\\s*tag:\\s*\"(?<currentValue>[\\w\\/.-]*?)\"\\s*digest:\\s*\"(?<currentDigest>sha256:[a-f0-9]+)\""
],
"datasourceTemplate": "docker",
"versioningTemplate": "docker"
Expand Down
8 changes: 8 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
load("@com_github_tnarg_rules_cue//cue:cue.bzl", "cue_library")
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "tools_test",
srcs = ["tools_test.go"],
)

cue_library(
name = "cue_tools_library",
srcs = ["image.cue"],
importpath = "github.com/uhthomas/automata/tools",
visibility = ["//visibility:public"],
)
19 changes: 19 additions & 0 deletions tools/image.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tools

import "strings"

#Image: {
name: string
tag: string
digest?: string & strings.HasPrefix("sha256:")

if tag == "" && digest == "" {
reference: name
}
if tag != "" && digest == "" {
reference: "\(name):\(tag)"
}
if tag != "" && digest != "" {
reference: "\(name):\(tag)@\(digest)"
}
}

0 comments on commit 92c7d3b

Please sign in to comment.