Skip to content

Commit 253f7b8

Browse files
committed
Send go runtime information for a function.
Signed-off-by: David Calavera <[email protected]>
1 parent b433c81 commit 253f7b8

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

go/plumbing/operations/upload_deploy_function_parameters.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/porcelain/deploy.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
403403
_, operationError = n.Operations.UploadDeployFile(params, authInfo)
404404
}
405405
case functionUpload:
406-
params := operations.NewUploadDeployFunctionParams().WithDeployID(d.ID).WithName(f.Name).WithFileBody(f)
406+
params := operations.NewUploadDeployFunctionParams().WithDeployID(d.ID).WithName(f.Name).WithFileBody(f).WithRuntime(&f.Runtime)
407407
if timeout != 0 {
408408
params.SetTimeout(timeout)
409409
}
@@ -528,24 +528,28 @@ func bundle(functionDir string, observer DeployObserver) (*deployFiles, error) {
528528
return functions, nil
529529
}
530530

531-
func newFunctionFile(filePath string, i os.FileInfo, tp string, observer DeployObserver) (*FileBundle, error) {
531+
func newFunctionFile(filePath string, i os.FileInfo, runtime string, observer DeployObserver) (*FileBundle, error) {
532532
file := &FileBundle{
533533
Name: strings.TrimSuffix(i.Name(), filepath.Ext(i.Name())),
534-
Runtime: tp,
534+
Runtime: runtime,
535535
}
536536

537537
s := sha256.New()
538-
buf := new(bytes.Buffer)
539-
archive := zip.NewWriter(buf)
540-
fileHeader, err := archive.Create(i.Name())
538+
539+
fileEntry, err := os.Open(filePath)
541540
if err != nil {
542541
return nil, err
543542
}
544-
fileEntry, err := os.Open(filePath)
543+
defer fileEntry.Close()
544+
545+
buf := new(bytes.Buffer)
546+
archive := zip.NewWriter(buf)
547+
548+
fileHeader, err := createHeader(archive, i, runtime)
545549
if err != nil {
546550
return nil, err
547551
}
548-
defer fileEntry.Close()
552+
549553
if _, err = io.Copy(fileHeader, fileEntry); err != nil {
550554
return nil, err
551555
}
@@ -595,3 +599,15 @@ func ignoreFile(rel string) bool {
595599
}
596600
return false
597601
}
602+
603+
func createHeader(archive *zip.Writer, i os.FileInfo, runtime string) (io.Writer, error) {
604+
if runtime == goRuntime {
605+
return archive.CreateHeader(&zip.FileHeader{
606+
CreatorVersion: 3 << 8, // indicates Unix
607+
ExternalAttrs: 0777 << 16, // -rwxrwxrwx file permissions
608+
Name: i.Name(),
609+
Method: zip.Deflate,
610+
})
611+
}
612+
return archive.Create(i.Name())
613+
}

swagger.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@ paths:
813813
type: string
814814
in: path
815815
required: true
816+
- name: runtime
817+
type: string
818+
in: query
816819
- name: file_body
817820
in: body
818821
schema:

ui/swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@
389389
"in": "path",
390390
"required": true
391391
},
392+
{
393+
"type": "string",
394+
"name": "runtime",
395+
"in": "query"
396+
},
392397
{
393398
"name": "file_body",
394399
"in": "body",

0 commit comments

Comments
 (0)