Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ REVISION?=$(shell git rev-list -1 HEAD)
# Docker client API version. Change this to be consistent with the version of the vendored sources you use.
DOCKER_CLIENT_VERSION?=1.24

# True to run e2e test
E2E_TESTS?=true

# Allow turning off function inlining and variable registerization
ifeq (${DISABLE_OPTIMIZATION},true)
GO_GCFLAGS=-gcflags "-N -l"
Expand Down Expand Up @@ -50,8 +53,10 @@ build-docker:
@docker build ${DOCKER_BUILD_FLAGS} \
-t ${DOCKER_IMAGE}:${DOCKER_TAG} \
-f ${CURDIR}/dockerfiles/Dockerfile.bundle .
ifeq (${E2E_TESTS},true)
@echo "Running tests -- scripts/e2e-test-docker-containers.sh to verify the binaries"
@scripts/e2e-test-docker-containers.sh
endif
ifeq (${DOCKER_PUSH},true)
@docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
ifeq (${DOCKER_TAG_LATEST},true)
Expand Down Expand Up @@ -197,7 +202,11 @@ coverage:

e2e-test: binaries
@echo "+ $@"
./scripts/e2e-test.sh
ifeq (${E2E_TESTS},true)
@echo "Running tests -- scripts/e2e-test.sh to verify the binaries"
@./scripts/e2e-test.sh
endif


test-full:
@echo "+ $@"
Expand Down
72 changes: 56 additions & 16 deletions cmd/infrakit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/docker/infrakit/cmd/infrakit/base"
Expand All @@ -14,6 +16,7 @@ import (
discovery_local "github.com/docker/infrakit/pkg/discovery/local"
"github.com/docker/infrakit/pkg/discovery/remote"
logutil "github.com/docker/infrakit/pkg/log"
"github.com/docker/infrakit/pkg/types"
"github.com/spf13/cobra"

_ "github.com/docker/infrakit/cmd/infrakit/event"
Expand Down Expand Up @@ -58,31 +61,67 @@ func main() {

cmd.PersistentFlags().AddFlagSet(cli.Flags(logOptions))
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)

cmd.PersistentFlags().StringSliceVarP(&remotes, "host", "H", remotes, "host list. Default is local sockets")

// parse the list of hosts
cmd.PersistentPreRunE = func(c *cobra.Command, args []string) error {
logutil.Configure(logOptions)

hosts := []string{}

if len(remotes) > 0 {
for _, h := range remotes {
addProtocol := false
if !strings.Contains(h, "://") {
h = "http://" + h
addProtocol = true
}
u, err := url.Parse(h)
if err != nil {
return err
}
if addProtocol {
u.Scheme = "http"
}

ulist = append(ulist, u)

// The command line flag wins.
hosts = remotes

} else {

// If not -- see if INFRAKIT_HOST is set to point to a host list in the $INFRAKIT_HOME/hosts file.
host := os.Getenv("INFRAKIT_HOST")
if host == "" {
return nil // do nothing -- local mode
}

// Now look up the host lists in the file
hostsFile := filepath.Join(os.Getenv("INFRAKIT_HOME"), "hosts")
buff, err := ioutil.ReadFile(hostsFile)
if err != nil {
return fmt.Errorf("cannot read hosts file at %s for INFRAKIT_HOST=%s, err=%v", hostsFile, host, err)
}
m := map[string]string{}
yaml, err := types.AnyYAML(buff)
if err != nil {
return fmt.Errorf("bad format for hosts file at %s for INFRAKIT_HOST=%s, err=%v", hostsFile, host, err)

}
err = yaml.Decode(&m)
if err != nil {
return fmt.Errorf("cannot decode hosts file at %s for INFRAKIT_HOST=%s, err=%v", hostsFile, host, err)
}

if list, has := m[host]; has {
hosts = strings.Split(list, ",")
} else {
return fmt.Errorf("no entry in hosts file at %s for INFRAKIT_HOST=%s", hostsFile, host)
}
}

for _, h := range hosts {
addProtocol := false
if !strings.Contains(h, "://") {
h = "http://" + h
addProtocol = true
}
u, err := url.Parse(h)
if err != nil {
return err
}
if addProtocol {
u.Scheme = "http"
}

ulist = append(ulist, u)
}
return nil
}

Expand All @@ -94,6 +133,7 @@ func main() {
// They are returned from cmd.Execute() below and we print it ourselves.
cmd.SilenceErrors = true
f := func() discovery.Plugins {

if len(ulist) == 0 {
d, err := discovery_local.NewPluginDiscovery()
if err != nil {
Expand Down
26 changes: 25 additions & 1 deletion cmd/infrakit/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
typeMap, err := hs.Types()
if err != nil {
log.Warn("cannot get types for this kind", "err", err, "addr", entry.Address)

// plugins that haven't been updated to the new types() call

// try the implements
if spis, err := hs.Implements(); err == nil {
for _, spi := range spis {
ep := ep{
name: major,
listen: entry.Address,
spi: rpc.InterfaceSpec(fmt.Sprintf("%s/%s", spi.Name, spi.Version)),
}

key := fmt.Sprintf("%s:%s", ep.name, ep.spi)
view[key] = ep
keys = append(keys, key)
}
} else {
ep := ep{
name: major,
listen: entry.Address,
}
view[ep.name] = ep
keys = append(keys, ep.name)
}
continue
}

Expand Down Expand Up @@ -98,7 +122,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
}

if !*quiet {
fmt.Printf("%-20s\t%-50s\t%-s\n", "NAME", "LISTEN", "INTERFACES")
fmt.Printf("%-20s\t%-50s\t%-s\n", "NAME", "LISTEN", "INTERFACE")
}

sort.Strings(keys)
Expand Down
5 changes: 5 additions & 0 deletions docs/playbooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ In your terminal, or add this to your `.bash_profile`:
```shell
export INFRAKIT_HOME=~/.infrakit
```
If you're on the Mac, also

```shell
export INFRAKIT_HOST=localhost
```

## Add a Playbook

Expand Down
6 changes: 6 additions & 0 deletions docs/playbooks/linuxkit/start-infrakit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ docker run -d --volumes-from infrakit --name manager \
{{ source "start-instance-hyperkit.sh" }}

{{ source "start-instance-gcp.sh" }}

echo "Updating hosts file"
{{ $hostsFile := list (env `INFRAKIT_HOME`) `/hosts` | join `` }}
{{ $hosts := include (list `file://` $hostsFile | join ``) | yamlDecode }}
{{ $_ := set $hosts `localhost` (list `localhost` $port | join `:`) }}
echo "{{ $hosts | yamlEncode }}" > {{ $hostsFile }}
3 changes: 0 additions & 3 deletions docs/playbooks/linuxkit/start-instance-hyperkit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ echo "This plugin is listening at localhost:24865"

infrakit-instance-hyperkit --log 5 > {{env `INFRAKIT_HOME`}}/logs/instance-hyperkit.log 2>&1 &

# hack to make this work with Docker4Mac -- if connecting locally on the host
echo "tcp://localhost:24865" > {{ env `INFRAKIT_HOME`}}/plugins/instance-hyperkit-local.listen

{{ end }}
2 changes: 0 additions & 2 deletions docs/playbooks/linuxkit/stop-infrakit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ echo "Stopping local hyperkit plugin"
export INFRAKIT_HOME={{ env `INFRAKIT_HOME` }}
infrakit plugin stop --all

rm -f $INFRAKIT_HOME/plugins/instance-hyperkit-local.listen

{{ else }}

echo "Not stopping Infrakit"
Expand Down
1 change: 1 addition & 0 deletions scripts/e2e-test-docker-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ expect_output_lines() {
fi
}

ls $TEST_DIR/plugins
expect_output_lines "16 plugins should be discoverable" "run infrakit plugin ls -q" "16"

expect_output_lines "0 instances should exist" "run infrakit instance describe -q --name instance-file" "0"
Expand Down
13 changes: 12 additions & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ github.com/golang/protobuf/jsonpb 4bd1920723d7b7c925de087a
github.com/golang/protobuf/proto 4bd1920723d7b7c925de087aa32e2187708897f7
github.com/gorilla/mux 757bef9
github.com/gorilla/rpc 22c016f
github.com/graymeta/stow 0f16e17
github.com/graymeta/stow 0f16e170afc5e1b89434469a3b52a81f792c9038
github.com/grpc-ecosystem/go-grpc-prometheus v1.1
github.com/grpc-ecosystem/grpc-gateway/runtime 84398b94e188ee336f307779b57b3aa91af7063c
github.com/grpc-ecosystem/grpc-gateway/utilities 84398b94e188ee336f307779b57b3aa91af7063c
Expand Down Expand Up @@ -96,3 +96,14 @@ gopkg.in/mgo.v2/bson 3f83fa5
gopkg.in/mgo.v2/internal 3f83fa5
gopkg.in/tylerb/graceful.v1 v1.2.13
gopkg.in/yaml.v2 a5b47d3
cloud.google.com/go/compute/metadata 3c8d908
github.com/aws/aws-sdk-go/private/protocol 19c3b41
github.com/aws/aws-sdk-go/private/protocol/rest 19c3b41
github.com/aws/aws-sdk-go/private/protocol/restxml 19c3b41
github.com/aws/aws-sdk-go/service/sts 19c3b41
github.com/go-ini/ini e7fea39
golang.org/x/oauth2 a6bd8ce
golang.org/x/oauth2/jws a6bd8ce
golang.org/x/oauth2/jwt a6bd8ce
google.golang.org/api/gensupport d48d03b
google.golang.org/api/googleapi d48d03b
Loading