Skip to content

Commit

Permalink
tag all targets generated by k8s_deploy (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
apesternikov committed Jun 11, 2024
1 parent 2eef5b8 commit ecb6cae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ When you run `bazel run ///helloworld:mynamespace.apply`, it applies this file i
| ***release_branch_prefix*** | `master` | A git branch name/prefix. Automatically run GitOps while building this branch. See [GitOps and Deployment](#gitops_and_deployment).
| ***deployment_branch*** | `None` | Automatic GitOps output will appear in a branch and PR with this name. See [GitOps and Deployment](#gitops_and_deployment).
| ***gitops_path*** | `cloud` | Path within the git repo where gitops files get generated into
| ***tags*** | `[]` | A list of tags that will be added to all generated bazel targets. Useful for marking targets as manual.
| ***visibility*** | [Default_visibility](https://docs.bazel.build/versions/master/be/functions.html#package.default_visibility) | Changes the visibility of all rules generated by this macro. See [Bazel docs on visibility](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).


Expand Down
2 changes: 2 additions & 0 deletions push_oci/push_oci.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def push_oci(
image_digest_tag = False, # buildifier: disable=unused-variable either remove parameter or implement
tag = None,
remote_tags = None, # file with tags to push
tags = [], # bazel tags to add to the push_oci_rule
visibility = None):
if tag:
tags_label = "_{}_write_tags".format(name)
Expand All @@ -128,5 +129,6 @@ def push_oci(
image = image,
repository = repository,
remote_tags = remote_tags,
tags = tags,
visibility = visibility,
)
19 changes: 14 additions & 5 deletions skylib/k8s.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ show = rule(
executable = True,
)

def _image_pushes(name_suffix, images, image_registry, image_repository, image_digest_tag):
def _image_pushes(name_suffix, images, image_registry, image_repository, image_digest_tag, tags = []):
image_pushes = []

def process_image(image_label, image_alias = None):
Expand All @@ -81,6 +81,7 @@ def _image_pushes(name_suffix, images, image_registry, image_repository, image_d
image_digest_tag = image_digest_tag,
registry = image_registry,
repository = image_repository,
tags = tags,
visibility = ["//visibility:public"],
)
if not image_alias:
Expand All @@ -92,6 +93,7 @@ def _image_pushes(name_suffix, images, image_registry, image_repository, image_d
name = rule_name + "_alias_" + name_suffix,
alias = image_alias,
pushed_image = rule_name + name_suffix,
tags = tags,
visibility = ["//visibility:public"],
)
return rule_name + "_alias_" + name_suffix
Expand All @@ -106,10 +108,6 @@ def _image_pushes(name_suffix, images, image_registry, image_repository, image_d
push = process_image(image)
image_pushes.append(push)
return image_pushes
for image in images:
image_push = process_image(image)
image_pushes.append(image_push)
return image_pushes

def k8s_deploy(
name, # name of the rule is important for gitops, since it will become a part of the target manifest file name in /cloud
Expand Down Expand Up @@ -144,6 +142,7 @@ def k8s_deploy(
release_branch_prefix = "main",
start_tag = "{{",
end_tag = "}}",
tags = [], # tags to add to all generated rules.
visibility = None):
""" k8s_deploy
"""
Expand Down Expand Up @@ -175,6 +174,7 @@ def k8s_deploy(
image_registry = image_registry + "/mynamespace",
image_repository = image_repository,
image_digest_tag = image_digest_tag,
tags = tags,
)
kustomize(
name = name,
Expand All @@ -200,6 +200,7 @@ def k8s_deploy(
image_name_patches = image_name_patches,
image_tag_patches = image_tag_patches,
openapi_path = openapi_path,
tags = tags,
visibility = visibility,
)
kubectl(
Expand All @@ -208,6 +209,7 @@ def k8s_deploy(
cluster = cluster,
user = user,
namespace = namespace,
tags = tags,
visibility = visibility,
)
kubectl(
Expand All @@ -218,12 +220,14 @@ def k8s_deploy(
push = False,
user = user,
namespace = namespace,
tags = tags,
visibility = visibility,
)
show(
name = name + ".show",
namespace = namespace,
src = name,
tags = tags,
visibility = visibility,
)
else:
Expand All @@ -236,6 +240,7 @@ def k8s_deploy(
image_registry = image_registry,
image_repository = image_repository,
image_digest_tag = image_digest_tag,
tags = tags,
)
kustomize(
name = name,
Expand All @@ -261,13 +266,15 @@ def k8s_deploy(
image_name_patches = image_name_patches,
image_tag_patches = image_tag_patches,
openapi_path = openapi_path,
tags = tags,
)
kubectl(
name = name + ".apply",
srcs = [name],
cluster = cluster,
user = user,
namespace = namespace,
tags = tags,
visibility = visibility,
)
kustomize_gitops(
Expand All @@ -282,12 +289,14 @@ def k8s_deploy(
],
deployment_branch = deployment_branch,
release_branch_prefix = release_branch_prefix,
tags = tags,
visibility = ["//visibility:public"],
)
show(
name = name + ".show",
src = name,
namespace = namespace,
tags = tags,
visibility = visibility,
)

Expand Down

0 comments on commit ecb6cae

Please sign in to comment.