Skip to content

Commit

Permalink
Merge branch 'refactor/appdir' into 'master'
Browse files Browse the repository at this point in the history
configurable appdir

See merge request !49
  • Loading branch information
timfeirg committed Jan 25, 2017
2 parents b735204 + a790f6c commit ef0101f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.12e
0.7.12f
18 changes: 10 additions & 8 deletions cluster/calcium/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ echo 32768 > /writable-proc/sys/net/core/somaxconn
echo 1 > /writable-proc/sys/vm/overcommit_memory
chmod 777 /dev/stdout
chmod 777 /dev/stderr
if [ -d /{{.Appname}}/permdir ]; then chown {{.UID}} /{{.Appname}}/permdir; fi
if [ -d {{.Appdir}}/{{.Appname}}/permdir ]; then chown {{.UID}} {{.Appdir}}/{{.Appname}}/permdir; fi
neednetwork=$1
if [ $neednetwork = "network" ]; then
Expand All @@ -44,12 +44,12 @@ shift

const dockerFile = `FROM {{.Base}}
ENV ERU 1
ADD %s /{{.Appname}}
ADD %s {{.Appdir}}/{{.Appname}}
ADD launcher /usr/local/bin/launcher
ADD launcheroot /usr/local/bin/launcheroot
WORKDIR /{{.Appname}}
WORKDIR {{.Appdir}}/{{.Appname}}
RUN useradd -u %s -d /nonexistent -s /sbin/nologin -U {{.Appname}}
RUN chown -R %s /{{.Appname}}
RUN chown -R %s {{.Appdir}}/{{.Appname}}
{{with .Build}}
{{range $index, $value := .}}
RUN {{$value}}
Expand All @@ -60,6 +60,7 @@ RUN {{$value}}
// Entry is used to format templates
type entry struct {
Command string
Appdir string
Appname string
UID string
}
Expand Down Expand Up @@ -153,7 +154,7 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
}

// create launcher scripts and dockerfile
if err := createLauncher(buildDir, uid, specs); err != nil {
if err := createLauncher(c.config.AppDir, buildDir, uid, specs); err != nil {
return ch, err
}
if err := createDockerfile(buildDir, uid, reponame, specs); err != nil {
Expand Down Expand Up @@ -254,7 +255,7 @@ func createTarStream(path string) (io.ReadCloser, error) {
}

// launcher scripts
func createLauncher(buildDir string, uid string, specs types.Specs) error {
func createLauncher(appDir, buildDir, uid string, specs types.Specs) error {
launcherScriptTemplate, _ := template.New("launcher script").Parse(launcherScript)

entryCommand := fmt.Sprintf("exec sudo -E -u %s $@", specs.Appname)
Expand All @@ -265,7 +266,8 @@ func createLauncher(buildDir string, uid string, specs types.Specs) error {
return err
}
defer f.Close()
launcherScriptTemplate.Execute(f, entry{Command: entryCommand, Appname: specs.Appname, UID: uid})
appDir = strings.TrimRight(appDir, "/")
launcherScriptTemplate.Execute(f, entry{Command: entryCommand, Appdir: appDir, Appname: specs.Appname, UID: uid})
if err := f.Sync(); err != nil {
return err
}
Expand All @@ -278,7 +280,7 @@ func createLauncher(buildDir string, uid string, specs types.Specs) error {
return err
}
defer fr.Close()
launcherScriptTemplate.Execute(fr, entry{Command: entryRootCommand, Appname: specs.Appname, UID: uid})
launcherScriptTemplate.Execute(fr, entry{Command: entryRootCommand, Appdir: appDir, Appname: specs.Appname, UID: uid})
if err := fr.Sync(); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions core.yaml.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bind: ":5001"
agent_port: "12345"
appdir: "/home"
permdir: "/mnt/mfs/permdirs"
etcd:
- "http://127.0.0.1:2379"
Expand Down
1 change: 1 addition & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package types
type Config struct {
Bind string `yaml:"bind"` // HTTP API address
AgentPort string `yaml:"agent_port"` // Agent HTTP port, may not be used
AppDir string `yaml:"appdir"` // App directory inside container
PermDir string `yaml:"permdir"` // Permanent dir on host
EtcdMachines []string `yaml:"etcd"` // etcd cluster addresses
EtcdLockPrefix string `yaml:"etcd_lock_prefix"` // etcd lock prefix, all locks will be created under this dir
Expand Down

0 comments on commit ef0101f

Please sign in to comment.