@@ -22,6 +22,11 @@ func getPatchedFiles() (string, error) {
2222 return runnerService , nil
2323}
2424
25+ type templateCompressedScriptValue struct {
26+ CompressedScript string
27+ RunnerBaseDirectory string
28+ }
29+
2530func (s * Starter ) getSetupScript (ctx context.Context , targetScope , runnerName string ) (string , error ) {
2631 rawScript , err := s .getSetupRawScript (ctx , targetScope , runnerName )
2732 if err != nil {
@@ -41,7 +46,20 @@ func (s *Starter) getSetupScript(ctx context.Context, targetScope, runnerName st
4146 }
4247 encoded := base64 .StdEncoding .EncodeToString (compressedScript .Bytes ())
4348
44- return fmt .Sprintf (templateCompressedScript , encoded ), nil
49+ v := templateCompressedScriptValue {
50+ CompressedScript : encoded ,
51+ RunnerBaseDirectory : config .Config .RunnerBaseDirectory ,
52+ }
53+
54+ t , err := template .New ("templateCompressedScript" ).Parse (templateCompressedScript )
55+ if err != nil {
56+ return "" , fmt .Errorf ("failed to create template: %w" , err )
57+ }
58+ var buff bytes.Buffer
59+ if err := t .Execute (& buff , v ); err != nil {
60+ return "" , fmt .Errorf ("failed to execute compressed script: %w" , err )
61+ }
62+ return buff .String (), nil
4563}
4664
4765func (s * Starter ) getSetupRawScript (ctx context.Context , targetScope , runnerName string ) (string , error ) {
@@ -89,6 +107,7 @@ func (s *Starter) getSetupRawScript(ctx context.Context, targetScope, runnerName
89107 RunnerServiceJS : runnerServiceJs ,
90108 RunnerArg : runnerTemporaryMode .StringFlag (),
91109 AdditionalLabels : labelsToOneLine (labels ),
110+ RunnerBaseDirectory : config .Config .RunnerBaseDirectory ,
92111 }
93112
94113 t , err := template .New ("templateCreateLatestRunnerOnce" ).Parse (templateCreateLatestRunnerOnce )
@@ -115,8 +134,8 @@ const templateCompressedScript = `#!/bin/bash
115134set -e
116135
117136# main script compressed base64 and gzip
118- export COMPRESSED_SCRIPT=%s
119- export MAIN_SCRIPT_PATH=/tmp /main.sh
137+ export COMPRESSED_SCRIPT={{.CompressedScript}}
138+ export MAIN_SCRIPT_PATH={{.RunnerBaseDirectory}} /main.sh
120139
121140echo ${COMPRESSED_SCRIPT} | base64 -d | gzip -d > ${MAIN_SCRIPT_PATH}
122141
@@ -133,6 +152,7 @@ type templateCreateLatestRunnerOnceValue struct {
133152 RunnerServiceJS string
134153 RunnerArg string
135154 AdditionalLabels string
155+ RunnerBaseDirectory string
136156}
137157
138158// templateCreateLatestRunnerOnce is script template of setup runner.
@@ -148,7 +168,7 @@ runner_name={{.RunnerName}}
148168RUNNER_TOKEN={{.RunnerRegistrationToken}}
149169RUNNER_USER={{.RunnerUser}}
150170RUNNER_VERSION={{.RunnerVersion}}
151- RUNNER_BASE_DIRECTORY=/tmp # /tmp is path of all user writable.
171+ RUNNER_BASE_DIRECTORY={{.RunnerBaseDirectory}}
152172
153173sudo_prefix=""
154174if [ $(id -u) -eq 0 ]; then # if root
0 commit comments