-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (39 loc) · 1.08 KB
/
main.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
45
46
47
48
49
50
51
52
package main
import (
"context"
"fmt"
"os"
"github.com/docker/docker/client"
githubactions "github.com/sethvargo/go-githubactions"
)
func getDockerClient() (*client.Client, error) {
return client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
}
func doesImageExist(ctx context.Context, client *client.Client, image, authStr string) bool {
_, err := client.DistributionInspect(ctx, image, authStr)
return err == nil
}
func main() {
ctx := context.Background()
action := githubactions.New()
config, err := NewFromInputs(action)
if err != nil {
action.Fatalf("Failed to get inputs: %s", err)
}
action.Debugf(config.String())
client, err := getDockerClient()
if err != nil {
action.Fatalf("Failed to get docker client: %s", err)
}
authStr, err := config.GetAuthString()
if err != nil {
action.Fatalf("Failed to get auth string: %s", err)
}
imageExists := doesImageExist(ctx, client, config.image, authStr)
client.Close()
if imageExists {
fmt.Printf("Image %s exists\n", config.image)
os.Exit(0)
}
action.Fatalf("Image does not exist")
}