From 129faffb200a1bc47eb3574f8205dd6c28e9c228 Mon Sep 17 00:00:00 2001 From: Julian Nonino Date: Wed, 29 Oct 2025 00:00:53 +0000 Subject: [PATCH] Add server written in Golang --- Dockerfile | 17 ++++++++++++++--- src/go.mod | 3 +++ src/main.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/go.mod create mode 100644 src/main.go diff --git a/Dockerfile b/Dockerfile index 95bb85e..704cfec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,13 @@ FROM hashicorp/terraform:1.13 AS terraform FROM fullstorydev/grpcurl:v1.9.3 AS grpcurl +################# +# Build Go Binary +FROM golang:1.25-alpine3.21 AS build +WORKDIR /app +COPY src/ . +RUN go build -o toolbox + ####### # Image FROM debian:13-slim @@ -10,10 +17,8 @@ LABEL maintainer="Julian Nonino " # Args ARG TARGETARCH -# Copy Terraform Binary +# Copy dependencies COPY --from=terraform /bin/terraform /bin/terraform - -# Copy gRPCurl Binary COPY --from=grpcurl /bin/grpcurl /bin/grpcurl # Install Tools @@ -30,3 +35,9 @@ ENV KUBECTL_VERSION=v1.34.0 RUN curl -o /tmp/kubectl -LO "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl" && \ install -o root -g root -m 0755 /tmp/kubectl /bin/kubectl && \ rm /tmp/kubectl + +# Run the server +WORKDIR /app +COPY --from=build /app/toolbox /bin/toolbox +EXPOSE 8080 +CMD ["/bin/toolbox"] diff --git a/src/go.mod b/src/go.mod new file mode 100644 index 0000000..ac46f81 --- /dev/null +++ b/src/go.mod @@ -0,0 +1,3 @@ +module toolbox + +go 1.25 diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..c93c235 --- /dev/null +++ b/src/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + host, _ := os.Hostname() + fmt.Fprintf(w, "

Hostname: %s

", host) + }) + + http.HandleFunc("/exitWithError", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "Exit with Error") + os.Exit(1) + }) + + http.HandleFunc("/exitSuccess", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "Exit Successfully") + os.Exit(0) + }) + + log.Println("Server is running at http://localhost:8080") + log.Fatal(http.ListenAndServe(":8080", nil)) +}