// AddLabel will add a label with the given name and value to the untarred ACI // stored at a.CurrentACIPath. If the label already exists its value will be updated to // the new value. func (a *ACBuild) AddLabel(name, value string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() acid, err := types.NewACIdentifier(name) if err != nil { return err } fn := func(s *schema.ImageManifest) error { removeLabelFromMan(*acid)(s) s.Labels = append(s.Labels, types.Label{ Name: *acid, Value: value, }) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// AddPort will add a port with the given name, protocol, port, and count to // the untarred ACI stored at a.CurrentACIPath. If the port already exists its // value will be updated to the new value. socketActivated signifies whether or // not the application will be socket activated via this port. func (a *ACBuild) AddPort(name, protocol string, port, count uint, socketActivated bool) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() acn, err := types.NewACName(name) if err != nil { return err } fn := func(s *schema.ImageManifest) error { if s.App == nil { s.App = newManifestApp() } removePort(*acn)(s) s.App.Ports = append(s.App.Ports, types.Port{ Name: *acn, Protocol: protocol, Port: port, Count: count, SocketActivated: socketActivated, }) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// AddMount will add a mount point with the given name and path to the untarred // ACI stored at a.CurrentACIPath. If the mount point already exists its value // will be updated to the new value. readOnly signifies whether or not the // mount point should be read only. func (a *ACBuild) AddMount(name, path string, readOnly bool) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() acn, err := types.NewACName(name) if err != nil { return err } fn := func(s *schema.ImageManifest) error { removeMount(*acn)(s) if s.App == nil { s.App = newManifestApp() } s.App.MountPoints = append(s.App.MountPoints, types.MountPoint{ Name: *acn, Path: path, ReadOnly: readOnly, }) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// RemoveEnv will remove the environment variable with the given name from the // untarred ACI stored at a.CurrentACIPath. func (a *ACBuild) RemoveEnv(name string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() return util.ModifyManifest(removeFromEnv(name), a.CurrentACIPath) }
// RemoveAnnotation will remove the annotation with the given name from the // untarred ACI stored at a.CurrentACIPath func (a *ACBuild) RemoveAnnotation(name string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() acid, err := types.NewACIdentifier(name) if err != nil { return err } return util.ModifyManifest(removeAnnotation(*acid), a.CurrentACIPath) }
// RemovePort will remove the port with the given name from the untarred ACI // stored at a.CurrentACIPath. func (a *ACBuild) RemovePort(name string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() acn, err := types.NewACName(name) if err != nil { return err } return util.ModifyManifest(removePort(*acn), a.CurrentACIPath) }
func (a *ACBuild) AddIsolator(name string, value []byte) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() acid, err := types.NewACIdentifier(name) if err != nil { return err } rawMsg := json.RawMessage(value) fn := func(s *schema.ImageManifest) error { if s.App == nil { s.App = newManifestApp() } _, ok := types.ResourceIsolatorNames[*acid] if !ok { _, ok = types.LinuxIsolatorNames[*acid] if !ok { return fmt.Errorf("unknown isolator name: %s", name) } } i := &types.Isolator{ Name: *acid, ValueRaw: &rawMsg, } blob, err := json.Marshal(i) if err != nil { return err } err = i.UnmarshalJSON(blob) if err != nil { return err } removeIsolatorFromMan(*acid)(s) s.App.Isolators = append(s.App.Isolators, *i) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// SetExec sets the exec command for the untarred ACI stored at // a.CurrentACIPath. func (a *ACBuild) SetExec(cmd []string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() fn := func(s *schema.ImageManifest) error { if s.App == nil { s.App = newManifestApp() } s.App.Exec = cmd return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// AddEnv will add an environment variable with the given name and value to the // untarred ACI stored at a.CurrentACIPath. If the environment variable already // exists its value will be updated to the new value. func (a *ACBuild) AddEnv(name, value string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() fn := func(s *schema.ImageManifest) error { if s.App == nil { s.App = newManifestApp() } s.App.Environment.Set(name, value) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// SetWorkingDir sets the workingDirectory value in the untarred ACI stored at // a.CurrentACIPath func (a *ACBuild) SetWorkingDir(dir string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() fn := func(s *schema.ImageManifest) error { if s.App == nil { s.App = newManifestApp() } s.App.WorkingDirectory = dir return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// AddAnnotation will add an annotation with the given name and value to the // untarred ACI stored at a.CurrentACIPath. If the annotation already exists // its value will be updated to the new value. func (a *ACBuild) AddAnnotation(name, value string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() acid, err := types.NewACIdentifier(name) if err != nil { return err } fn := func(s *schema.ImageManifest) error { s.Annotations.Set(*acid, value) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// SetGroup sets the group the pod will run as in the untarred ACI stored at // a.CurrentACIPath. func (a *ACBuild) SetGroup(group string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() if group == "" { return fmt.Errorf("group cannot be empty") } fn := func(s *schema.ImageManifest) error { if s.App == nil { s.App = newManifestApp() } s.App.Group = group return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// AddDependency will add a dependency with the given name, id, labels, and size // to the untarred ACI stored at a.CurrentACIPath. If the dependency already // exists its fields will be updated to the new values. func (a *ACBuild) AddDependency(imageName types.ACIdentifier, imageId *types.Hash, labels types.Labels, size uint) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() fn := func(s *schema.ImageManifest) error { removeDep(imageName)(s) s.Dependencies = append(s.Dependencies, types.Dependency{ ImageName: imageName, ImageID: imageId, Labels: labels, Size: size, }) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
// SetName sets the name for the untarred ACI stored at a.CurrentACIPath func (a *ACBuild) SetName(name string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() if name == "" { return fmt.Errorf("name cannot be empty") } acid, err := types.NewACIdentifier(name) if err != nil { return err } fn := func(s *schema.ImageManifest) error { s.Name = *acid return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }
func (a *ACBuild) setEventHandler(name string, exec []string) (err error) { if err = a.lock(); err != nil { return err } defer func() { if err1 := a.unlock(); err == nil { err = err1 } }() fn := func(s *schema.ImageManifest) error { removeEventHandler(name, s) if s.App == nil { s.App = newManifestApp() } s.App.EventHandlers = append(s.App.EventHandlers, types.EventHandler{ Name: name, Exec: exec, }) return nil } return util.ModifyManifest(fn, a.CurrentACIPath) }