pkg: Remove metadata-gcp

It's no longer used

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-04-12 14:56:50 +01:00
parent 27a3eee6dc
commit 432bdda272
4 changed files with 0 additions and 126 deletions

View File

@ -1,4 +0,0 @@
dev
proc
sys
usr

View File

@ -1,3 +0,0 @@
FROM scratch
COPY . ./
CMD ["/usr/bin/metadata-gcp"]

View File

@ -1,44 +0,0 @@
GO_COMPILE=mobylinux/go-compile:3afebc59c5cde31024493c3f91e6102d584a30b9@sha256:e0786141ea7df8ba5735b63f2a24b4ade9eae5a02b0e04c4fca33b425ec69b0a
SHA_IMAGE=alpine:3.5@sha256:dfbd4a3a8ebca874ebd2474f044a0b33600d4523d03b0df76e5c5986cb02d7e8
METADATA_BINARY=usr/bin/metadata-gcp
IMAGE=metadata-gcp
.PHONY: tag push clean container
default: push
$(METADATA_BINARY): gcp.go
mkdir -p $(dir $@)
tar cf - $^ | docker run --rm --net=none --log-driver=none -i $(GO_COMPILE) -o $@ | tar xf -
DIRS=dev proc sys
$(DIRS):
mkdir -p $@
DEPS=$(DIRS) $(METADATA_BINARY)
container: Dockerfile $(DEPS)
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
hash: Dockerfile $(DEPS)
find $^ -type f | xargs cat | docker run --rm -i $(SHA_IMAGE) sha1sum - | sed 's/ .*//' > hash
push: hash container
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
docker push mobylinux/$(IMAGE):$(shell cat hash))
docker rmi $(IMAGE):build
rm -f hash
tag: hash container
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
docker rmi $(IMAGE):build
rm -f hash
clean:
rm -rf hash $(DIRS) usr
.DELETE_ON_ERROR:

View File

@ -1,75 +0,0 @@
package main
import (
"io/ioutil"
"log"
"net/http"
"strings"
"syscall"
"time"
)
const (
project = "http://metadata.google.internal/computeMetadata/v1/project/"
instance = "http://metadata.google.internal/computeMetadata/v1/instance/"
)
// If optional not set, will panic. Optional will allow 404
// We assume most failure cases are that this code is included in a non Google Cloud
// environment, which should generally be ok, so just fail fast.
func metadata(url string, optional bool) []byte {
var client = &http.Client{
Timeout: time.Second * 2,
}
req, err := http.NewRequest("", url, nil)
if err != nil {
log.Fatalf("http NewRequest failed: %v", err)
}
req.Header.Set("Metadata-Flavor", "Google")
resp, err := client.Do(req)
if err != nil {
// Probably not running on Google Cloud but this package included
log.Fatalf("Could not contact Google Cloud Metadata service: %v", err)
}
if optional && resp.StatusCode == 404 {
return []byte{}
}
if resp.StatusCode != 200 {
// Probably not running on Google Cloud but this package included
log.Fatalf("Google Cloud Metadata Server http error: %s", resp.Status)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Failed to read http response: %v", err)
}
return body
}
func main() {
hostname := metadata(instance+"hostname", false)
err := syscall.Sethostname(hostname)
if err != nil {
log.Printf("Failed to set hostname: %v", err)
}
sshKeys := metadata(project+"attributes/sshKeys", true)
// TODO also retrieve the instance keys and respect block project keys see https://cloud.google.com/compute/docs/instances/ssh-keys
// the keys have usernames attached, but as a simplification we are going to add them all to one root file
// TODO split them into individual user files and make the ssh container construct those users
rootKeys := ""
for _, line := range strings.Split(string(sshKeys), "\n") {
parts := strings.SplitN(line, ":", 2)
// ignoring username for now
if len(parts) == 2 {
rootKeys = rootKeys + parts[1] + "\n"
}
}
err = ioutil.WriteFile("/etc/ssh/authorized_keys", []byte(rootKeys), 0600)
if err != nil {
log.Printf("Failed to write ssh keys: %v", err)
}
}