-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (52 loc) · 1.07 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
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"bufio"
"fmt"
"log"
"os"
"time"
"github.com/stshontikidis/image_check/config"
"github.com/stshontikidis/image_check/docker"
"github.com/stshontikidis/image_check/github"
)
func main() {
cfg := config.GetConfig()
file, err := os.OpenFile("/tmp/digest", os.O_CREATE|os.O_RDWR, 0664)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Scan()
digest := scanner.Text()
for {
fmt.Println("looping")
loop(&digest, file, cfg)
time.Sleep(time.Hour)
}
}
func loop(digest *string, file *os.File, cfg *config.Config) {
newDigest, err := docker.GetDigest(cfg.DockerRepo, cfg.DockerTag)
if err != nil {
log.Fatal(err)
}
if *digest != newDigest {
fmt.Println("no match!!")
err := github.Dispatch(cfg.GithubRepo,
cfg.GithubRef,
cfg.GithubWorkflowID,
cfg.GithubToken,
newDigest,
)
if err != nil {
log.Fatal(err)
}
wipeAndWrite(file, newDigest)
*digest = newDigest
}
}
func wipeAndWrite(f *os.File, contents string) {
f.Truncate(0)
f.Seek(0, 0)
f.WriteString(contents)
}