Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit f91cf9f

Browse files
committed
Merge branch 'master' into integration-test
2 parents 0158453 + d0cbee8 commit f91cf9f

File tree

9 files changed

+80
-18
lines changed

9 files changed

+80
-18
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ matrix:
88
- go: 1.5
99

1010
script:
11-
- ./build-hyperserve-client.sh
11+
- ./build.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ $ mkdir $GOPATH/src/github.com/hyperhq/
88
$ cd $GOPATH/src/github.com/hyperhq/
99
$ git clone https://github.com/hyperhq/hypercli hypercli
1010
$ cd hypercli
11-
$ ./build-hyperserve-client.sh
11+
$ ./build.sh
1212
```

api/client/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (cli *DockerCli) WaitExec(execID string) error {
198198
case running:
199199
time.Sleep(100 * time.Millisecond)
200200
case status != 0:
201-
err = fmt.Errorf("Failed to init volume: %d", status)
201+
err = fmt.Errorf("Failed to exec cmd: %d", status)
202202
return err
203203
case status == 0:
204204
return nil

api/client/fip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func fipUsage() string {
146146
fipCommands := map[string]string{
147147
"allocate": "Allocate a or some IPs",
148148
"associate": "Associate floating IP to container",
149-
"disassociate": "Disassociate floating IP from conainer",
149+
"disassociate": "Disassociate floating IP from container",
150150
"ls": "List all floating IPs",
151151
"release": "Release a floating IP",
152152
}

api/client/kill.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
1414
func (cli *DockerCli) CmdKill(args ...string) error {
1515
cmd := Cli.Subcmd("kill", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["kill"].Description, true)
16-
signal := cmd.String([]string{}, "KILL", "Signal to send to the container")
16+
signal := cmd.String([]string{"s", "-signal"}, "KILL", "Signal to send to the container")
1717
cmd.Require(flag.Min, 1)
1818

1919
cmd.ParseFlags(args, true)

api/client/run.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ func checkSourceType(source string) string {
118118

119119
func (cli *DockerCli) initSpecialVolumes(config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, initvols []*InitVolume) error {
120120
const INIT_VOLUME_PATH = "/vol/"
121-
const INIT_VOLUME_IMAGE = "hyperhq/volume_uploader:latest"
121+
const INIT_VOLUME_IMAGE = "hyperhq/volume_uploader:v1"
122+
const INIT_VOLUME_FILENAME = ".hyper_file_volume_data_do_not_create_on_your_own"
122123
var (
123124
initConfig *container.Config
124125
initHostConfig *container.HostConfig
@@ -176,9 +177,21 @@ func (cli *DockerCli) initSpecialVolumes(config *container.Config, hostConfig *c
176177
case "git":
177178
cmd = append(cmd, "git", "clone", vol.Source, INIT_VOLUME_PATH+vol.Destination)
178179
case "http":
180+
isFile, err := fileSourceVolume(vol.Source)
181+
if err != nil {
182+
return err
183+
}
179184
parts := strings.Split(vol.Source, "/")
180-
cmd = append(cmd, "wget", "--no-check-certificate", "--tries=5", "--mirror", "--no-host-directories", "--cut-dirs="+strconv.Itoa(len(parts)), vol.Source, "--directory-prefix="+INIT_VOLUME_PATH+vol.Destination)
185+
if isFile {
186+
cmd = append(cmd, "wget", "--no-check-certificate", "--tries=5", vol.Source, "--output-document="+INIT_VOLUME_PATH+vol.Destination+"/"+INIT_VOLUME_FILENAME)
187+
} else {
188+
cmd = append(cmd, "wget", "--no-check-certificate", "--tries=5", "--mirror", "--no-host-directories", "--cut-dirs="+strconv.Itoa(len(parts)), vol.Source, "--directory-prefix="+INIT_VOLUME_PATH+vol.Destination)
189+
}
181190
case "local":
191+
isFile, err := fileSourceVolume(vol.Source)
192+
if err != nil {
193+
return err
194+
}
182195
execCount++
183196
if fip == "" {
184197
fip, err = cli.associateNewFip(createResponse.ID)
@@ -187,7 +200,11 @@ func (cli *DockerCli) initSpecialVolumes(config *container.Config, hostConfig *c
187200
}
188201
}
189202
go func(vol *InitVolume) {
190-
err := cli.uploadLocalResource(vol.Source, INIT_VOLUME_PATH+vol.Destination, fip, "root", passwd.String())
203+
dest := INIT_VOLUME_PATH + vol.Destination
204+
if isFile {
205+
dest = dest + "/" + INIT_VOLUME_FILENAME
206+
}
207+
err := cli.uploadLocalResource(vol.Source, dest, fip, "root", passwd.String(), isFile)
191208
if err != nil {
192209
err = fmt.Errorf("Failed to upload %s: %s", vol.Source, err.Error())
193210
}
@@ -245,6 +262,38 @@ func (cli *DockerCli) initSpecialVolumes(config *container.Config, hostConfig *c
245262
return nil
246263
}
247264

265+
func fileSourceVolume(source string) (bool, error) {
266+
switch {
267+
case strings.HasPrefix(source, "git://"):
268+
return false, nil
269+
case strings.HasPrefix(source, "http://"):
270+
fallthrough
271+
case strings.HasPrefix(source, "https://"):
272+
part := strings.Split(source, ":")
273+
count := len(part)
274+
if strings.HasSuffix(source, "/") || strings.HasSuffix(source, ".git") ||
275+
(count >= 3 && strings.HasSuffix(part[count-2], ".git")) {
276+
return false, nil
277+
} else {
278+
return true, nil
279+
}
280+
case strings.HasPrefix(source, "/"):
281+
info, err := os.Stat(source)
282+
if err != nil {
283+
return false, err
284+
}
285+
if info.IsDir() {
286+
return false, nil
287+
} else if info.Mode()&os.ModeType != 0 {
288+
return false, fmt.Errorf("cannot init volume from special file: %s", source)
289+
}
290+
return true, nil
291+
default:
292+
return false, fmt.Errorf("unsupported volume source type: %s", source)
293+
}
294+
295+
}
296+
248297
// CmdRun runs a command in a new container.
249298
//
250299
// Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

api/client/utils.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (cli *DockerCli) resolveAuthConfig(authConfigs map[string]types.AuthConfig,
219219
}
220220

221221
// uploadLocalResource upload a local file/directory to a container
222-
func (cli *DockerCli) uploadLocalResource(source, dest, serverIP, user, passwd string) error {
222+
func (cli *DockerCli) uploadLocalResource(source, dest, serverIP, user, passwd string, isFile bool) error {
223223
if !strings.Contains(serverIP, ":") {
224224
serverIP += ":21"
225225
}
@@ -236,12 +236,25 @@ func (cli *DockerCli) uploadLocalResource(source, dest, serverIP, user, passwd s
236236
return err
237237
}
238238

239-
if err = ftp.Cwd(dest); err != nil {
240-
return err
241-
}
239+
if isFile {
240+
file, err := os.Open(source)
241+
if err != nil {
242+
return err
243+
}
244+
defer func() {
245+
file.Close()
246+
}()
247+
if err = ftp.Stor(dest, file); err != nil {
248+
return err
249+
}
250+
} else {
251+
if err = ftp.Cwd(dest); err != nil {
252+
return err
253+
}
242254

243-
if err = ftp.Upload(source); err != nil {
244-
return err
255+
if err = ftp.Upload(source); err != nil {
256+
return err
257+
}
245258
}
246259

247260
return nil
File renamed without changes.

runconfig/opts/parse.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
5959
flPrivileged = cmd.Bool([]string{}, false, "Give extended privileges to this container")
6060
flPidMode = cmd.String([]string{}, "", "PID namespace to use")
6161
flUTSMode = cmd.String([]string{}, "", "UTS namespace to use")
62-
flPublishAll = cmd.Bool([]string{}, true, "Publish all exposed ports to random ports")
62+
flPublishAll = cmd.Bool([]string{"P", "-publish-all"}, false, "Publish all exposed ports to random ports")
6363
flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
6464
flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY")
6565
flOomKillDisable = cmd.Bool([]string{}, false, "Disable OOM Killer")
@@ -90,7 +90,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
9090
flLoggingDriver = cmd.String([]string{}, "", "Logging driver for container")
9191
flCgroupParent = cmd.String([]string{}, "", "Optional parent cgroup for the container")
9292
flVolumeDriver = cmd.String([]string{}, "", "Optional volume driver for the container")
93-
flStopSignal = cmd.String([]string{}, signal.DefaultStopSignal, fmt.Sprintf("Signal to stop a container, %v by default", signal.DefaultStopSignal))
93+
flStopSignal = cmd.String([]string{"-stop-signal"}, signal.DefaultStopSignal, fmt.Sprintf("Signal to stop a container, %v by default", signal.DefaultStopSignal))
9494
flIsolation = cmd.String([]string{}, "", "Container isolation level")
9595
flShmSize = cmd.String([]string{}, "", "Size of /dev/shm, default value is 64MB")
9696
flInstanceType = cmd.String([]string{"-size"}, "xs", "The type for each instance (e.g. xxs, xs, s, m, l, xl, xxl)")
@@ -111,8 +111,8 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
111111
cmd.Var(&flLabelsFile, []string{"-label-file"}, "Read in a line delimited file of labels")
112112
cmd.Var(&flEnv, []string{"e", "-env"}, "Set environment variables")
113113
cmd.Var(&flEnvFile, []string{"-env-file"}, "Read in a file of environment variables")
114-
cmd.Var(&flPublish, []string{}, "Publish a container's port(s) to the host")
115-
cmd.Var(&flExpose, []string{}, "Expose a port or a range of ports")
114+
cmd.Var(&flPublish, []string{"p", "-publish"}, "Publish a container's port(s) to the host")
115+
cmd.Var(&flExpose, []string{"-expose"}, "Expose a port or a range of ports")
116116
cmd.Var(&flDNS, []string{}, "Set custom DNS servers")
117117
cmd.Var(&flDNSSearch, []string{}, "Set custom DNS search domains")
118118
cmd.Var(&flDNSOptions, []string{}, "Set DNS options")

0 commit comments

Comments
 (0)