-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (43 loc) · 1.35 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
package main
import (
"os"
"time"
"gitlab.com/dj_arbz/traextor/acme"
"gitlab.com/dj_arbz/traextor/internal"
)
func main() {
// Load config from environmental variables
acmeFile := internal.GetEnv("ACME_FILE", "/acme.json")
outputDir := internal.GetEnv("OUTPUT_DIR", "/certificates")
// Create certificate output dir
if err := internal.CreateDir(outputDir); err != nil {
internal.Log("Failed to create output dir %s: %v", outputDir, err)
os.Exit(1)
}
if internal.GetEnv("BUILD_TEST", "") != "" {
internal.Log("Dockerfile is running.")
internal.Log("ACME is: %s", acmeFile)
internal.Log("Output directory is: %s", outputDir)
os.Exit(0)
}
// Check that the given acme.json file exists
for !internal.CheckFileExists(acmeFile) {
internal.Log("%s does not exist!", acmeFile)
// sleep for 30 seconds
time.Sleep(30 * 1000 * time.Millisecond)
}
internal.Log("%s found!", acmeFile)
internal.Log("Your certificates will be exported to %s", outputDir)
// Create a new ACME store
ACME := acme.New(internal.GetEnv("TRAEFIK_VERSION", "2"))
if err := ACME.LoadFromFile(acmeFile); err != nil {
internal.Log("Failed to load %s: %v", acmeFile, err)
os.Exit(1)
}
if err := ACME.Generate(outputDir); err != nil {
internal.Log("Failed to generate certificates: %v", err)
os.Exit(1)
}
ACME.Watch(acmeFile, outputDir)
internal.Log("Done?")
}