diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..284341f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# specify the base image to be used for the application +FROM golang:1.21.4-alpine + +# create the working directory in the image +WORKDIR /app + +# copy Go modules and dependencies to image +COPY go.mod ./ + +# download Go modules and dependencies +RUN go mod download + +# copy all the Go files ending with .go extension +COPY *.go ./ + +# compile application +RUN go build -o /golang-http-header + +# network port at runtime +EXPOSE 8000 + +# execute when the container starts +CMD [ "/golang-http-header" ] \ No newline at end of file diff --git a/deployment.yaml b/deployment.yaml new file mode 100644 index 0000000..9f72c9f --- /dev/null +++ b/deployment.yaml @@ -0,0 +1,34 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: http-header + labels: + app: golang +spec: + replicas: 2 + selector: + matchLabels: + app: golang + template: + metadata: + labels: + app: golang + spec: + containers: + - name: http-header + image: git.10bit.link/kcrawford/golang-http-header:0.0.4 + ports: + - containerPort: 8000 + +--- +apiVersion: v1 +kind: Service +metadata: + name: go-frontend +spec: + selector: + app: golang + ports: + - protocol: TCP + port: 80 + targetPort: 8000 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6efdd56 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module golang-http-header + +go 1.21.4 diff --git a/main.go b/main.go index b409e6a..641268b 100644 --- a/main.go +++ b/main.go @@ -18,16 +18,16 @@ func handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server-Hostname", hostname) // Send a response - fmt.Fprintf(w, "Hello! This is server: %s\n", hostname) + fmt.Fprintf(w, "This is server: %s\n", hostname) } func main() { // Define the handler function for incoming requests http.HandleFunc("/", handler) - // Start the HTTP server on port 8080 - fmt.Println("Server listening on :8080...") - err := http.ListenAndServe(":8080", nil) + // Start the HTTP server on port 8000 + fmt.Println("Server listening on :8000...") + err := http.ListenAndServe(":8000", nil) if err != nil { fmt.Println("Error:", err) }