Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
builder: enable the user to set event handlers
Browse files Browse the repository at this point in the history
Event handlers which have been set in the `aci-manifest.yml` will be written
to the final `manifest` file.

If a "pre-start" handler has been set, then it will not be overwritten by
dgr's default, "/dgr/bin/prestart".

Iff "/dgr/bin" has been excluded from the image, especially using the prefix
"/dgr", then dgr's defaults won't be used at all.
(Such an image would not start anyway, leaving the user confused about the
cause, whether it's app.exec or any pre-start handler.)
  • Loading branch information
mark-kubacki committed Dec 19, 2016
1 parent f829091 commit c639dbe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
18 changes: 17 additions & 1 deletion dgr/common/aci-manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"

"github.com/appc/spec/aci"
Expand Down Expand Up @@ -110,9 +111,24 @@ func WriteAciManifest(m *AciManifest, targetFile string, projectName string, dgr
im.Name = *name
im.Labels = labels

for _, exclusion := range m.Build.Exclude {
if strings.HasPrefix("/dgr/bin", exclusion) {
goto collectionIsComplete
}
}
if len(m.Aci.App.Exec) == 0 {
m.Aci.App.Exec = []string{"/dgr/bin/busybox", "sh"}
}
// Set a pre-start handler, to run dgr's scripts.
for i := range m.Aci.App.EventHandlers {
if m.Aci.App.EventHandlers[i].Name == "pre-start" {
goto collectionIsComplete
}
}
m.Aci.App.EventHandlers = append(m.Aci.App.EventHandlers,
types.EventHandler{Name: "pre-start", Exec: []string{"/dgr/bin/prestart"}})

collectionIsComplete:

isolators, err := ToAppcIsolators(m.Aci.App.Isolators)
if err != nil {
Expand All @@ -121,7 +137,7 @@ func WriteAciManifest(m *AciManifest, targetFile string, projectName string, dgr

im.App = &types.App{
Exec: m.Aci.App.Exec,
EventHandlers: []types.EventHandler{{Name: "pre-start", Exec: []string{"/dgr/bin/prestart"}}},
EventHandlers: m.Aci.App.EventHandlers,
User: m.Aci.App.User,
Group: m.Aci.App.Group,
WorkingDirectory: m.Aci.App.WorkingDirectory,
Expand Down
19 changes: 10 additions & 9 deletions dgr/common/dgr-manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ type AciDefinition struct {
}

type DgrApp struct {
Exec types.Exec `json:"exec,omitempty" yaml:"exec,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
Group string `json:"group,omitempty" yaml:"group,omitempty"`
SupplementaryGIDs []int `json:"supplementaryGIDs,omitempty" yaml:"supplementaryGIDs,omitempty"`
WorkingDirectory string `json:"workingDirectory,omitempty" yaml:"workingDirectory,omitempty"`
Environment types.Environment `json:"environment,omitempty" yaml:"environment,omitempty"`
MountPoints []types.MountPoint `json:"mountPoints,omitempty" yaml:"mountPoints,omitempty"`
Ports []types.Port `json:"ports,omitempty" yaml:"ports,omitempty"`
Isolators []Isolator `json:"isolators,omitempty" yaml:"isolators,omitempty"`
Exec types.Exec `json:"exec,omitempty" yaml:"exec,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
Group string `json:"group,omitempty" yaml:"group,omitempty"`
SupplementaryGIDs []int `json:"supplementaryGIDs,omitempty" yaml:"supplementaryGIDs,omitempty"`
WorkingDirectory string `json:"workingDirectory,omitempty" yaml:"workingDirectory,omitempty"`
Environment types.Environment `json:"environment,omitempty" yaml:"environment,omitempty"`
EventHandlers []types.EventHandler `json:"eventHandlers,omitempty" yaml:"eventHandlers,omitempty"`
MountPoints []types.MountPoint `json:"mountPoints,omitempty" yaml:"mountPoints,omitempty"`
Ports []types.Port `json:"ports,omitempty" yaml:"ports,omitempty"`
Isolators types.Isolators `json:"isolators,omitempty" yaml:"isolators,omitempty"`
}

type LinuxCapabilitiesSetValue struct {
Expand Down

0 comments on commit c639dbe

Please sign in to comment.