manifests.go 683 Bytes
Newer Older
Michael Yang's avatar
Michael Yang committed
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
package server

import (
	"bytes"
	"encoding/json"
	"os"
	"path/filepath"
)

func WriteManifest(name string, config *Layer, layers []*Layer) error {
	manifest := ManifestV2{
		SchemaVersion: 2,
		MediaType:     "application/vnd.docker.distribution.manifest.v2+json",
		Config:        config,
		Layers:        layers,
	}

	var b bytes.Buffer
	if err := json.NewEncoder(&b).Encode(manifest); err != nil {
		return err
	}

	modelpath := ParseModelPath(name)
	manifestPath, err := modelpath.GetManifestPath()
	if err != nil {
		return err
	}

Michael Yang's avatar
Michael Yang committed
29
	if err := os.MkdirAll(filepath.Dir(manifestPath), 0o755); err != nil {
Michael Yang's avatar
Michael Yang committed
30
31
32
		return err
	}

Michael Yang's avatar
Michael Yang committed
33
	return os.WriteFile(manifestPath, b.Bytes(), 0o644)
Michael Yang's avatar
Michael Yang committed
34
}