forked from flynn/flynn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.go
71 lines (59 loc) · 1.57 KB
/
release.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-docopt"
"github.com/flynn/flynn/controller/client"
ct "github.com/flynn/flynn/controller/types"
)
func init() {
register("release", runRelease, `
usage: flynn release add [-t <type>] <uri>
Manage app releases.
Options:
-t <type> type of the release. Currently only 'docker' is supported. [default: docker]
-f, --file <file> add a release referencing a Docker image
Commands:
add add a new release
`)
}
func runRelease(args *docopt.Args, client *controller.Client) error {
if args.Bool["add"] {
if args.String["-t"] == "docker" {
return runReleaseAddDocker(args, client)
} else {
return fmt.Errorf("Release type %s not supported.", args.String["-t"])
}
}
return fmt.Errorf("Top-level command not implemented.")
}
func runReleaseAddDocker(args *docopt.Args, client *controller.Client) error {
release := &ct.Release{}
if args.String["--file"] != "" {
data, err := ioutil.ReadFile(args.String["--file"])
if err != nil {
return err
}
if err := json.Unmarshal(data, release); err != nil {
return err
}
}
artifact := &ct.Artifact{
Type: "docker",
URI: args.String["<uri>"],
}
if err := client.CreateArtifact(artifact); err != nil {
return err
}
release.ArtifactID = artifact.ID
if err := client.CreateRelease(release); err != nil {
return err
}
if err := client.SetAppRelease(mustApp(), release.ID); err != nil {
return err
}
log.Printf("Created release %s.", release.ID)
return nil
}