-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (61 loc) · 1.77 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
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/go-git/go-git/v5"
. "github.com/go-git/go-git/v5/_examples"
)
func main() {
for {
CheckArgs("<path>")
path := os.Args[1]
// We instantiate a new repository targeting the given path (the .git folder)
r, err := git.PlainOpen(path)
CheckIfError(err)
// Get the working directory for the repository
w, err := r.Worktree()
CheckIfError(err)
status := w.Pull(&git.PullOptions{})
currentStatus := status.Error()
if currentStatus == "already up-to-date" {
fmt.Println("no changes")
} else {
fmt.Println("changes detected!")
command := "sh"
script := "./test.sh"
image := "java17_test:edge"
repo := "https://github.com/ryanbourdais/ImageProvisionerBackend.git"
cmd := exec.Command(command, script, image, repo)
stdout, err := cmd.Output()
println(err)
time.Sleep(5 * time.Second)
content, err := os.ReadFile("container.txt")
if err != nil {
log.Fatal(err)
}
fmt.Println("container id:")
fmt.Println(string(content))
containerID := strings.Trim(string(content), "\n")
repoName := "ImageProvisionerBackend"
runCmd := exec.Command("sh", "./exec.sh", containerID, repo, repoName)
out, err := runCmd.Output()
println(err)
println(out)
if err != nil {
fmt.Println(err.Error()) //test
return
}
fmt.Print(string(stdout))
}
time.Sleep(10 * time.Second)
}
}
//test commen
//run this script in a base docker image to fire off new docker images with the proper image
//have a db that has a bool for "changed" this script changes that value and fires off the corresponding image with the env var of the repo link then changes "changed" to false
//image runs CI.sh and outputs a directory
//hook all of this up to a frontend