-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile_test.go
More file actions
77 lines (72 loc) · 2.26 KB
/
Copy pathdockerfile_test.go
File metadata and controls
77 lines (72 loc) · 2.26 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package stint_test
import (
"os"
"strings"
"testing"
)
func TestProductionDockerfileDoesNotDownloadTestOnlyModuleGraph(t *testing.T) {
sourceBytes, err := os.ReadFile("Dockerfile")
if err != nil {
t.Fatal(err)
}
source := string(sourceBytes)
if strings.Contains(source, "go mod download") {
t.Fatal("production Docker build should not run go mod download because it pulls test-only dependencies")
}
if !strings.Contains(source, "go build -o /out/stint ./cmd/server") {
t.Fatal("production Docker build should still build the server binary")
}
}
func TestDockerfileHealthchecksMatchRuntimeTargets(t *testing.T) {
sourceBytes, err := os.ReadFile("Dockerfile")
if err != nil {
t.Fatal(err)
}
source := string(sourceBytes)
if !strings.Contains(source, "HEALTHCHECK") || !strings.Contains(source, "/healthz") {
t.Fatal("api image should publish an HTTP /healthz Dockerfile healthcheck")
}
collector := source[strings.Index(source, "FROM api AS collector"):]
if !strings.Contains(collector, "HEALTHCHECK NONE") {
t.Fatal("collector target should disable the inherited api HTTP healthcheck")
}
}
func TestWebDockerfileHealthcheckUsesReachableNextBinding(t *testing.T) {
sourceBytes, err := os.ReadFile("web/Dockerfile")
if err != nil {
t.Fatal(err)
}
source := string(sourceBytes)
if !strings.Contains(source, "ENV HOSTNAME=0.0.0.0") {
t.Fatal("web image should bind Next to all interfaces so its container healthcheck can reach 127.0.0.1")
}
if !strings.Contains(source, "http://127.0.0.1:3000/healthz") {
t.Fatal("web image should healthcheck the lightweight /healthz route")
}
}
func TestGitHubReleaseWorkflowPublishesStintBinaries(t *testing.T) {
sourceBytes, err := os.ReadFile(".github/workflows/release.yml")
if err != nil {
t.Fatal(err)
}
source := string(sourceBytes)
for _, want := range []string{
"on:",
"tags:",
"v*",
"cmd/stint",
"goos: darwin",
"goos: linux",
"goarch: amd64",
"goarch: arm64",
"stint_${VERSION}_${GOOS}_${GOARCH}.tar.gz",
"softprops/action-gh-release",
} {
if !strings.Contains(source, want) {
t.Fatalf("release workflow missing %q", want)
}
}
if strings.Contains(source, "go test ./...") {
t.Fatal("release workflow should not run the full testcontainers test suite just to package binaries")
}
}