This repository has been archived by the owner on Sep 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
startbuild.go
101 lines (85 loc) · 2.31 KB
/
startbuild.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"io/ioutil"
"path/filepath"
"github.com/sgotti/acido/util"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/appc/spec/schema"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/appc/spec/schema/types"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/coreos/fleet/log"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/coreos/rocket/cas"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/coreos/rocket/pkg/aci"
)
var (
cmdStartBuild = &Command{
Name: "startbuild",
Summary: "Prepare an image for future build. If base image is specified it's extracted (satisfying all its dependencies) and a base app-manifest with dependencies set to the baseimage is created",
Usage: "BASEIMAGEHASH...",
Description: `BASEIMAGEHASH hash of base image (it must exists in the store or it sould be imported with the \"import\" command.`,
Run: runStartBuild,
}
)
func init() {
commands = append(commands, cmdStartBuild)
}
func startBuild(args []string) error {
ds, err := cas.NewStore(globalFlags.Dir)
if err != nil {
return err
}
baseImageIDStr := args[0]
tmpdir, err := ioutil.TempDir(globalFlags.WorkDir, "")
if err != nil {
return err
}
log.Debugf("tmpdir: %s", tmpdir)
key, err := util.KeyFromArg(baseImageIDStr, ds)
if err != nil {
return err
}
log.Debugf("key: %s", key)
baseImageID, err := types.NewHash(key)
if err != nil {
return err
}
baseim, err := ds.GetImageManifest(key)
if err != nil {
return err
}
log.Debugf("baseim: %s", baseim)
err = aci.RenderACIWithImageID(*baseImageID, tmpdir, ds)
if err != nil {
return err
}
log.Infof("Image extracted to %s", tmpdir)
version := schema.AppContainerVersion
im := schema.ImageManifest{
ACKind: "ImageManifest",
ACVersion: version,
Name: baseim.Name,
Labels: baseim.Labels,
Dependencies: types.Dependencies{
types.Dependency{
App: baseim.Name,
ImageID: baseImageID,
Labels: baseim.Labels,
},
},
}
out, err := im.MarshalJSON()
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(tmpdir, "manifest"), out, 0644)
if err != nil {
return err
}
return nil
}
func runStartBuild(args []string) (exit int) {
err := startBuild(args)
if err != nil {
log.Errorf("error: %v", err)
return 1
}
return 0
}