Skip to content

Commit d3f1dd8

Browse files
author
Sean Connole
committed
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
1 parent 4798d96 commit d3f1dd8

File tree

6 files changed

+86
-83
lines changed

6 files changed

+86
-83
lines changed

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
FROM debian
1+
ARG GO_VERSION=1.22
2+
FROM golang:${GO_VERSION} AS build
23

3-
RUN apt update && apt install -y ca-certificates curl
4+
RUN mkdir -p /go/src/github.com/contentsquare/chproxy
5+
WORKDIR /go/src/github.com/contentsquare/chproxy
6+
COPY . ./
7+
ARG EXT_BUILD_TAG
8+
ENV EXT_BUILD_TAG=${EXT_BUILD_TAG}
9+
RUN make release-build
10+
RUN ls -al /go/src/github.com/contentsquare/chproxy
411

5-
COPY chproxy /
12+
FROM alpine
13+
RUN apk add --no-cache curl ca-certificates
14+
COPY --from=build /go/src/github.com/contentsquare/chproxy/chproxy* /
615

716
EXPOSE 9090
817

9-
ENTRYPOINT ["/chproxy"]
18+
ENTRYPOINT [ "/chproxy" ]
1019
CMD [ "--help" ]

Dockerfile_boringcrypto

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ${UBUNTU_IMAGE} AS build
33

44
ENV GOPATH=/gocode
55
ENV PATH=$PATH:$GOPATH/bin
6-
ENV GOVERSION=1.21
6+
ENV GO_VERSION=1.22
77

88
RUN mkdir /scr
99
WORKDIR /src
@@ -17,21 +17,23 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
1717
&& add-apt-repository -y ppa:longsleep/golang-backports \
1818
&& apt-get update \
1919
&& apt-get install -y --no-install-recommends \
20-
golang-$GOVERSION-go \
20+
golang-$GO_VERSION-go \
2121
golang-golang-x-tools \
2222
&& apt-get autoremove -y \
2323
&& apt-get remove -y \
2424
apt-utils \
2525
software-properties-common
2626

2727
# Create symbolic link
28-
RUN ln -s /usr/lib/go-$GOVERSION /gocode
28+
RUN ln -s /usr/lib/go-$GO_VERSION /gocode
2929

3030
# tools
3131
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
3232
git \
3333
make \
34-
tzdata
34+
tzdata \
35+
curl \
36+
ca-certificates
3537

3638
FROM build
3739

Dockerfile_build

Lines changed: 0 additions & 18 deletions
This file was deleted.

dockerfile_version_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"os"
6+
"regexp"
7+
"testing"
8+
)
9+
10+
func getVersionFromFile(filename string, searchPhrase string) (string, error) {
11+
file, err := os.Open(filename)
12+
if err != nil {
13+
return "", err
14+
}
15+
defer file.Close()
16+
17+
scanner := bufio.NewScanner(file)
18+
re := regexp.MustCompile(searchPhrase) // Regex to capture Go version
19+
for scanner.Scan() {
20+
line := scanner.Text()
21+
matches := re.FindStringSubmatch(line)
22+
if len(matches) > 1 {
23+
return matches[1], nil
24+
}
25+
}
26+
27+
return "", scanner.Err()
28+
}
29+
30+
// Test function to check if Go version in go.mod matches Dockerfile
31+
func TestGoVersionMatching(t *testing.T) {
32+
goModVersionSearchPhrase := `^go\s+(\d+\.\d+)`
33+
goModVersion, err := getVersionFromFile("go.mod", goModVersionSearchPhrase)
34+
if err != nil {
35+
t.Fatalf("Error getting Go version from go.mod: %v", err)
36+
}
37+
38+
dockerFileVersionSearchPhrase := "GO_VERSION=(.*)"
39+
dockerfileVersion, err := getVersionFromFile("Dockerfile", dockerFileVersionSearchPhrase)
40+
if err != nil {
41+
t.Fatalf("Error getting Go version from Dockerfile: %v", err)
42+
}
43+
44+
if goModVersion != dockerfileVersion {
45+
t.Errorf("Go version mismatch: go.mod (%s), Dockerfile (%s)", goModVersion, dockerfileVersion)
46+
}
47+
}
48+
49+
// Test function to check if Go version in go.mod matches Dockerfile_boringcrypto
50+
func TestGoVersionMatchingBoringCrypto(t *testing.T) {
51+
goModVersionSearchPhrase := `^go\s+(\d+\.\d+)`
52+
goModVersion, err := getVersionFromFile("go.mod", goModVersionSearchPhrase)
53+
if err != nil {
54+
t.Fatalf("Error getting Go version from go.mod: %v", err)
55+
}
56+
57+
dockerFileVersionSearchPhrase := "GO_VERSION=(.*)"
58+
dockerfileVersion, err := getVersionFromFile("Dockerfile_boringcrypto", dockerFileVersionSearchPhrase)
59+
if err != nil {
60+
t.Fatalf("Error getting Go version from Dockerfile_boringcrypto: %v", err)
61+
}
62+
63+
if goModVersion != dockerfileVersion {
64+
t.Errorf("Go version mismatch: go.mod (%s), Dockerfile (%s)", goModVersion, dockerfileVersion)
65+
}
66+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/contentsquare/chproxy
22

3-
go 1.19
3+
go 1.22
44

55
require (
66
github.com/alicebob/miniredis/v2 v2.21.0

0 commit comments

Comments
 (0)