Skip to content

Commit 43a30d9

Browse files
author
mirkobrombin
committed
add ref doc
1 parent 7e1cf22 commit 43a30d9

File tree

5 files changed

+76
-49
lines changed

5 files changed

+76
-49
lines changed

README.md

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,10 @@ and [Albius](https://github.com/vanilla-os/albius).
1616

1717
## Usage
1818

19-
```go
20-
package main
19+
You can see examples of how to use Prometheus in the [examples](examples)
20+
directory.
2121

22-
import (
23-
"fmt"
24-
25-
"github.com/containers/storage/pkg/reexec"
26-
"github.com/vanilla-os/prometheus"
27-
)
28-
29-
func main() {
30-
if reexec.Init() {
31-
return
32-
}
33-
34-
pmt, err := prometheus.NewPrometheus("storage", "overlay")
35-
if err != nil {
36-
panic(err)
37-
}
38-
39-
manifest, err := pmt.PullImage(
40-
"registry.vanillaos.org/vanillaos/desktop:main", // image name
41-
"vos-desktop", // stored image name
42-
)
43-
if err != nil {
44-
panic(err)
45-
}
46-
47-
fmt.Printf("Image pulled with digest %s\n", manifest.Config.Digest)
48-
49-
image, err := pmt.GetImageByDigest(manifest.Config.Digest)
50-
if err != nil {
51-
panic(err)
52-
}
53-
54-
mountPoint, err := pmt.MountImage(image.TopLayer)
55-
if err != nil {
56-
panic(err)
57-
}
58-
59-
fmt.Printf("Image mounted at %s\n", mountPoint)
60-
61-
if err := pmt.UnmountImage(mountPoint); err != nil {
62-
panic(err)
63-
}
64-
}
65-
```
22+
A reference documentation is available [here](docs/prometheus_docs.md).
6623

6724
## License
6825

docs/prometheus_docs.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package prometheus // import "github.com/vanilla-os/prometheus"
2+
3+
4+
VARIABLES
5+
6+
var version = "0.1.4"
7+
8+
FUNCTIONS
9+
10+
func main()
11+
12+
TYPES
13+
14+
type OciManifest struct {
15+
SchemaVersion int `json:"schemaVersion"`
16+
MediaType string `json:"mediaType"`
17+
Config OciManifestConfig `json:"config"`
18+
Layers []OciManifestConfig `json:"layers"`
19+
}
20+
21+
type OciManifestConfig struct {
22+
MediaType string `json:"mediaType"`
23+
Size int `json:"size"`
24+
Digest string `json:"digest"`
25+
}
26+
27+
type Prometheus struct {
28+
Store cstorage.Store
29+
}
30+
31+
func NewPrometheus(root, graphDriverName string) (*Prometheus, error)
32+
NewPrometheus creates a new Prometheus instance, note that currently *
33+
Prometheus only works with custom stores, so you need to pass the * root
34+
graphDriverName to create a new one.
35+
36+
func (p *Prometheus) BuildContainerFile(dockerfilePath string, imageName string) (cstorage.Image, error)
37+
BuildContainerFile builds a dockerfile and returns the manifest of the built
38+
* image and an error if any.
39+
40+
func (p *Prometheus) DoesImageExist(digest string) (bool, error)
41+
DoesImageExist checks if an image exists in the Prometheus store by its *
42+
digest. It returns a boolean indicating if the image exists and an error *
43+
if any.
44+
45+
func (p *Prometheus) GetImageByDigest(digest string) (cstorage.Image, error)
46+
GetImageByDigest returns an image from the Prometheus store by its digest.
47+
48+
func (p *Prometheus) MountImage(layerId string) (string, error)
49+
MountImage mounts an image from the Prometheus store by its main layer *
50+
digest. It returns the mount path and an error if any.
51+
52+
func (p *Prometheus) PullImage(imageName string, dstName string) (*OciManifest, error)
53+
PullImage pulls an image from a remote registry and stores it in the *
54+
Prometheus store. It returns the manifest of the pulled image and an *
55+
error if any. Note that the 'docker://' prefix is automatically added * to
56+
the imageName to make it compatible with the alltransports.ParseImageName *
57+
method.
58+
59+
func (p *Prometheus) UnMountImage(layerId string, force bool) (bool, error)
60+
UnMountImage unmounts an image from the Prometheus store by its main layer *
61+
digest. It returns a boolean indicating if the unmount was successful and *
62+
an error if any.
63+

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,20 @@ require (
110110
github.com/vbauerster/mpb/v8 v8.3.0 // indirect
111111
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
112112
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
113+
github.com/yuin/goldmark v1.4.13 // indirect
113114
go.etcd.io/bbolt v1.3.7 // indirect
114115
go.mongodb.org/mongo-driver v1.11.3 // indirect
115116
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
116117
go.opencensus.io v0.24.0 // indirect
117118
golang.org/x/crypto v0.8.0 // indirect
118119
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
119-
golang.org/x/mod v0.9.0 // indirect
120+
golang.org/x/mod v0.10.0 // indirect
120121
golang.org/x/net v0.9.0 // indirect
121122
golang.org/x/sync v0.1.0 // indirect
122123
golang.org/x/sys v0.7.0 // indirect
123124
golang.org/x/term v0.7.0 // indirect
124125
golang.org/x/text v0.9.0 // indirect
125-
golang.org/x/tools v0.7.0 // indirect
126+
golang.org/x/tools v0.8.0 // indirect
126127
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
127128
google.golang.org/grpc v1.54.0 // indirect
128129
google.golang.org/protobuf v1.30.0 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,8 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul
920920
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
921921
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
922922
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
923+
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
924+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
923925
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs=
924926
github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA=
925927
github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg=
@@ -1004,6 +1006,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
10041006
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
10051007
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
10061008
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
1009+
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
1010+
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
10071011
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
10081012
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
10091013
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -1233,6 +1237,8 @@ golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
12331237
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
12341238
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
12351239
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
1240+
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
1241+
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
12361242
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12371243
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12381244
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package prometheus
22

3-
var version = "0.1.3"
3+
var version = "0.1.4"
44

55
func main() {}

0 commit comments

Comments
 (0)