### Install color package Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/cppforlife/color/README.md Use 'go get' to install the color package. ```bash go get github.com/fatih/color ``` -------------------------------- ### Install go-yaml.v2 Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/sigs.k8s.io/yaml/goyaml.v2/README.md Use 'go get' to install the go-yaml.v2 package. ```bash go get gopkg.in/yaml.v2 ``` -------------------------------- ### Install go-version Library Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/hashicorp/go-version/README.md Install the go-version library using the standard go get command. ```bash $ go get github.com/hashicorp/go-version ``` -------------------------------- ### Build FreePort from Source Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/phayes/freeport/README.md Install Go and then use 'go get' to download and install the FreePort library from source. ```bash sudo apt-get install golang # Download go. Alternativly build from source: https://golang.org/doc/install/source go get github.com/phayes/freeport ``` -------------------------------- ### Install go-isatty Package Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/mattn/go-isatty/README.md Install the go-isatty package using the go get command. ```bash go get github.com/mattn/go-isatty ``` -------------------------------- ### Install Cobra Library Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/spf13/cobra/README.md Use 'go get' to install the latest version of the Cobra library. ```bash go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### Install go-autorest/autorest/adal Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/Azure/go-autorest/autorest/adal/README.md Install the Azure Active Directory authentication library for Go using go get. ```bash go get -u github.com/Azure/go-autorest/autorest/adal ``` -------------------------------- ### Install Doublestar Package Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/bmatcuk/doublestar/README.md Use `go get` to install the doublestar package. This command fetches and installs the package and its dependencies. ```bash go get github.com/bmatcuk/doublestar ``` -------------------------------- ### Install uniseg Package Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/rivo/uniseg/README.md Use 'go get' to install the uniseg package for your Go project. ```bash go get github.com/rivo/uniseg ``` -------------------------------- ### Install and Import Kubernetes YAML Library Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/sigs.k8s.io/yaml/README.md Install the library using 'go get' and import it into your Go projects for YAML processing. ```bash go get sigs.k8s.io/yaml ``` ```go import "sigs.k8s.io/yaml" ``` -------------------------------- ### Define a WebService with Routes Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/emicklei/go-restful/README.md Example of creating a WebService, defining its path, supported content types, and a GET route for retrieving a user. The route specifies the handler function, documentation, path parameters, and the expected response type. ```go ws := new(restful.WebService) ws. Path("/users"). Consumes(restful.MIME_XML, restful.MIME_JSON). Produces(restful.MIME_JSON, restful.MIME_XML) ws.Route(ws.GET("/{user-id}").To(u.findUser). Doc("get a user"). Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")), Writes(User{})) ... func (u UserResource) findUser(request *restful.Request, response *restful.Response) { id := request.PathParameter("user-id") ... } ``` -------------------------------- ### Install json-iterator/go Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/json-iterator/go/README.md Install the library using the go get command. This is the standard method for adding Go packages to your project. ```bash go get github.com/json-iterator/go ``` -------------------------------- ### Install go-autorest Libraries Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/Azure/go-autorest/README.md Provides the go get commands to install the core go-autorest libraries and its subpackages. ```bash go get github.com/Azure/go-autorest/autorest go get github.com/Azure/go-autorest/autorest/azure go get github.com/Azure/go-autorest/autorest/date go get github.com/Azure/go-autorest/autorest/to ``` -------------------------------- ### Install go-colorable Package Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/mattn/go-colorable/README.md Install the go-colorable package using the go get command. This is the standard method for adding Go dependencies to your project. ```bash go get github.com/mattn/go-colorable ``` -------------------------------- ### Install Compute API Go Package Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/cloud.google.com/go/compute/metadata/README.md Use this command to install the compute metadata Go package. ```bash go get cloud.google.com/go/compute/metadata ``` -------------------------------- ### Run ytt Examples Locally Source: https://github.com/carvel-dev/vendir/blob/develop/examples/git-shallow/vendor/deeper-sha/README.md Execute ytt examples from the playground directory using the command line. This command processes the specified directory and outputs the results. ```bash ytt -f examples/playground/example-demo/ ``` ```bash ytt -f examples/playground/example-demo/ --output-directory tmp/ ``` -------------------------------- ### Persistence Configuration Example Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci/vendor/custom-repo-custom-version/charts/common/README.md An example configuration for the Persistence section, detailing enabled status, storage class, access mode, size, and path. ```yaml enabled: true storageClass: "-" accessMode: ReadWriteOnce size: 8Gi path: /bitnami ``` -------------------------------- ### Golang Example for FreePort Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/phayes/freeport/README.md This Go code demonstrates how to use the freeport library to get an available TCP port. Ensure error handling for the GetFreePort function. ```go package main import "github.com/phayes/freeport" func main() { port, err := freeport.GetFreePort() if err != nil { log.Fatal(err) } // port is ready to listen on } ``` -------------------------------- ### Install Gonum LAPACK Packages Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/gonum.org/v1/gonum/lapack/README.md Use this command to install all Gonum LAPACK packages. Ensure you have Go installed and configured. ```bash go get gonum.org/v1/gonum/lapack/... ``` -------------------------------- ### ImageRoot Configuration Example Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci/vendor/custom-repo-custom-version/charts/common/README.md An example configuration for the ImageRoot section, specifying registry, repository, tag, pull policy, and debug settings. ```yaml registry: docker.io repository: bitnami/nginx tag: 1.16.1-debian-10-r63 pullPolicy: IfNotPresent debug: false ``` -------------------------------- ### Credential Helper Configuration Example Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/google/go-containerregistry/pkg/authn/README.md Modify your configuration file to use custom credential helpers. This example maps 'gcr.io' to the 'tee' helper and 'eu.gcr.io' to the 'hardcoded' helper. ```json { "credHelpers": { "gcr.io": "tee", "eu.gcr.io": "hardcoded" } } ``` -------------------------------- ### Helm Validation NOTES.txt Example Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci/vendor/custom-repo-custom-version/charts/common/README.md A NOTES.txt example demonstrating how to use common.validations.values.multiple.empty to enforce non-empty values, with corresponding command-line overrides. ```yaml {{- $validateValueConf00 := (dict "valueKey" "path.to.value00" "secret" "secretName" "field" "password-00") -}} {{- $validateValueConf01 := (dict "valueKey" "path.to.value01" "secret" "secretName" "field" "password-01") -}} {{ include "common.validations.values.multiple.empty" (dict "required" (list $validateValueConf00 $validateValueConf01) "context" $) }} ``` ```console $ helm install test mychart --set path.to.value00="",path.to.value01="" 'path.to.value00' must not be empty, please add '--set path.to.value00=$PASSWORD_00' to the command. To get the current value: export PASSWORD_00=$(kubectl get secret --namespace default secretName -o jsonpath="{.data.password-00}" | base64 --decode) 'path.to.value01' must not be empty, please add '--set path.to.value01=$PASSWORD_01' to the command. To get the current value: export PASSWORD_01=$(kubectl get secret --namespace default secretName -o jsonpath="{.data.password-01}" | base64 --decode) ``` -------------------------------- ### Install Bats Core Source: https://github.com/carvel-dev/vendir/blob/develop/examples/image/vendor/docker.io/dkalinin/consul-helm-by-tag/README.md Installs the Bats-core testing framework using Homebrew. This is a prerequisite for running unit and acceptance tests. ```bash brew install bats-core ``` -------------------------------- ### Install yq Source: https://github.com/carvel-dev/vendir/blob/develop/examples/image/vendor/docker.io/dkalinin/consul-helm-by-tag/README.md Installs the yq tool using Homebrew, which is a prerequisite for running tests. yq is used for processing YAML files. ```bash brew install python-yq ``` -------------------------------- ### Persistence Configuration Example Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci-dependencies/vendor/custom-repo-custom-version/charts/contour/charts/common/README.md Configures persistent storage for a deployment, including storage class, access mode, size, and path. ```yaml enabled: type: boolean description: Whether enable persistence. example: true storageClass: type: string description: Ghost data Persistent Volume Storage Class, If set to "-", storageClassName: "" which disables dynamic provisioning. example: "-" accessMode: type: string description: Access mode for the Persistent Volume Storage. example: ReadWriteOnce size: type: string description: Size the Persistent Volume Storage. example: 8Gi path: type: string description: Path to be persisted. example: /bitnami ## An instance would be: # enabled: true # storageClass: "-" # accessMode: ReadWriteOnce # size: 8Gi # path: /bitnami ``` -------------------------------- ### Install Consul Helm Chart Source: https://github.com/carvel-dev/vendir/blob/develop/examples/image/vendor/docker.io/dkalinin/consul-helm-by-tag/README.md Installs the Consul Helm chart directly from a local directory. Ensure the repository is downloaded and unpacked. ```bash helm install ./consul-helm ``` -------------------------------- ### ExistingSecret Configuration Example Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci/vendor/custom-repo-custom-version/charts/common/README.md An example configuration for the ExistingSecret section, showing how to reference an existing secret and map its keys. ```yaml name: mySecret keyMapping: password: myPasswordKey ``` -------------------------------- ### ImageRoot Configuration Example Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci-dependencies/vendor/custom-repo-custom-version/charts/contour/charts/common/README.md Defines parameters for specifying a Docker image, including registry, repository, tag, and pull policy. ```yaml registry: type: string description: Docker registry where the image is located example: docker.io repository: type: string description: Repository and image name example: bitnami/nginx tag: type: string description: image tag example: 1.16.1-debian-10-r63 pullPolicy: type: string description: Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' pullSecrets: type: array items: type: string description: Optionally specify an array of imagePullSecrets (evaluated as templates). debug: type: boolean description: Set to true if you would like to see extra information on logs example: false ## An instance would be: # registry: docker.io # repository: bitnami/nginx # tag: 1.16.1-debian-10-r63 # pullPolicy: IfNotPresent # debug: false ``` -------------------------------- ### Install Contour Helm Chart Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci-dependencies/vendor/custom-repo-custom-version/charts/contour/README.md Add the Bitnami Helm repository and install the Contour chart with a release name. This deploys the Contour Ingress Controller and Envoy Proxy. ```bash helm repo add bitnami https://charts.bitnami.com/bitnami helm install my-release bitnami/contour ``` -------------------------------- ### Create Root Logger Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/go-logr/logr/README.md Demonstrates how to create the initial 'root' logger in an application's main function, choosing a specific logging implementation. ```go func main() { // ... other setup code ... // Create the "root" logger. We have chosen the "logimpl" implementation, // which takes some initial parameters and returns a logr.Logger. logger := logimpl.New(param1, param2) // ... other setup code ... ``` -------------------------------- ### URL Path Preparation Example Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/Azure/go-autorest/README.md Illustrates how multiple WithPath decorators can be used to sequentially build a URL path during request preparation. The final URL will be a concatenation of the base URL and all provided path segments. ```go req, err := Prepare(&http.Request{}, \ WithBaseURL("https://microsoft.com/"), \ WithPath("a"), \ WithPath("b"), \ WithPath("c")) ``` -------------------------------- ### Set Helm Chart Parameters Source: https://github.com/carvel-dev/vendir/blob/develop/examples/helm-chart-oci-dependencies/vendor/custom-repo-custom-version/charts/contour/README.md Use the `--set` argument with `helm install` to configure chart parameters. This example shows how to set a specific readiness probe threshold for the Envoy proxy. ```bash helm install my-release \ --set envoy.readinessProbe.successThreshold=5 \ bitnami/contour ``` -------------------------------- ### Coexist with glog Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/k8s.io/klog/v2/README.md Example demonstrating how to initialize and synchronize flags between klog/v2 and glog. It also shows how to use stderr for combined output by setting alsologtostderr or logtostderr to true. ```go package main import ( "flag" "os" "k8s.io/klog/v2" ) func main() { // Initialize klog flags klog.InitFlags(nil) // Initialize glog flags (if used) // Note: This is just an example, actual glog flag initialization might differ // depending on how glog is integrated. // glog.InitFlags(nil) // Set alsologtostderr to true to redirect logs to stderr flag.Set("alsologtostderr", "true") // Parse flags flag.Parse() // Ensure flags are synced if necessary (e.g., for glog) // klog.Flush() // klog flushes automatically on exit, but explicit flush can be used. // Example logging klog.Info("This is an info message from klog") // Ensure logs are written before exiting defer klog.Flush() // Example of using stderr directly if needed os.Stderr.Write([]byte("This is a direct stderr message\n")) } ``` -------------------------------- ### Deploy Simple App with Kapp Source: https://github.com/carvel-dev/vendir/blob/develop/examples/http/vendor/k8s-simple-app-digested/k8s-simple-app-example-master/README.md Deploys the simple application using kapp. Use `kapp inspect` to view the deployment tree and `kapp logs` to follow application logs. ```bash kapp deploy -a simple-app -f config-step-1-minimal/ kapp inspect -a simple-app --tree kapp logs -f -a simple-app ``` -------------------------------- ### Install Gonum BLAS Packages Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/gonum.org/v1/gonum/blas/README.md Use this command to install all Gonum BLAS packages. ```sh go get gonum.org/v1/gonum/blas/... ``` -------------------------------- ### Install FreePort on Ubuntu/DEB Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/phayes/freeport/README.md Download and install the FreePort DEB package on Ubuntu and other Debian-based Linux distributions. ```bash wget wget https://github.com/phayes/freeport/releases/download/1.0.2/freeport_1.0.2_linux_amd64.deb dpkg -i freeport_1.0.2_linux_amd64.deb ``` -------------------------------- ### Install FreePort on CentOS/RPM Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/phayes/freeport/README.md Download and install the FreePort RPM package on CentOS and other RPM-based Linux distributions. ```bash wget https://github.com/phayes/freeport/releases/download/1.0.2/freeport_1.0.2_linux_386.rpm rpm -Uvh freeport_1.0.2_linux_386.rpm ``` -------------------------------- ### Show Build Commands (Old System) Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/golang.org/x/sys/unix/README.md Displays the commands that will be run by `mkall.sh` without executing them. Useful for understanding the build process. Requires bash and go. ```bash mkall.sh -n ``` -------------------------------- ### Install FreePort via Homebrew Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/phayes/freeport/README.md Install the FreePort utility on macOS using the Homebrew package manager. ```bash brew install phayes/repo/freeport ``` -------------------------------- ### Install Cobra CLI Generator Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/spf13/cobra/README.md Install the cobra-cli command line program to generate Cobra application scaffolding. ```bash go install github.com/spf13/cobra-cli@latest ``` -------------------------------- ### Install Helm Source: https://github.com/carvel-dev/vendir/blob/develop/examples/image/vendor/docker.io/dkalinin/consul-helm-by-tag/README.md Installs the Helm package manager using Homebrew. Helm is required for deploying the Consul chart and running tests. ```bash brew install kubernetes-helm ``` -------------------------------- ### EWMA Usage Example Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/VividCortex/ewma/README.md Demonstrates how to create and use both SimpleEWMA and VariableEWMA instances. SimpleEWMA is created with no arguments, while VariableEWMA requires an 'age' parameter. ```go package main import "github.com/VividCortex/ewma" func main() { samples := [100]float64{ 4599, 5711, 4746, 4621, 5037, 4218, 4925, 4281, 5207, 5203, 5594, 5149, } e := ewma.NewMovingAverage() //=> Returns a SimpleEWMA if called without params a := ewma.NewMovingAverage(5) //=> returns a VariableEWMA with a decay of 2 / (5 + 1) for _, f := range samples { e.Add(f) a.Add(f) } e.Value() //=> 13.577404704631077 a.Value() //=> 1.5806140565521463e-12 } ``` -------------------------------- ### Build All Files (Old System) Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/golang.org/x/sys/unix/README.md Generates Go files for the current OS and architecture using the old build system. Ensure GOOS and GOARCH are set correctly. Requires bash and go. ```bash mkall.sh ``` -------------------------------- ### glog Fatal Log Example Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/k8s.io/klog/README.md Shows how to use glog.Fatalf to log an error message and terminate the program. Use this for critical failures. ```go glog.Fatalf("Initialization failed: %s", err) ``` -------------------------------- ### Upload Stdin as a Layer to a Local Registry Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/google/go-containerregistry/pkg/v1/stream/README.md This example demonstrates how to upload the contents of standard input as a layer to a local registry. It uses stream.NewLayer to create a streaming layer from os.Stdin and remote.WriteLayer to upload it. ```go package main import ( "os" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/stream" ) // upload the contents of stdin as a layer to a local registry func main() { repo, err := name.NewRepository("localhost:5000/stream") if err != nil { panic(err) } layer := stream.NewLayer(os.Stdin) if err := remote.WriteLayer(repo, layer); err != nil { panic(err) } } ``` -------------------------------- ### Build and Sign JWT with HMAC Source: https://github.com/carvel-dev/vendir/blob/develop/vendor/github.com/form3tech-oss/jwt-go/README.md Example of building and signing a JWT using HMAC. This demonstrates creating a new token with specific claims and signing it. ```go package main import ( "fmt" "github.com/dgrijalva/jwt-go" "time" ) func main() { // Create a new token object, specifying the signing method and the claims token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ "name": "John Doe", "nbf": time.Now().Unix(), "exp": time.Now().Add(time.Hour * 1).Unix(), // Expires in 1 hour "iat": time.Now().Unix(), }) // Sign the token with a secret key. tokenString, err := token.SignedString([]byte("your_secret_key")) if err != nil { panic(err) } fmt.Println(tokenString) } ```