-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseimage.go
More file actions
52 lines (47 loc) · 1.7 KB
/
Copy pathbaseimage.go
File metadata and controls
52 lines (47 loc) · 1.7 KB
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
package main
import (
"fmt"
"os"
"os/exec"
)
// baseImageTag may be injected via ldflags by downstream release builds. The
// OSS release pipeline leaves it as "dev" so resolveBaseImage falls back to the
// public :latest base image instead of requiring this repo to publish matching
// base-image tags.
var baseImageTag = "dev"
const baseImageRepo = "ramseymcgrath/back2base-base"
// resolveBaseImage returns the fully-qualified base image reference that the
// compose runtime should build on top of. Precedence:
// 1. BACK2BASE_BASE_IMAGE env var (explicit caller override — supports local
// testing against a custom image).
// 2. The binary's embedded baseImageTag, when a downstream build chooses to
// pin one.
// 3. :latest — OSS releases and local builds.
func resolveBaseImage() string {
if v := os.Getenv("BACK2BASE_BASE_IMAGE"); v != "" {
return v
}
if baseImageTag == "" || baseImageTag == "dev" {
return baseImageRepo + ":latest"
}
return baseImageRepo + ":" + baseImageTag
}
// ensureBaseImage makes sure the given image exists in the local Docker
// daemon, pulling it if not. Silent on cache hit; on miss it streams the
// pull to stderr so the user sees why the first launch takes a minute.
//
// Called before compose build/run so first launch pulls the base image when the
// daemon has not already cached it.
func ensureBaseImage(image string) error {
if err := exec.Command("docker", "image", "inspect", image).Run(); err == nil {
return nil
}
fmt.Fprintf(os.Stderr, ":: Pulling %s\n", image)
cmd := exec.Command("docker", "pull", image)
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("pull %s: %w", image, err)
}
return nil
}