mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-19 18:07:45 +08:00

Tested with `kind` and GKE. Note: "nodes" shown in `docker buildx ls` are unrelated to Kubernetes "nodes". Probably buildx should come up with an alternative term. Usage: $ kind create cluster $ export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" $ docker buildx create --driver kubernetes --driver-opt replicas=3 --use $ docker buildx build -t foo --load . `--load` loads the image into the local Docker. Driver opts: - `image=IMAGE` - Sets the container image to be used for running buildkit. - `namespace=NS` - Sets the Kubernetes namespace. Defaults to the current namespace. - `replicas=N` - Sets the number of `Pod` replicas. Defaults to 1. - `rootless=(true|false)` - Run the container as a non-root user without `securityContext.privileged`. Defaults to false. - `loadbalance=(sticky|random)` - Load-balancing strategy. If set to "sticky", the pod is chosen using the hash of the context path. Defaults to "sticky" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
// Copyright 2014 Google Inc. All rights reserved.
|
|
// Use of this source code is governed by the Apache 2.0
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package internal
|
|
|
|
// This file has code for accessing metadata.
|
|
//
|
|
// References:
|
|
// https://cloud.google.com/compute/docs/metadata
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
const (
|
|
metadataHost = "metadata"
|
|
metadataPath = "/computeMetadata/v1/"
|
|
)
|
|
|
|
var (
|
|
metadataRequestHeaders = http.Header{
|
|
"Metadata-Flavor": []string{"Google"},
|
|
}
|
|
)
|
|
|
|
// TODO(dsymonds): Do we need to support default values, like Python?
|
|
func mustGetMetadata(key string) []byte {
|
|
b, err := getMetadata(key)
|
|
if err != nil {
|
|
log.Fatalf("Metadata fetch failed: %v", err)
|
|
}
|
|
return b
|
|
}
|
|
|
|
func getMetadata(key string) ([]byte, error) {
|
|
// TODO(dsymonds): May need to use url.Parse to support keys with query args.
|
|
req := &http.Request{
|
|
Method: "GET",
|
|
URL: &url.URL{
|
|
Scheme: "http",
|
|
Host: metadataHost,
|
|
Path: metadataPath + key,
|
|
},
|
|
Header: metadataRequestHeaders,
|
|
Host: metadataHost,
|
|
}
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != 200 {
|
|
return nil, fmt.Errorf("metadata server returned HTTP %d", resp.StatusCode)
|
|
}
|
|
return ioutil.ReadAll(resp.Body)
|
|
}
|