示例#1
0
文件: image.go 项目: saper/jetpack
func NewImage(h *Host, id uuid.UUID) *Image {
	if id == nil {
		id = uuid.NewRandom()
	}
	return &Image{
		Host:     h,
		UUID:     id,
		Manifest: *schema.BlankImageManifest(),
		ui:       ui.NewUI("blue", "image", id.String()),
	}
}
示例#2
0
func WriteImageManifest(m *spec.AciManifest, targetFile string, projectName string, cntVersion string) {
	name, err := types.NewACIdentifier(m.NameAndVersion.Name())
	if err != nil {
		panic(err)
	}

	version := m.NameAndVersion.Version()
	if version == "" {
		version = GenerateVersion()
	}

	labels := types.Labels{}
	labels = append(labels, types.Label{Name: "version", Value: version})
	labels = append(labels, types.Label{Name: "os", Value: "linux"})
	labels = append(labels, types.Label{Name: "arch", Value: "amd64"})

	if m.Aci.App.User == "" {
		m.Aci.App.User = "******"
	}
	if m.Aci.App.Group == "" {
		m.Aci.App.Group = "0"
	}

	im := schema.BlankImageManifest()
	im.Annotations = m.Aci.Annotations

	cntVersionIdentifier, _ := types.NewACIdentifier("cnt-version")
	im.Annotations.Set(*cntVersionIdentifier, cntVersion)
	im.Dependencies = toAppcDependencies(m.Aci.Dependencies)
	im.Name = *name
	im.Labels = labels

	im.App = &types.App{
		Exec:             m.Aci.App.Exec,
		EventHandlers:    []types.EventHandler{{Name: "pre-start", Exec: []string{"/cnt/bin/prestart"}}},
		User:             m.Aci.App.User,
		Group:            m.Aci.App.Group,
		WorkingDirectory: m.Aci.App.WorkingDirectory,
		Environment:      m.Aci.App.Environment,
		MountPoints:      m.Aci.App.MountPoints,
		Ports:            m.Aci.App.Ports,
		Isolators:        m.Aci.App.Isolators,
	}

	buff, err := im.MarshalJSON()
	if err != nil {
		panic(err)
	}
	err = ioutil.WriteFile(targetFile, buff, 0644)
	if err != nil {
		panic(err)
	}
}
func (s Service) aciManifestToMap(result map[string][]cntspec.ACFullname, contents []byte) error {
	aci := schema.BlankImageManifest()
	err := aci.UnmarshalJSON(contents)
	if err != nil {
		return err
	}

	version, _ := aci.Labels.Get("version")
	fullname := cntspec.NewACFullName(aci.Name.String() + ":" + version)
	result[fullname.Name()] = []cntspec.ACFullname{*fullname}
	return nil
}
示例#4
0
func (cmd *Builder) prepareManifest() error {
	name, err := cmd.custom.GetImageName()
	if err != nil {
		return err
	}
	labels, err := cmd.getLabels()
	if err != nil {
		return err
	}
	app, err := cmd.getApp()
	if err != nil {
		return err
	}

	cmd.manifest = schema.BlankImageManifest()
	cmd.manifest.Name = *name
	cmd.manifest.App = app
	cmd.manifest.Labels = labels
	return nil
}
示例#5
0
func WriteImageManifest(m *spec.AciManifest, targetFile string, projectName string, version string) {
	name, _ := types.NewACIdentifier(m.NameAndVersion.Name())

	labels := types.Labels{}
	labels = append(labels, types.Label{Name: "version", Value: m.NameAndVersion.Version()})

	if m.Aci.App.User == "" {
		m.Aci.App.User = "******"
	}
	if m.Aci.App.Group == "" {
		m.Aci.App.Group = "0"
	}

	im := schema.BlankImageManifest()
	im.Annotations = m.Aci.Annotations
	im.Dependencies = toAppcDependencies(m.Aci.Dependencies)
	im.Name = *name
	im.Labels = labels
	im.App = &types.App{
		Exec:             m.Aci.App.Exec,
		EventHandlers:    m.Aci.App.EventHandlers,
		User:             m.Aci.App.User,
		Group:            m.Aci.App.Group,
		WorkingDirectory: m.Aci.App.WorkingDirectory,
		Environment:      m.Aci.App.Environment,
		MountPoints:      m.Aci.App.MountPoints,
		Ports:            m.Aci.App.Ports,
		Isolators:        m.Aci.App.Isolators,
	}

	buff, err := im.MarshalJSON()
	if err != nil {
		log.Get().Panic(err)
	}
	err = ioutil.WriteFile(targetFile, buff, 0644)
	if err != nil {
		log.Get().Panic(err)
	}
}
示例#6
0
func WriteAciManifest(m *AciManifest, targetFile string, projectName string, dgrVersion string) error {
	fields := data.WithField("name", m.NameAndVersion.String())
	name, err := types.NewACIdentifier(projectName)
	if err != nil {
		return errs.WithEF(err, fields, "aci name is not a valid identifier for rkt")
	}

	labels := types.Labels{}
	if m.NameAndVersion.Version() != "" {
		labels = append(labels, types.Label{Name: "version", Value: m.NameAndVersion.Version()})
	}
	labels = append(labels, types.Label{Name: "os", Value: "linux"})
	labels = append(labels, types.Label{Name: "arch", Value: "amd64"})

	if m.Aci.App.User == "" {
		m.Aci.App.User = "******"
	}
	if m.Aci.App.Group == "" {
		m.Aci.App.Group = "0"
	}

	im := schema.BlankImageManifest()
	im.Annotations = m.Aci.Annotations

	//dgrBuilderIdentifier, _ := types.NewACIdentifier(ManifestDrgBuilder)
	dgrVersionIdentifier, _ := types.NewACIdentifier(ManifestDrgVersion)
	buildDateIdentifier, _ := types.NewACIdentifier("build-date")
	im.Annotations.Set(*dgrVersionIdentifier, dgrVersion)
	//im.Annotations.Set(*dgrBuilderIdentifier, m.Builder.Image.String())
	im.Annotations.Set(*buildDateIdentifier, time.Now().Format(time.RFC3339))
	im.Dependencies, err = ToAppcDependencies(m.Aci.Dependencies)
	if err != nil {
		return errs.WithEF(err, fields, "Failed to prepare dependencies for manifest")
	}
	im.Name = *name
	im.Labels = labels

	if len(m.Aci.App.Exec) == 0 {
		m.Aci.App.Exec = []string{"/dgr/bin/busybox", "sh"}
	}

	im.App = &types.App{
		Exec:              m.Aci.App.Exec,
		EventHandlers:     []types.EventHandler{{Name: "pre-start", Exec: []string{"/dgr/bin/prestart"}}},
		User:              m.Aci.App.User,
		Group:             m.Aci.App.Group,
		WorkingDirectory:  m.Aci.App.WorkingDirectory,
		SupplementaryGIDs: m.Aci.App.SupplementaryGIDs,
		Environment:       m.Aci.App.Environment,
		MountPoints:       m.Aci.App.MountPoints,
		Ports:             m.Aci.App.Ports,
		Isolators:         m.Aci.App.Isolators,
	}
	buff, err := json.MarshalIndent(im, "", "  ")
	if err != nil {
		return errs.WithEF(err, fields.WithField("object", im), "Failed to marshal manifest")
	}
	err = ioutil.WriteFile(targetFile, buff, 0644)
	if err != nil {
		return errs.WithEF(err, fields.WithField("file", targetFile), "Failed to write manifest file")
	}
	return nil
}