-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
44 lines (37 loc) · 1.04 KB
/
version.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
package proto
import (
"context"
"embed"
"io/fs"
"gopkg.in/yaml.v3"
"github.com/Masterminds/semver"
"github.com/codefly-dev/core/resources"
"github.com/codefly-dev/core/wool"
)
func version(ctx context.Context) (string, error) {
w := wool.Get(ctx).In("proto.version")
content, err := fs.ReadFile(infoFS, "info.codefly.yaml")
if err != nil {
return "", w.Wrapf(err, "cannot read file")
}
var info Info
if err = yaml.Unmarshal(content, &info); err != nil {
return "", w.Wrapf(err, "cannot unmarshal file")
}
// check we have a valid semantic version
v, err := semver.NewVersion(info.Version)
if err != nil {
return "", w.Wrapf(err, "cannot parse version <%s>", info.Version)
}
return v.String(), nil
}
func CompanionImage(ctx context.Context) (*resources.DockerImage, error) {
w := wool.Get(ctx).In("proto.CompanionImage")
v, err := version(ctx)
if err != nil {
return nil, w.Wrapf(err, "cannot get version")
}
return &resources.DockerImage{Name: "codeflydev/proto", Tag: v}, nil
}
//go:embed info.codefly.yaml
var infoFS embed.FS