forked from cloudfoundry-incubator/cflocal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.go
60 lines (50 loc) · 1.72 KB
/
script.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
package fixtures
import "fmt"
func RunRSyncScript() string {
return fmt.Sprintf(runnerScript, "\n\trsync -a /tmp/local/ /home/vcap/app/", rsyncRunningToLocal)
}
func CommitScript() string {
return fmt.Sprintf(runnerScript, "", "")
}
func StageRSyncScript() string {
return fmt.Sprintf(stageScript, "", "\n\trsync -a /tmp/app/ /tmp/local/")
}
func ForwardScript() string {
return forwardScript
}
const forwardScript = `
echo 'Forwarding: some-name some-other-name'
sshpass -f /tmp/ssh-code ssh -4 -N \
-o PermitLocalCommand=yes -o LocalCommand="touch /tmp/healthy" \
-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
-o LogLevel=ERROR -o ExitOnForwardFailure=yes \
-o ServerAliveInterval=10 -o ServerAliveCountMax=60 \
-p 'some-port' 'some-user@some-ssh-host' \
-L 'some-from:some-to' \
-L 'some-other-from:some-other-to'
rm -f /tmp/healthy
`
const rsyncRunningToLocal = `
if [[ -z $(ls -A /tmp/local) ]]; then
rsync -a /home/vcap/app/ /tmp/local/
fi`
const runnerScript = `
set -e%s
if [[ ! -z $(ls -A /home/vcap/app) ]]; then
exclude='--exclude=./app'
fi
tar $exclude -C /home/vcap -xzf /tmp/droplet
chown -R vcap:vcap /home/vcap%s
command=$1
if [[ -z $command ]]; then
command=$(jq -r .start_command /home/vcap/staging_info.yml)
fi
exec /tmp/lifecycle/launcher /home/vcap/app "$command" ''
`
const stageScript = `
set -e
su vcap -c "unzip -qq /tmp/some-checksum-one.zip -d /tmp/buildpacks/some-checksum-one" && rm /tmp/some-checksum-one.zip
su vcap -c "unzip -qq /tmp/some-checksum-two.zip -d /tmp/buildpacks/some-checksum-two" && rm /tmp/some-checksum-two.zip
chown -R vcap:vcap /tmp/app /tmp/cache
%ssu vcap -p -c "PATH=$PATH exec /tmp/lifecycle/builder -buildpackOrder $0 -skipDetect=$1"%s
`