-
Notifications
You must be signed in to change notification settings - Fork 318
/
prebuild.go
43 lines (35 loc) · 1.12 KB
/
prebuild.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
package devcontainer
import (
"context"
"fmt"
"github.com/loft-sh/devpod/pkg/devcontainer/config"
"github.com/loft-sh/devpod/pkg/image"
"github.com/pkg/errors"
)
func (r *Runner) Build(ctx context.Context, options config.BuildOptions) (string, error) {
substitutedConfig, _, err := r.prepare()
if err != nil {
return "", err
}
// check if we need to build container
buildInfo, err := r.build(ctx, substitutedConfig, options)
if err != nil {
return "", errors.Wrap(err, "build image")
}
// prebuild already exists
prebuildImage := options.Repository + ":" + buildInfo.PrebuildHash
if buildInfo.ImageName == prebuildImage {
return buildInfo.ImageName, nil
}
// check if we can push image
err = image.CheckPushPermissions(prebuildImage)
if err != nil {
return "", fmt.Errorf("cannot push to repository %s. Please make sure you are logged into the registry and credentials are available. (Error: %w)", prebuildImage, err)
}
// push the image to the registry
err = r.Driver.PushDevContainer(context.TODO(), prebuildImage)
if err != nil {
return "", errors.Wrap(err, "push image")
}
return prebuildImage, nil
}