bazelbuild / rules_k8s

This repository contains rules for interacting with Kubernetes configurations / clusters.
Apache License 2.0
290 stars 136 forks source link

How to resolve locally built images? #685

Open nickdecooman opened 2 years ago

nickdecooman commented 2 years ago

For local development, I am using Docker inside a Minikube cluster. I would like to build the image and then apply it to the cluster directly without the image being published to some remote registry.

Unfortunately, when not providing a registry in the image name, k8s_object seems to fall back to index.docker.io.

Example Assume a Docker target (:image) that builds an image with the following name: bazel/services/api:image

BUILD.bazel:

rust_image(
      name ="image",
      ....
)

k8s_object(
    name = "k8s",
    template = ":k8s.yaml",
    context = "minikube",
    images = {
        "bazel/services/api:image": ":image"
    },
)

k8s.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-deployment
  labels:
    app: api
spec:
  selector:
    matchLabels:
      app: api
  replicas: 1
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: bazel/services/api:image
          imagePullPolicy: Never

Now, when running bazel run //services/api:k8s.resolve -- --no_push=true, the image is resolved to index.docker.io/bazel/services/api@sha256:3ebdf5964644a7aba0b4cde6baa5fd1c822ee61f784ca2c3b6cc5cf29bd72270

How can I disable the fallback to index.docker.io so that the image name resolves to bazel/services/api@sha256:3ebdf5964644a7aba0b4cde6baa5fd1c822ee61f784ca2c3b6cc5cf29bd72270?

Setting image_chroot with an empty string does not work.

Thanks!

jmileson commented 2 years ago

I got local images working by doing the following:

loeffel-io commented 2 years ago

🙈