4
4
"archive/tar"
5
5
"context"
6
6
"errors"
7
+ "fmt"
7
8
"io"
8
9
"runtime"
9
10
"strings"
@@ -17,6 +18,7 @@ import (
17
18
// It basically moves content of /workspace to /workspace/fn and then setup scaffolding code directly in /workspace.
18
19
type pyScaffoldInjector struct {
19
20
client.CommonAPIClient
21
+ invoke string
20
22
}
21
23
22
24
func (s pyScaffoldInjector ) CopyToContainer (ctx context.Context , ctr , p string , r io.Reader , opts container.CopyToContainerOptions ) error {
@@ -61,7 +63,7 @@ func (s pyScaffoldInjector) CopyToContainer(ctx context.Context, ctr, p string,
61
63
return
62
64
}
63
65
}
64
- err = writePythonScaffolding (tw )
66
+ err = writePythonScaffolding (tw , s . invoke )
65
67
if err != nil {
66
68
return
67
69
}
@@ -71,7 +73,7 @@ func (s pyScaffoldInjector) CopyToContainer(ctx context.Context, ctr, p string,
71
73
return s .CommonAPIClient .CopyToContainer (ctx , ctr , p , pr , opts )
72
74
}
73
75
74
- func writePythonScaffolding (tw * tar.Writer ) error {
76
+ func writePythonScaffolding (tw * tar.Writer , invoke string ) error {
75
77
for _ , f := range []struct {
76
78
path string
77
79
content string
@@ -82,7 +84,7 @@ func writePythonScaffolding(tw *tar.Writer) error {
82
84
},
83
85
{
84
86
path : "service/main.py" ,
85
- content : serviceMain ,
87
+ content : serviceMain ( invoke ) ,
86
88
},
87
89
{
88
90
path : "service/__init__.py" ,
@@ -133,14 +135,15 @@ python = ">=3.9,<4.0"
133
135
script = "service.main:main"
134
136
`
135
137
136
- const serviceMain = `"""
138
+ func serviceMain (invoke string ) string {
139
+ template := `"""
137
140
This code is glue between a user's Function and the middleware which will
138
141
expose it as a network service. This code is written on-demand when a
139
142
Function is being built, deployed or run. This will be included in the
140
143
final container.
141
144
"""
142
145
import logging
143
- from func_python.cloudevent import serve
146
+ from func_python.%s import serve
144
147
145
148
logging.basicConfig(level=logging.INFO)
146
149
@@ -161,3 +164,5 @@ def main():
161
164
if __name__ == "__main__":
162
165
main()
163
166
`
167
+ return fmt .Sprintf (template , invoke )
168
+ }
0 commit comments