Skip to content

Commit 2902199

Browse files
authored
fix: convert all paths to relative for deploy (#3403)
* fix: convert all paths to relative for deploy * chore: move log statement to callback
1 parent 2d3bd36 commit 2902199

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

pkg/function/deploy.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func (s *EdgeRuntimeAPI) Deploy(ctx context.Context, functionConfig config.Funct
2828
if s.eszip != nil {
2929
return s.UpsertFunctions(ctx, functionConfig)
3030
}
31+
// Convert all paths in functions config to relative when using api deploy
3132
var toDeploy []api.FunctionDeployMetadata
3233
for slug, fc := range functionConfig {
3334
if !fc.Enabled {
@@ -36,13 +37,13 @@ func (s *EdgeRuntimeAPI) Deploy(ctx context.Context, functionConfig config.Funct
3637
}
3738
meta := api.FunctionDeployMetadata{
3839
Name: &slug,
39-
EntrypointPath: filepath.ToSlash(fc.Entrypoint),
40-
ImportMapPath: cast.Ptr(filepath.ToSlash(fc.ImportMap)),
40+
EntrypointPath: toRelPath(fc.Entrypoint),
41+
ImportMapPath: cast.Ptr(toRelPath(fc.ImportMap)),
4142
VerifyJwt: &fc.VerifyJWT,
4243
}
4344
files := make([]string, len(fc.StaticFiles))
4445
for i, sf := range fc.StaticFiles {
45-
files[i] = filepath.ToSlash(sf)
46+
files[i] = toRelPath(sf)
4647
}
4748
meta.StaticPatterns = &files
4849
toDeploy = append(toDeploy, meta)
@@ -57,16 +58,27 @@ func (s *EdgeRuntimeAPI) Deploy(ctx context.Context, functionConfig config.Funct
5758
return s.bulkUpload(ctx, toDeploy, fsys)
5859
}
5960

61+
func toRelPath(fp string) string {
62+
if filepath.IsAbs(fp) {
63+
if cwd, err := os.Getwd(); err == nil {
64+
if relPath, err := filepath.Rel(cwd, fp); err == nil {
65+
fp = relPath
66+
}
67+
}
68+
}
69+
return filepath.ToSlash(fp)
70+
}
71+
6072
func (s *EdgeRuntimeAPI) bulkUpload(ctx context.Context, toDeploy []api.FunctionDeployMetadata, fsys fs.FS) error {
6173
jq := queue.NewJobQueue(s.maxJobs)
6274
toUpdate := make([]api.BulkUpdateFunctionBody, len(toDeploy))
6375
for i, meta := range toDeploy {
64-
fmt.Fprintln(os.Stderr, "Deploying Function:", *meta.Name)
6576
param := api.V1DeployAFunctionParams{
6677
Slug: meta.Name,
6778
BundleOnly: cast.Ptr(true),
6879
}
6980
bundle := func() error {
81+
fmt.Fprintln(os.Stderr, "Deploying Function:", *meta.Name)
7082
resp, err := s.upload(ctx, param, meta, fsys)
7183
if err != nil {
7284
return err

0 commit comments

Comments
 (0)