-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update dockerfile, add tests for dockerfile
Added tests for dockerfile to ensure that GoVersions in dockerfiles stay in sync with Go.mod version. Updated dockerfile to use a more reliable base image. Install ca-certificates and curl
- Loading branch information
Sean Connole
committed
Oct 22, 2024
1 parent
4798d96
commit d3f1dd8
Showing
6 changed files
with
86 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
FROM debian | ||
ARG GO_VERSION=1.22 | ||
FROM golang:${GO_VERSION} AS build | ||
|
||
RUN apt update && apt install -y ca-certificates curl | ||
RUN mkdir -p /go/src/github.com/contentsquare/chproxy | ||
WORKDIR /go/src/github.com/contentsquare/chproxy | ||
COPY . ./ | ||
ARG EXT_BUILD_TAG | ||
ENV EXT_BUILD_TAG=${EXT_BUILD_TAG} | ||
RUN make release-build | ||
RUN ls -al /go/src/github.com/contentsquare/chproxy | ||
|
||
COPY chproxy / | ||
FROM alpine | ||
RUN apk add --no-cache curl ca-certificates | ||
COPY --from=build /go/src/github.com/contentsquare/chproxy/chproxy* / | ||
|
||
EXPOSE 9090 | ||
|
||
ENTRYPOINT ["/chproxy"] | ||
ENTRYPOINT [ "/chproxy" ] | ||
CMD [ "--help" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func getVersionFromFile(filename string, searchPhrase string) (string, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
re := regexp.MustCompile(searchPhrase) // Regex to capture Go version | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
matches := re.FindStringSubmatch(line) | ||
if len(matches) > 1 { | ||
return matches[1], nil | ||
} | ||
} | ||
|
||
return "", scanner.Err() | ||
} | ||
|
||
// Test function to check if Go version in go.mod matches Dockerfile | ||
func TestGoVersionMatching(t *testing.T) { | ||
goModVersionSearchPhrase := `^go\s+(\d+\.\d+)` | ||
goModVersion, err := getVersionFromFile("go.mod", goModVersionSearchPhrase) | ||
if err != nil { | ||
t.Fatalf("Error getting Go version from go.mod: %v", err) | ||
} | ||
|
||
dockerFileVersionSearchPhrase := "GO_VERSION=(.*)" | ||
dockerfileVersion, err := getVersionFromFile("Dockerfile", dockerFileVersionSearchPhrase) | ||
if err != nil { | ||
t.Fatalf("Error getting Go version from Dockerfile: %v", err) | ||
} | ||
|
||
if goModVersion != dockerfileVersion { | ||
t.Errorf("Go version mismatch: go.mod (%s), Dockerfile (%s)", goModVersion, dockerfileVersion) | ||
} | ||
} | ||
|
||
// Test function to check if Go version in go.mod matches Dockerfile_boringcrypto | ||
func TestGoVersionMatchingBoringCrypto(t *testing.T) { | ||
goModVersionSearchPhrase := `^go\s+(\d+\.\d+)` | ||
goModVersion, err := getVersionFromFile("go.mod", goModVersionSearchPhrase) | ||
if err != nil { | ||
t.Fatalf("Error getting Go version from go.mod: %v", err) | ||
} | ||
|
||
dockerFileVersionSearchPhrase := "GO_VERSION=(.*)" | ||
dockerfileVersion, err := getVersionFromFile("Dockerfile_boringcrypto", dockerFileVersionSearchPhrase) | ||
if err != nil { | ||
t.Fatalf("Error getting Go version from Dockerfile_boringcrypto: %v", err) | ||
} | ||
|
||
if goModVersion != dockerfileVersion { | ||
t.Errorf("Go version mismatch: go.mod (%s), Dockerfile (%s)", goModVersion, dockerfileVersion) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/contentsquare/chproxy | ||
|
||
go 1.19 | ||
go 1.22 | ||
|
||
require ( | ||
github.com/alicebob/miniredis/v2 v2.21.0 | ||
|
Oops, something went wrong.