-
Notifications
You must be signed in to change notification settings - Fork 9
/
golang.go
57 lines (46 loc) · 1.63 KB
/
golang.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package integrations
import (
"context"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/parsing/integration/api"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
)
func Register() {
api.RegisterIntegration[*schema.GoIntegration, *schema.GoIntegration](impl{})
}
type impl struct {
api.DefaultBinaryTestIntegration[*schema.GoIntegration]
}
func (impl) ApplyToServer(ctx context.Context, env *schema.Environment, pl pkggraph.PackageLoader, pkg *pkggraph.Package, data *schema.GoIntegration) error {
if pkg.Server == nil {
// Can't happen with the current syntax.
return fnerrors.NewWithLocation(pkg.Location, "go integration requires a server")
}
goPkg := data.Pkg
if goPkg == "" {
goPkg = "."
}
return api.SetServerBinary(pkg,
&schema.LayeredImageBuildPlan{
LayerBuildPlan: []*schema.ImageBuildPlan{{GoPackage: goPkg}},
},
[]string{"/" + pkg.Server.Name})
}
func (impl) CreateBinary(ctx context.Context, env *schema.Environment, pl pkggraph.PackageLoader, loc pkggraph.Location, data *schema.GoIntegration) (*schema.Binary, error) {
goPkg := data.Pkg
if goPkg == "" {
goPkg = "."
}
// TODO consider validating that goPkg is valid (e.g. a Go test and a Go server cannot live in the same package)
return &schema.Binary{
BuildPlan: &schema.LayeredImageBuildPlan{
LayerBuildPlan: []*schema.ImageBuildPlan{{
GoPackage: goPkg,
}},
},
}, nil
}