From 8c5fe54d11afe5402519d4a3c9ead646d84188a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Fri, 4 Oct 2019 19:49:31 +0200 Subject: [PATCH] start --- .travis.yml | 11 +++++++++++ hello-world/Dockerfile | 30 ++++++++++++++++++++++++++++++ hello-world/go.mod | 1 + hello-world/helloworld.go | 30 ++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .travis.yml create mode 100644 hello-world/Dockerfile create mode 100644 hello-world/go.mod create mode 100644 hello-world/helloworld.go diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c9e4e89 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ + +language: bash + +services: + - docker + +script: + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin docker.pkg.github.com + - cd hello-world + - docker build -t=docker.pkg.github.com/tormachris/knative-report-functions/hello-world . + - docker push docker.pkg.github.com/tormachris/knative-report-functions/hello-world diff --git a/hello-world/Dockerfile b/hello-world/Dockerfile new file mode 100644 index 0000000..06531f6 --- /dev/null +++ b/hello-world/Dockerfile @@ -0,0 +1,30 @@ +# Use the offical Golang image to create a build artifact. +# This is based on Debian and sets the GOPATH to /go. +# https://hub.docker.com/_/golang +FROM golang:1.13 as builder + +# Create and change to the app directory. +WORKDIR /app + +# Retrieve application dependencies. +# This allows the container build to reuse cached dependencies. +COPY go.* ./ +RUN go mod download + +# Copy local code to the container image. +COPY . ./ + +# Build the binary. +RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server + +# Use the official Alpine image for a lean production container. +# https://hub.docker.com/_/alpine +# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds +FROM alpine:3 +RUN apk add --no-cache ca-certificates + +# Copy the binary to the production image from the builder stage. +COPY --from=builder /app/server /server + +# Run the web service on container startup. +CMD ["/server"] diff --git a/hello-world/go.mod b/hello-world/go.mod new file mode 100644 index 0000000..a3e0840 --- /dev/null +++ b/hello-world/go.mod @@ -0,0 +1 @@ +module github.com/tormachris/knative-report-functions/hello-world diff --git a/hello-world/helloworld.go b/hello-world/helloworld.go new file mode 100644 index 0000000..dbe5c7c --- /dev/null +++ b/hello-world/helloworld.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" +) + +func handler(w http.ResponseWriter, r *http.Request) { + log.Print("Hello world received a request.") + target := os.Getenv("TARGET") + if target == "" { + target = "World" + } + fmt.Fprintf(w, "Hello %s!\n", target) +} + +func main() { + log.Print("Hello world sample started.") + + http.HandleFunc("/", handler) + + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) +}