From b8a66242d606e78c3faef64e8ef4036b9bbd2dbd Mon Sep 17 00:00:00 2001 From: Anand Francis Joseph Date: Thu, 12 Oct 2023 15:24:07 +0530 Subject: [PATCH 1/3] Added go based file server for hosting KAM binaries Signed-off-by: Anand Francis Joseph --- Dockerfile.serve | 20 ++++++++++++-------- tools/kam-serve/main.go | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tools/kam-serve/main.go diff --git a/Dockerfile.serve b/Dockerfile.serve index 0825d284e..c60ab7e24 100644 --- a/Dockerfile.serve +++ b/Dockerfile.serve @@ -1,16 +1,20 @@ -FROM openshift/origin-release:golang-1.19 AS builder +FROM openshift/origin-release:golang-1.21 AS builder WORKDIR /tmp/kam COPY . . -RUN make all_platforms -RUN make checksum +RUN make all_platforms && \ + make checksum && \ + cd tools/kam-serve && \ + go build -o /tmp/kam-serve main.go && \ + mkdir -p /tmp/workdir/kam-root/kam && \ + cp config/index.html /tmp/workdir/kam-root/index.html && \ + mv /tmp/kam/dist/* /tmp/workdir/kam-root/kam/ -FROM registry.redhat.io/rhel8/httpd-24 +FROM scratch # Add application sources -RUN mkdir -p /var/www/html/kam -COPY --from=builder /tmp/kam/dist/kam_windows_amd64.exe /tmp/kam/dist/kam_windows_arm64.exe /tmp/kam/dist/kam_linux_amd64 /tmp/kam/dist/kam_linux_arm64 /tmp/kam/dist/kam_linux_ppc64le /tmp/kam/dist/kam_linux_s390x /tmp/kam/dist/kam_darwin_amd64 /tmp/kam/dist/kam_darwin_arm64 /tmp/kam/dist/kam_checksums.txt /var/www/html/kam/ -COPY config/index.html /var/www/html/index.html +COPY --from=builder /tmp/workdir/ /tmp/ +COPY --from=builder /tmp/kam-serve / # The run script uses standard ways to run the application -CMD run-httpd +ENTRYPOINT ["/kam-serve"] diff --git a/tools/kam-serve/main.go b/tools/kam-serve/main.go new file mode 100644 index 000000000..67511c375 --- /dev/null +++ b/tools/kam-serve/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "net/http" +) + +func main() { + fs := http.FileServer(http.Dir("/tmp/kam-root")) + + fmt.Println("Listening on port 9000 to serve directory contents /tmp/kam-root") + + err := http.ListenAndServe(":9000", fs) + + if err != nil { + panic(err) + } +} From 553036d2fdbeab4d341e90f11c2ab143ee7f37a5 Mon Sep 17 00:00:00 2001 From: Anand Francis Joseph Date: Thu, 12 Oct 2023 17:06:20 +0530 Subject: [PATCH 2/3] Added new tools kam-serve for acting as a file server and fixed Dockerfile Signed-off-by: Anand Francis Joseph --- Dockerfile.serve | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile.serve b/Dockerfile.serve index c60ab7e24..ee3890fe6 100644 --- a/Dockerfile.serve +++ b/Dockerfile.serve @@ -4,17 +4,16 @@ WORKDIR /tmp/kam COPY . . RUN make all_platforms && \ make checksum && \ - cd tools/kam-serve && \ - go build -o /tmp/kam-serve main.go && \ + go build -o /tmp/kamserve tools/kam-serve/main.go && \ mkdir -p /tmp/workdir/kam-root/kam && \ cp config/index.html /tmp/workdir/kam-root/index.html && \ mv /tmp/kam/dist/* /tmp/workdir/kam-root/kam/ -FROM scratch +FROM ubuntu # Add application sources COPY --from=builder /tmp/workdir/ /tmp/ -COPY --from=builder /tmp/kam-serve / +COPY --from=builder /tmp/kamserve / # The run script uses standard ways to run the application -ENTRYPOINT ["/kam-serve"] +ENTRYPOINT ["/kamserve"] From 840600084b8c03593fb7f2a4def470c3e6c6435a Mon Sep 17 00:00:00 2001 From: Anand Francis Joseph Date: Thu, 12 Oct 2023 21:26:16 +0530 Subject: [PATCH 3/3] Using a scratch image to reduce image size and attack surface Signed-off-by: Anand Francis Joseph --- Dockerfile.serve | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile.serve b/Dockerfile.serve index ee3890fe6..e7ba1fd5e 100644 --- a/Dockerfile.serve +++ b/Dockerfile.serve @@ -4,16 +4,19 @@ WORKDIR /tmp/kam COPY . . RUN make all_platforms && \ make checksum && \ - go build -o /tmp/kamserve tools/kam-serve/main.go && \ + CGO_ENABLED=0 go build -o /tmp/kamserve tools/kam-serve/main.go && \ mkdir -p /tmp/workdir/kam-root/kam && \ cp config/index.html /tmp/workdir/kam-root/index.html && \ mv /tmp/kam/dist/* /tmp/workdir/kam-root/kam/ -FROM ubuntu +FROM scratch # Add application sources COPY --from=builder /tmp/workdir/ /tmp/ COPY --from=builder /tmp/kamserve / + +EXPOSE 9000 + # The run script uses standard ways to run the application -ENTRYPOINT ["/kamserve"] +ENTRYPOINT ["./kamserve"]