28
28
{{rootCmdUse}} run - Run a function locally
29
29
30
30
SYNOPSIS
31
- {{rootCmdUse}} run [-t|--container] [- r|--registry] [-i|--image] [-e|--env]
32
- [--build] [-b|--builder] [--builder-image] [-c|--confirm]
31
+ {{rootCmdUse}} run [-r|--registry] [-i|--image] [-e|--env] [--build ]
32
+ [-b|--builder] [--builder-image] [-c|--confirm]
33
33
[--address] [--json] [-v|--verbose]
34
34
35
35
DESCRIPTION
@@ -38,38 +38,32 @@ DESCRIPTION
38
38
Values provided for flags are not persisted to the function's metadata.
39
39
40
40
Containerized Runs
41
- The --container flag indicates that the function's container should be
42
- run rather than running the source code directly. This may require that
43
- the function's container first be rebuilt. Building the container on or
44
- off can be altered using the --build flag. The value --build=auto
45
- can be used to indicate the function should be run in a container, with
46
- the container automatically built if necessary.
47
-
48
- The --container flag defaults to true if the builder defined for the
49
- function is a containerized builder such as Pack or S2I, and in the case
50
- where the function's runtime requires containerized builds (is not yet
51
- supported by the Host builder.
41
+ You can build your function in a container using the Pack or S2i builders.
42
+ On the contrary, non-containerized run is achieved via Host builder which
43
+ will use your host OS' environment to build the function. This builder is
44
+ currently enabled for Go and Python. Building defaults to using the Host
45
+ builder when available. You can alter this by using the --builder flag
46
+ eg: --builder=s2i.
52
47
53
48
Process Scaffolding
54
- This is an Experimental Feature currently available only to Go projects.
55
- When running a function with --container=false (host-based runs), the
56
- function is first wrapped code which presents it as a process.
57
- This "scaffolding" is transient, written for each build or run, and should
58
- in most cases be transparent to a function author. However, to customize,
59
- or even completely replace this scafolding code, see the 'scaffold'
60
- subcommand.
49
+ This is an Experimental Feature currently available only to Go and Python
50
+ projects. When running a function with --builder=host, the function is
51
+ first wrapped with code which presents it as a process. This "scaffolding"
52
+ is transient, written for each build or run, and should in most cases be
53
+ transparent to a function author.
61
54
62
55
EXAMPLES
63
56
64
57
o Run the function locally from within its container.
65
58
$ {{rootCmdUse}} run
66
59
67
60
o Run the function locally from within its container, forcing a rebuild
68
- of the container even if no filesysem changes are detected
69
- $ {{rootCmdUse}} run --build
61
+ of the container even if no filesystem changes are detected. There are 2
62
+ builders available for containerized build - 'pack' and 's2i'.
63
+ $ {{rootCmdUse}} run --build=<builder>
70
64
71
- o Run the function locally on the host with no containerization (Go only).
72
- $ {{rootCmdUse}} run --container=false
65
+ o Run the function locally on the host with no containerization (Go/Python only).
66
+ $ {{rootCmdUse}} run --builder=host
73
67
74
68
o Run the function locally on a specific address.
75
69
$ {{rootCmdUse}} run --address='[::]:8081'
@@ -79,7 +73,7 @@ EXAMPLES
79
73
` ,
80
74
SuggestFor : []string {"rnu" },
81
75
PreRunE : bindEnv ("build" , "builder" , "builder-image" , "base-image" ,
82
- "confirm" , "container" , " env" , "image" , "path" , "registry" ,
76
+ "confirm" , "env" , "image" , "path" , "registry" ,
83
77
"start-timeout" , "verbose" , "address" , "json" ),
84
78
RunE : func (cmd * cobra.Command , _ []string ) error {
85
79
return runRun (cmd , newClient )
@@ -121,8 +115,6 @@ EXAMPLES
121
115
"You may provide this flag multiple times for setting multiple environment variables. " +
122
116
"To unset, specify the environment variable name followed by a \" -\" (e.g., NAME-)." )
123
117
cmd .Flags ().Duration ("start-timeout" , f .Run .StartTimeout , fmt .Sprintf ("time this function needs in order to start. If not provided, the client default %v will be in effect. ($FUNC_START_TIMEOUT)" , fn .DefaultStartTimeout ))
124
- cmd .Flags ().BoolP ("container" , "t" , runContainerizedByDefault (f ),
125
- "Run the function in a container. ($FUNC_CONTAINER)" )
126
118
127
119
// TODO: Without the "Host" builder enabled, this code-path is unreachable,
128
120
// so remove hidden flag when either the Host builder path is available,
@@ -157,10 +149,6 @@ EXAMPLES
157
149
return cmd
158
150
}
159
151
160
- func runContainerizedByDefault (f fn.Function ) bool {
161
- return f .Build .Builder == "pack" || f .Build .Builder == "s2i" || ! oci .IsSupported (f .Runtime )
162
- }
163
-
164
152
func runRun (cmd * cobra.Command , newClient ClientFactory ) (err error ) {
165
153
var (
166
154
cfg runConfig
@@ -174,28 +162,17 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
174
162
if ! f .Initialized () {
175
163
return fn .NewErrNotInitialized (f .Root )
176
164
}
177
- if f , err = cfg .Configure (f ); err != nil { // Updates f with deploy cfg
178
- return
179
- }
180
-
181
- // Smart auto-fix logic for builder/container compatibility
182
- // This fixes the original bug where --builder=pack doesn't default to container=true
183
165
184
- // Case 1: Containerized builders (pack/s2i) should force container=true when not explicitly set
185
- if (f .Build .Builder == "pack" || f .Build .Builder == "s2i" ) && ! cfg .Container && ! cmd .Flags ().Changed ("container" ) {
186
- cfg .Container = true
187
- }
188
-
189
- // Case 2: container=false should auto-select host builder when no builder explicitly set
190
- if ! cfg .Container && cmd .Flags ().Changed ("container" ) && ! cmd .Flags ().Changed ("builder" ) {
191
- f .Build .Builder = "host"
166
+ if err = cfg .Validate (cmd , f ); err != nil {
167
+ return
192
168
}
193
169
194
- // Validate after configure and auto-fix
195
- if err = cfg .Validate (cmd , f ); err != nil {
170
+ if f , err = cfg .Configure (f ); err != nil { // Updates f with deploy cfg
196
171
return
197
172
}
198
173
174
+ container := f .Build .Builder != "host"
175
+
199
176
// Ignore the verbose flag if JSON output
200
177
if cfg .JSON {
201
178
cfg .Verbose = false
@@ -206,7 +183,7 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
206
183
if err != nil {
207
184
return
208
185
}
209
- if cfg . Container {
186
+ if container {
210
187
clientOptions = append (clientOptions , fn .WithRunner (docker .NewRunner (cfg .Verbose , os .Stdout , os .Stderr )))
211
188
}
212
189
if cfg .StartTimeout != 0 {
@@ -220,7 +197,7 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
220
197
//
221
198
// If requesting to run via the container, build the container if it is
222
199
// either out-of-date or a build was explicitly requested.
223
- if cfg . Container {
200
+ if container {
224
201
var digested bool
225
202
226
203
buildOptions , err := cfg .buildOptions ()
@@ -234,31 +211,25 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
234
211
if err != nil {
235
212
return err
236
213
}
237
- if ! digested {
238
- // assign valid undigested image
239
- f .Build .Image = cfg .Image
240
- }
241
- }
242
-
243
- if digested {
244
- // run cmd takes f.Build.Image - see newContainerConfig in docker/runner.go
245
- // it doesnt get saved, just runtime image
214
+ // image was parsed and both digested AND undigested imgs are valid
246
215
f .Build .Image = cfg .Image
247
- } else {
216
+ }
248
217
218
+ // actual build step
219
+ if ! digested {
249
220
if f , _ , err = build (cmd , cfg .Build , f , client , buildOptions ); err != nil {
250
221
return err
251
222
}
252
223
}
253
- } else {
224
+ } else { // if !container
254
225
// dont run digested image without a container
255
226
if cfg .Image != "" {
256
227
digested , err := isDigested (cfg .Image )
257
228
if err != nil {
258
229
return err
259
230
}
260
231
if digested {
261
- return fmt .Errorf ("cannot use digested image with --container=false " )
232
+ return fmt .Errorf ("cannot use digested image with non-containerized builds (--builder=host) " )
262
233
}
263
234
}
264
235
}
@@ -330,10 +301,6 @@ type runConfig struct {
330
301
// Can be 'auto' or a truthy value.
331
302
Build string
332
303
333
- // Container indicates the function should be run in a container.
334
- // Requires the container be built.
335
- Container bool
336
-
337
304
// Env variables. may include removals using a "-"
338
305
Env []string
339
306
@@ -353,7 +320,6 @@ func newRunConfig(cmd *cobra.Command) (c runConfig) {
353
320
buildConfig : newBuildConfig (),
354
321
Build : viper .GetString ("build" ),
355
322
Env : viper .GetStringSlice ("env" ),
356
- Container : viper .GetBool ("container" ),
357
323
StartTimeout : viper .GetDuration ("start-timeout" ),
358
324
Address : viper .GetString ("address" ),
359
325
JSON : viper .GetBool ("json" ),
@@ -379,7 +345,7 @@ func (c runConfig) Configure(f fn.Function) (fn.Function, error) {
379
345
380
346
f .Run .Envs , err = applyEnvs (f .Run .Envs , c .Env )
381
347
382
- // The other members; build, path, and container ; are not part of function
348
+ // The other members; build and path ; are not part of function
383
349
// state, so are not mentioned here in Configure.
384
350
return f , err
385
351
}
@@ -412,18 +378,13 @@ func (c runConfig) Validate(cmd *cobra.Command, f fn.Function) (err error) {
412
378
}
413
379
}
414
380
415
- if ! c . Container && ! oci .IsSupported (f .Runtime ) {
381
+ if f . Build . Builder == "host" && ! oci .IsSupported (f .Runtime ) {
416
382
return fmt .Errorf ("the %q runtime currently requires being run in a container" , f .Runtime )
417
383
}
418
384
419
- // Validate that containerized builders (pack/s2i) cannot be used with container=false
420
- if (f .Build .Builder == "pack" || f .Build .Builder == "s2i" ) && ! c .Container {
421
- return fmt .Errorf ("builder %q requires container mode but --container=false was set" , f .Build .Builder )
422
- }
423
-
424
385
// When the docker runner respects the StartTimeout, this validation check
425
386
// can be removed
426
- if c .StartTimeout != 0 && c . Container {
387
+ if c .StartTimeout != 0 && f . Build . Builder != "host" {
427
388
return errors .New ("the ability to specify the startup timeout for containerized runs is coming soon" )
428
389
}
429
390
0 commit comments