├── go.mod ├── README.md ├── Dockerfile ├── .gitignore └── simple-web-server.go /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/kostis-codefresh/simple-web-app 2 | 3 | go 1.13 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A sample GO web application with Dockerfile 2 | 3 | See also 4 | * https://github.com/codefresh-contrib/gitops-kubernetes-configuration 5 | * https://github.com/codefresh-contrib/gitops-pipelines 6 | 7 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.15.1-alpine3.12 AS build-env 2 | 3 | WORKDIR /tmp/simple-go-app 4 | 5 | COPY . . 6 | 7 | RUN CGO_ENABLED=0 GOOS=linux go build 8 | 9 | FROM scratch 10 | COPY --from=build-env /tmp/simple-go-app/simple-web-app /app/simple-web-app 11 | 12 | EXPOSE 8080 13 | CMD ["/app/simple-web-app"] 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | bin 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.exe 24 | *.test 25 | *.prof 26 | -------------------------------------------------------------------------------- /simple-web-server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | func indexHandler(w http.ResponseWriter, r *http.Request) { 9 | fmt.Fprintf(w, "I am a GO application running inside Docker.") 10 | 11 | } 12 | 13 | func healthHandler(w http.ResponseWriter, r *http.Request) { 14 | fmt.Fprintf(w, "OK\n") 15 | 16 | } 17 | 18 | func main() { 19 | fmt.Println("Simple web server is starting on port 8080...") 20 | http.HandleFunc("/", indexHandler) 21 | http.HandleFunc("/health", healthHandler) 22 | http.ListenAndServe(":8080", nil) 23 | } 24 | --------------------------------------------------------------------------------