Skip to content

Commit 2988acf

Browse files
matejvasekgauron99
andauthored
Cherry picks 1.19 (#3089)
* Fix backward compat Python pack build picking #2962 Signed-off-by: Matej Vašek <[email protected]> * fix: Python host builder base image version picking #2965 Signed-off-by: Matej Vašek <[email protected]> * Remove container flag - variant I picking #2987 Signed-off-by: Matej Vašek <[email protected]> * fix python injector bug picking #2992 Signed-off-by: Matej Vašek <[email protected]> * fix-of-a-fix picking #2994 Signed-off-by: Matej Vašek <[email protected]> * fix: python scaffolding picking #3080 Signed-off-by: Matej Vašek <[email protected]> * fix: use python3 when python not presetn picking #3082 Signed-off-by: Matej Vašek <[email protected]> * dapr install upgrade picking #3055 Signed-off-by: David Fridrich <[email protected]> Co-authored-by: David Fridrich <[email protected]> Signed-off-by: Matej Vašek <[email protected]> * test: skip ipv6 test correctly picking #3076 Signed-off-by: Matej Vašek <[email protected]> --------- Signed-off-by: Matej Vašek <[email protected]> Signed-off-by: David Fridrich <[email protected]> Co-authored-by: David Fridrich <[email protected]>
1 parent 28c35e2 commit 2988acf

File tree

11 files changed

+167
-108
lines changed

11 files changed

+167
-108
lines changed

cmd/run.go

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ NAME
2727
{{rootCmdUse}} run - Run a function locally
2828
2929
SYNOPSIS
30-
{{rootCmdUse}} run [-t|--container] [-r|--registry] [-i|--image] [-e|--env]
31-
[--build] [-b|--builder] [--builder-image] [-c|--confirm]
30+
{{rootCmdUse}} run [-r|--registry] [-i|--image] [-e|--env] [--build]
31+
[-b|--builder] [--builder-image] [-c|--confirm]
3232
[--address] [--json] [-v|--verbose]
3333
3434
DESCRIPTION
@@ -37,38 +37,32 @@ DESCRIPTION
3737
Values provided for flags are not persisted to the function's metadata.
3838
3939
Containerized Runs
40-
The --container flag indicates that the function's container should be
41-
run rather than running the source code directly. This may require that
42-
the function's container first be rebuilt. Building the container on or
43-
off can be altered using the --build flag. The value --build=auto
44-
can be used to indicate the function should be run in a container, with
45-
the container automatically built if necessary.
46-
47-
The --container flag defaults to true if the builder defined for the
48-
function is a containerized builder such as Pack or S2I, and in the case
49-
where the function's runtime requires containerized builds (is not yet
50-
supported by the Host builder.
40+
You can build your function in a container using the Pack or S2i builders.
41+
On the contrary, non-containerized run is achieved via Host builder which
42+
will use your host OS' environment to build the function. This builder is
43+
currently enabled for Go and Python. Building defaults to using the Host
44+
builder when available. You can alter this by using the --builder flag
45+
eg: --builder=s2i.
5146
5247
Process Scaffolding
53-
This is an Experimental Feature currently available only to Go projects.
54-
When running a function with --container=false (host-based runs), the
55-
function is first wrapped code which presents it as a process.
56-
This "scaffolding" is transient, written for each build or run, and should
57-
in most cases be transparent to a function author. However, to customize,
58-
or even completely replace this scafolding code, see the 'scaffold'
59-
subcommand.
48+
This is an Experimental Feature currently available only to Go and Python
49+
projects. When running a function with --builder=host, the function is
50+
first wrapped with code which presents it as a process. This "scaffolding"
51+
is transient, written for each build or run, and should in most cases be
52+
transparent to a function author.
6053
6154
EXAMPLES
6255
6356
o Run the function locally from within its container.
6457
$ {{rootCmdUse}} run
6558
6659
o Run the function locally from within its container, forcing a rebuild
67-
of the container even if no filesysem changes are detected
68-
$ {{rootCmdUse}} run --build
60+
of the container even if no filesystem changes are detected. There are 2
61+
builders available for containerized build - 'pack' and 's2i'.
62+
$ {{rootCmdUse}} run --build=<builder>
6963
70-
o Run the function locally on the host with no containerization (Go only).
71-
$ {{rootCmdUse}} run --container=false
64+
o Run the function locally on the host with no containerization (Go/Python only).
65+
$ {{rootCmdUse}} run --builder=host
7266
7367
o Run the function locally on a specific address.
7468
$ {{rootCmdUse}} run --address='[::]:8081'
@@ -78,7 +72,7 @@ EXAMPLES
7872
`,
7973
SuggestFor: []string{"rnu"},
8074
PreRunE: bindEnv("build", "builder", "builder-image", "base-image",
81-
"confirm", "container", "env", "image", "path", "registry",
75+
"confirm", "env", "image", "path", "registry",
8276
"start-timeout", "verbose", "address", "json"),
8377
RunE: func(cmd *cobra.Command, _ []string) error {
8478
return runRun(cmd, newClient)
@@ -120,8 +114,6 @@ EXAMPLES
120114
"You may provide this flag multiple times for setting multiple environment variables. "+
121115
"To unset, specify the environment variable name followed by a \"-\" (e.g., NAME-).")
122116
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))
123-
cmd.Flags().BoolP("container", "t", runContainerizedByDefault(f),
124-
"Run the function in a container. ($FUNC_CONTAINER)")
125117

126118
// TODO: Without the "Host" builder enabled, this code-path is unreachable,
127119
// so remove hidden flag when either the Host builder path is available,
@@ -156,10 +148,6 @@ EXAMPLES
156148
return cmd
157149
}
158150

159-
func runContainerizedByDefault(f fn.Function) bool {
160-
return f.Build.Builder == "pack" || f.Build.Builder == "s2i" || !oci.IsSupported(f.Runtime)
161-
}
162-
163151
func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
164152
var (
165153
cfg runConfig
@@ -170,16 +158,20 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
170158
if f, err = fn.NewFunction(cfg.Path); err != nil {
171159
return
172160
}
173-
if err = cfg.Validate(cmd, f); err != nil {
174-
return
175-
}
176161
if !f.Initialized() {
177162
return fn.NewErrNotInitialized(f.Root)
178163
}
164+
165+
if err = cfg.Validate(cmd, f); err != nil {
166+
return
167+
}
168+
179169
if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg
180170
return
181171
}
182172

173+
container := f.Build.Builder != "host"
174+
183175
// Ignore the verbose flag if JSON output
184176
if cfg.JSON {
185177
cfg.Verbose = false
@@ -190,7 +182,7 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
190182
if err != nil {
191183
return
192184
}
193-
if cfg.Container {
185+
if container {
194186
clientOptions = append(clientOptions, fn.WithRunner(docker.NewRunner(cfg.Verbose, os.Stdout, os.Stderr)))
195187
}
196188
if cfg.StartTimeout != 0 {
@@ -204,7 +196,7 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
204196
//
205197
// If requesting to run via the container, build the container if it is
206198
// either out-of-date or a build was explicitly requested.
207-
if cfg.Container {
199+
if container {
208200
var digested bool
209201

210202
buildOptions, err := cfg.buildOptions()
@@ -218,31 +210,25 @@ func runRun(cmd *cobra.Command, newClient ClientFactory) (err error) {
218210
if err != nil {
219211
return err
220212
}
221-
if !digested {
222-
// assign valid undigested image
223-
f.Build.Image = cfg.Image
224-
}
225-
}
226-
227-
if digested {
228-
// run cmd takes f.Build.Image - see newContainerConfig in docker/runner.go
229-
// it doesnt get saved, just runtime image
213+
// image was parsed and both digested AND undigested imgs are valid
230214
f.Build.Image = cfg.Image
231-
} else {
215+
}
232216

217+
// actual build step
218+
if !digested {
233219
if f, _, err = build(cmd, cfg.Build, f, client, buildOptions); err != nil {
234220
return err
235221
}
236222
}
237-
} else {
223+
} else { // if !container
238224
// dont run digested image without a container
239225
if cfg.Image != "" {
240226
digested, err := isDigested(cfg.Image)
241227
if err != nil {
242228
return err
243229
}
244230
if digested {
245-
return fmt.Errorf("cannot use digested image with --container=false")
231+
return fmt.Errorf("cannot use digested image with non-containerized builds (--builder=host)")
246232
}
247233
}
248234
}
@@ -314,10 +300,6 @@ type runConfig struct {
314300
// Can be 'auto' or a truthy value.
315301
Build string
316302

317-
// Container indicates the function should be run in a container.
318-
// Requires the container be built.
319-
Container bool
320-
321303
// Env variables. may include removals using a "-"
322304
Env []string
323305

@@ -337,7 +319,6 @@ func newRunConfig(cmd *cobra.Command) (c runConfig) {
337319
buildConfig: newBuildConfig(),
338320
Build: viper.GetString("build"),
339321
Env: viper.GetStringSlice("env"),
340-
Container: viper.GetBool("container"),
341322
StartTimeout: viper.GetDuration("start-timeout"),
342323
Address: viper.GetString("address"),
343324
JSON: viper.GetBool("json"),
@@ -363,7 +344,7 @@ func (c runConfig) Configure(f fn.Function) (fn.Function, error) {
363344

364345
f.Run.Envs, err = applyEnvs(f.Run.Envs, c.Env)
365346

366-
// The other members; build, path, and container; are not part of function
347+
// The other members; build and path; are not part of function
367348
// state, so are not mentioned here in Configure.
368349
return f, err
369350
}
@@ -396,13 +377,13 @@ func (c runConfig) Validate(cmd *cobra.Command, f fn.Function) (err error) {
396377
}
397378
}
398379

399-
if !c.Container && !oci.IsSupported(f.Runtime) {
380+
if f.Build.Builder == "host" && !oci.IsSupported(f.Runtime) {
400381
return fmt.Errorf("the %q runtime currently requires being run in a container", f.Runtime)
401382
}
402383

403384
// When the docker runner respects the StartTimeout, this validation check
404385
// can be removed
405-
if c.StartTimeout != 0 && c.Container {
386+
if c.StartTimeout != 0 && f.Build.Builder != "host" {
406387
return errors.New("the ability to specify the startup timeout for containerized runs is coming soon")
407388
}
408389

docs/reference/func_run.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ NAME
99
func run - Run a function locally
1010

1111
SYNOPSIS
12-
func run [-t|--container] [-r|--registry] [-i|--image] [-e|--env]
13-
[--build] [-b|--builder] [--builder-image] [-c|--confirm]
12+
func run [-r|--registry] [-i|--image] [-e|--env] [--build]
13+
[-b|--builder] [--builder-image] [-c|--confirm]
1414
[--address] [--json] [-v|--verbose]
1515

1616
DESCRIPTION
@@ -19,38 +19,32 @@ DESCRIPTION
1919
Values provided for flags are not persisted to the function's metadata.
2020

2121
Containerized Runs
22-
The --container flag indicates that the function's container should be
23-
run rather than running the source code directly. This may require that
24-
the function's container first be rebuilt. Building the container on or
25-
off can be altered using the --build flag. The value --build=auto
26-
can be used to indicate the function should be run in a container, with
27-
the container automatically built if necessary.
28-
29-
The --container flag defaults to true if the builder defined for the
30-
function is a containerized builder such as Pack or S2I, and in the case
31-
where the function's runtime requires containerized builds (is not yet
32-
supported by the Host builder.
22+
You can build your function in a container using the Pack or S2i builders.
23+
On the contrary, non-containerized run is achieved via Host builder which
24+
will use your host OS' environment to build the function. This builder is
25+
currently enabled for Go and Python. Building defaults to using the Host
26+
builder when available. You can alter this by using the --builder flag
27+
eg: --builder=s2i.
3328

3429
Process Scaffolding
35-
This is an Experimental Feature currently available only to Go projects.
36-
When running a function with --container=false (host-based runs), the
37-
function is first wrapped code which presents it as a process.
38-
This "scaffolding" is transient, written for each build or run, and should
39-
in most cases be transparent to a function author. However, to customize,
40-
or even completely replace this scafolding code, see the 'scaffold'
41-
subcommand.
30+
This is an Experimental Feature currently available only to Go and Python
31+
projects. When running a function with --builder=host, the function is
32+
first wrapped with code which presents it as a process. This "scaffolding"
33+
is transient, written for each build or run, and should in most cases be
34+
transparent to a function author.
4235

4336
EXAMPLES
4437

4538
o Run the function locally from within its container.
4639
$ func run
4740

4841
o Run the function locally from within its container, forcing a rebuild
49-
of the container even if no filesysem changes are detected
50-
$ func run --build
42+
of the container even if no filesystem changes are detected. There are 2
43+
builders available for containerized build - 'pack' and 's2i'.
44+
$ func run --build=<builder>
5145

52-
o Run the function locally on the host with no containerization (Go only).
53-
$ func run --container=false
46+
o Run the function locally on the host with no containerization (Go/Python only).
47+
$ func run --builder=host
5448

5549
o Run the function locally on a specific address.
5650
$ func run --address='[::]:8081'
@@ -72,7 +66,6 @@ func run
7266
-b, --builder string Builder to use when creating the function's container. Currently supported builders are "host", "pack" and "s2i". (default "pack")
7367
--builder-image string Specify a custom builder image for use by the builder other than its default. ($FUNC_BUILDER_IMAGE)
7468
-c, --confirm Prompt to confirm options interactively ($FUNC_CONFIRM)
75-
-t, --container Run the function in a container. ($FUNC_CONTAINER) (default true)
7669
-e, --env stringArray Environment variable to set in the form NAME=VALUE. You may provide this flag multiple times for setting multiple environment variables. To unset, specify the environment variable name followed by a "-" (e.g., NAME-).
7770
-h, --help help for run
7871
-i, --image string Full image name in the form [registry]/[namespace]/[name]:[tag]. This option takes precedence over --registry. Specifying tag is optional. ($FUNC_IMAGE)

hack/allocate.sh

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,54 @@ dapr_runtime() {
351351
# to only start a single instance rather than four.
352352
# helm repo add bitnami https://charts.bitnami.com/bitnami
353353
echo "${blue}- Redis ${reset}"
354-
$HELM repo add bitnami https://charts.bitnami.com/bitnami
355-
$HELM install redis bitnami/redis --set image.tag=6.2
356-
$HELM repo update
354+
# Deploy Redis using simple manifest with official Redis image
355+
# (Bitnami images have migration issues as of Sept 2025)
356+
$KUBECTL apply -f - << EOF
357+
apiVersion: v1
358+
kind: Service
359+
metadata:
360+
name: redis-master
361+
namespace: default
362+
spec:
363+
ports:
364+
- port: 6379
365+
targetPort: 6379
366+
selector:
367+
app: redis
368+
---
369+
apiVersion: apps/v1
370+
kind: StatefulSet
371+
metadata:
372+
name: redis-master
373+
namespace: default
374+
spec:
375+
serviceName: redis-master
376+
replicas: 1
377+
selector:
378+
matchLabels:
379+
app: redis
380+
template:
381+
metadata:
382+
labels:
383+
app: redis
384+
spec:
385+
containers:
386+
- name: redis
387+
image: redis:7-alpine
388+
ports:
389+
- containerPort: 6379
390+
volumeMounts:
391+
- name: redis-storage
392+
mountPath: /data
393+
volumeClaimTemplates:
394+
- metadata:
395+
name: redis-storage
396+
spec:
397+
accessModes: [ "ReadWriteOnce" ]
398+
resources:
399+
requests:
400+
storage: 1Gi
401+
EOF
357402

358403
# 2) Expose a Redis-backed Dapr State Storage component
359404
echo "${blue}- State Storage Component${reset}"
@@ -370,9 +415,7 @@ spec:
370415
- name: redisHost
371416
value: redis-master.default.svc.cluster.local:6379
372417
- name: redisPassword
373-
secretKeyRef:
374-
name: redis
375-
key: redis-password
418+
value: ""
376419
EOF
377420

378421
# 3) Expose A Redis-backed Dapr Pub/Sub Component
@@ -390,9 +433,7 @@ spec:
390433
- name: redisHost
391434
value: redis-master.default.svc.cluster.local:6379
392435
- name: redisPassword
393-
secretKeyRef:
394-
name: redis
395-
key: redis-password
436+
value: ""
396437
EOF
397438

398439
echo "${green}✅ Dapr Runtime${reset}"

hack/install-binaries.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ install_binaries() {
2828

2929
local kubectl_version=1.33.1
3030
local kind_version=0.29.0
31-
local dapr_version=1.14.1
31+
local dapr_version=1.16.0
3232
local helm_version=3.18.0
3333
local stern_version=1.32.0
3434
local kn_version=1.18.0

pkg/builders/buildpacks/builder.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,16 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
216216
}
217217

218218
if f.Runtime == "python" {
219-
cli = pyScaffoldInjector{cli}
219+
if fi, _ := os.Lstat(filepath.Join(f.Root, "Procfile")); fi == nil {
220+
// HACK (of a hack): need to get the right invocation signature
221+
// the standard scaffolding does this in toSignature() func.
222+
// we know we have python here.
223+
invoke := f.Invoke
224+
if invoke == "" {
225+
invoke = "http"
226+
}
227+
cli = pyScaffoldInjector{cli, invoke}
228+
}
220229
}
221230

222231
// Client with a logger which is enabled if in Verbose mode and a dockerClient that supports SSH docker daemon connection.

0 commit comments

Comments
 (0)