Skip to content

Commit

Permalink
k8s_deploy api for images already in registry (adobe#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
apesternikov authored and arturo-skydio committed Oct 5, 2023
1 parent fc30ed0 commit 45bc912
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ When you run `bazel run ///helloworld:mynamespace.apply`, it applies this file i
| ***image_repository*** | `None` | The repository to push images to. By default, this is generated from the current package path.
| ***image_repository_prefix*** | `None` | Add a prefix to the image_repository. Can be used to upload the images in
| ***not_gitops_image_repository_prefix*** | `{BUILD_USER}` | Add a prefix to the image_repository when gitops == False for the .apply|.delete targets
| ***image_pushes*** | `[]` | A list of labels implementing K8sPushInfo referring image uploaded into registry. See [Injecting Docker Images](#injecting-docker-images).
| ***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
Expand Down Expand Up @@ -318,6 +319,25 @@ Docker image and the files in the image. So for example, here's what will happen
1. A new `helloworld` manifest will be rendered using the new image
1. The new `helloworld` pod will be deployed

It is possible to use alternative ways to resolve images as long as respective rule implements K8sPushInfo provider. For example, this setup will mirror the referred image into a local registry and provide a reference to it. `k8s_deploy` will need to use `image_pushes` parameter:

```starlark
load("@com_fasterci_rules_mirror//mirror:defs.bzl", "mirror_image")
mirror_image(
name = "agnhost_image",
digest = "sha256:93c166faf53dba3c9c4227e2663ec1247e2a9a193d7b59eddd15244a3e331c3e",
dst_prefix = "gcr.io/myregistry/mirror",
src_image = "registry.k8s.io/e2e-test-images/agnhost:2.39",
)
k8s_deploy(
name = "agnhost",
manifests = ["agnhost.yaml"],
image_pushes = [
":agnhost_image",
]
)
```


<a name="adding-dependencies"></a>
### Adding Dependencies
Expand Down
5 changes: 3 additions & 2 deletions skylib/k8s.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def k8s_deploy(
image_registry = "docker.io", # registry to push container to. jenkins will need an access configured for gitops to work. Ignored for mynamespace.
image_repository = None, # repository (registry path) to push container to. Generated from the image bazel path if empty.
image_repository_prefix = None, # Mutually exclusive with 'image_repository'. Add a prefix to the repository name generated from the image bazel path
image_pushes = [], # list of targets implementing K8sPushInfo provider, representing reference to image already in a registry.
objects = [],
omit_image_tag_in_gitops = False,
gitops = True, # make sure to use gitops = False to work with individual namespace. This option will be turned False if namespace is '{BUILD_USER}'
Expand Down Expand Up @@ -162,7 +163,7 @@ def k8s_deploy(
# Mynamespace option
if not namespace:
namespace = "{BUILD_USER}"
image_pushes = _image_pushes(
image_pushes = image_pushes + _image_pushes(
name_suffix = "-mynamespace.push",
images = images,
image_registry = image_registry,
Expand Down Expand Up @@ -228,7 +229,7 @@ def k8s_deploy(
# gitops
if not namespace:
fail("namespace must be defined for gitops k8s_deploy")
image_pushes = _image_pushes(
image_pushes = image_pushes + _image_pushes(
name_suffix = ".push",
images = images,
image_registry = image_registry,
Expand Down

0 comments on commit 45bc912

Please sign in to comment.