Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Cloud Builder for CUE CLI #620

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mmizutani
Copy link

@mmizutani mmizutani commented May 20, 2023

This PR introduces a Cloud Builder for CUE, a data constraint language for effective management of configurations, schemas, and data.

The CUE CLI is useful when, for instance, generating YAML resource definitions for Kubernetes and Google Cloud Run from type-safe templates. Its functionalities are more generic than those of kustomize, HCL (Terraform) and ksonnet.

A template file written in the CUE language can generate variations of YAML files based on input variables:

# template.cue

_env: "dev" | "stg" | "prd" @tag(env)
_project: =~"^my-project-[a-z]$" @tag(project)
_commit_hash: =~"^[0-9a-z]{7}$" | *_env @tag(commit_hash)

apiVersion: "serving.knative.dev/v1"
kind:       "Service"
metadata: {
  name: "myservice-\(_env)"
}
spec: {
  template: {
    spec: {
      containers: [{
        name:  "nginx"
        image: "us-docker.pkg.dev/\(_project)/myrepo-\(_env)/nginx:\(_commit_hash)"
      }]
    }
  }
}
$ cue eval template.cue -t env=dev -t project=my-project-a -t commit_hash=$(git rev-parse --short HEAD -- .) --out yaml 
              
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: myservice-dev
spec:
  template:
    spec:
      containers:
        - name: nginx
          image: us-docker.pkg.dev/my-project-a/myrepo-dev/nginx:1cdcc3e

An example usage of this Cloud Builder is as follows:

steps:
- name: 'gcr.io/${PROJECT_ID}/cue'
  args: ['--help']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant