start
This commit is contained in:
parent
2defad24c8
commit
8c5fe54d11
11
.travis.yml
Normal file
11
.travis.yml
Normal file
@ -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
|
30
hello-world/Dockerfile
Normal file
30
hello-world/Dockerfile
Normal file
@ -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"]
|
1
hello-world/go.mod
Normal file
1
hello-world/go.mod
Normal file
@ -0,0 +1 @@
|
||||
module github.com/tormachris/knative-report-functions/hello-world
|
30
hello-world/helloworld.go
Normal file
30
hello-world/helloworld.go
Normal file
@ -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))
|
||||
}
|
Loading…
Reference in New Issue
Block a user