This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nicolas Degory <ndegory@axway.com>
- Loading branch information
Showing
7 changed files
with
832 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
InfraKit Instance Plugin - Docker | ||
================================= | ||
|
||
[InfraKit](https://github.com/docker/infrakit) plugins for creating and managing Docker containers. | ||
|
||
## Instance plugin | ||
|
||
The InfraKit instance plugin creates and monitors Docker containers. | ||
|
||
### Example | ||
|
||
Based on the [default](https://github.com/docker/infrakit/tree/master/cmd/group) Group | ||
plugin: | ||
```console | ||
$ build/infrakit-group-default | ||
INFO[0000] Starting discovery | ||
INFO[0000] Starting plugin | ||
INFO[0000] Starting | ||
INFO[0000] Listening on: unix:///run/infrakit/plugins/group.sock | ||
INFO[0000] listener protocol= unix addr= /run/infrakit/plugins/group.sock err= <nil> | ||
``` | ||
|
||
and the [Vanilla](https://github.com/docker/infrakit/tree/master/pkg/example/flavor/vanilla) Flavor plugin: | ||
```console | ||
$ build/infrakit-flavor-vanilla | ||
INFO[0000] Starting plugin | ||
INFO[0000] Listening on: unix:///run/infrakit/plugins/flavor-vanilla.sock | ||
INFO[0000] listener protocol= unix addr= /run/infrakit/plugins/flavor-vanilla.sock err= <nil> | ||
``` | ||
|
||
We will use a basic configuration that creates a single instance: | ||
```console | ||
$ cat << EOF > aws-vanilla.json | ||
{ | ||
"ID": "docker-example", | ||
"Properties": { | ||
"Allocation": { | ||
"Size": 1 | ||
}, | ||
"Instance": { | ||
"Plugin": "instance-docker", | ||
"Properties": { | ||
"Config": { | ||
"Image": "alpine:3.5" | ||
}, | ||
"HostConfig": { | ||
"AutoRemove": true | ||
}, | ||
"Tags": { | ||
"Name": "infrakit-example" | ||
} | ||
} | ||
}, | ||
"Flavor": { | ||
"Plugin": "flavor-vanilla", | ||
"Properties": { | ||
"Init": [ | ||
"sh -c \"echo 'Hello, World!' > /hello\"" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
EOF | ||
``` | ||
|
||
For the structure of `Config` `HostConfig`, see the plugin properties definition below. | ||
|
||
Finally, instruct the Group plugin to start watching the group: | ||
```console | ||
$ build/infrakit group watch docker-vanilla.json | ||
watching docker-example | ||
``` | ||
|
||
In the console running the Group plugin, we will see input like the following: | ||
``` | ||
INFO[1208] Watching group 'docker-example' | ||
INFO[1219] Adding 1 instances to group to reach desired 1 | ||
INFO[1219] Created instance i-ba0412a2 with tags map[infrakit.config_sha:dUBtWGmkptbGg29ecBgv1VJYzys= infrakit.group:aws-example] | ||
``` | ||
|
||
Additionally, the CLI will report the newly-created instance: | ||
```console | ||
$ build/infrakit group inspect docker-example | ||
ID LOGICAL TAGS | ||
90e6f3de4918 elusive_leaky Name=infrakit-example,infrakit.config_sha=dUBtWGmkptbGg29ecBgv1VJYzys=,infrakit.group=docker-example | ||
``` | ||
|
||
Retrieve the name of the container and connect to it with an exec | ||
|
||
```console | ||
$ docker exec -ti elusive_leaky cat /hello | ||
Hello, World! | ||
``` | ||
|
||
### Plugin properties | ||
|
||
The plugin expects properties in the following format: | ||
```json | ||
{ | ||
"Tags": { | ||
}, | ||
"Config": { | ||
}, | ||
"HostConfig": { | ||
}, | ||
"NetworkAttachments": [ | ||
] | ||
} | ||
``` | ||
|
||
The `Tags` property is a string-string mapping of labels to apply to all Docker containers that are created. | ||
`Config` follows the structure of the type by the same name in the | ||
[Docker go SDK](https://github.com/docker/docker/blob/master/api/types/container/config.go). | ||
`HostConfig` follows the structure of the type by the same name in the | ||
[Docker go SDK](https://github.com/docker/docker/blob/master/api/types/container/host_config.go). | ||
`NetworkAttachments` is an array of [NetworkResource](https://github.com/docker/docker/blob/master/api/types/types.go). | ||
|
||
### LogicalID | ||
|
||
To take advantage of the Docker networking DNS, the InfraKit logicalID is mapped to the Docker container hostname (and not its IP). | ||
The plugin is compatible with both allocation methods, logical IDs (cattles) or group size (pets). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/docker/docker/client" | ||
"github.com/docker/infrakit/pkg/spi/instance" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
const ( | ||
defaultDockerURL = "unix:///var/run/docker.sock" | ||
defaultDockerAPIVersion = "1.25" | ||
) | ||
|
||
type options struct { | ||
dockerURL string | ||
dockerAPIVersion string | ||
//todo: add TLS options | ||
retries int | ||
} | ||
|
||
// Builder is a ProvisionerBuilder that creates a Docker instance provisioner | ||
type Builder struct { | ||
client *client.Client | ||
options options | ||
} | ||
|
||
// Flags returns the flags required. | ||
func (b *Builder) Flags() *pflag.FlagSet { | ||
flags := pflag.NewFlagSet("docker", pflag.PanicOnError) | ||
flags.StringVar(&b.options.dockerURL, "url", defaultDockerURL, "Docker API URL") | ||
flags.StringVar(&b.options.dockerAPIVersion, "version", defaultDockerAPIVersion, "Docker API version") | ||
flags.IntVar(&b.options.retries, "retries", 5, "Number of retries for Docker API operations") | ||
return flags | ||
} | ||
|
||
// BuildInstancePlugin creates an instance Provisioner configured with the Flags. | ||
func (b *Builder) BuildInstancePlugin(namespaceTags map[string]string) (instance.Plugin, error) { | ||
if b.client == nil { | ||
defaultHeaders := map[string]string{"User-Agent": "InfraKit"} | ||
cli, err := client.NewClient(b.options.dockerURL, b.options.dockerAPIVersion, nil, defaultHeaders) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to connect to Docker on [%s]\n%v", b.options.dockerURL, err) | ||
} | ||
b.client = cli | ||
} | ||
return NewInstancePlugin(b.client, namespaceTags), nil | ||
} | ||
|
||
type logger struct { | ||
logger *log.Logger | ||
} | ||
|
||
func (l logger) Log(args ...interface{}) { | ||
l.logger.Println(args...) | ||
} |
Oops, something went wrong.