From 6bc0a3fb12e05f8662e2d2819993163ec3d49c2b Mon Sep 17 00:00:00 2001 From: Christopher Crone Date: Wed, 30 Oct 2019 13:01:49 +0100 Subject: [PATCH] Add service image build example Signed-off-by: Christopher Crone --- examples/service-build/back/Dockerfile | 9 ++++++++ examples/service-build/back/main.go | 23 +++++++++++++++++++ .../build-demo.dockerapp/docker-compose.yml | 17 ++++++++++++++ .../build-demo.dockerapp/metadata.yml | 10 ++++++++ .../build-demo.dockerapp/parameters.yml | 2 ++ examples/service-build/front/Dockerfile | 2 ++ examples/service-build/front/nginx-conf | 9 ++++++++ 7 files changed, 72 insertions(+) create mode 100644 examples/service-build/back/Dockerfile create mode 100644 examples/service-build/back/main.go create mode 100644 examples/service-build/build-demo.dockerapp/docker-compose.yml create mode 100644 examples/service-build/build-demo.dockerapp/metadata.yml create mode 100644 examples/service-build/build-demo.dockerapp/parameters.yml create mode 100644 examples/service-build/front/Dockerfile create mode 100644 examples/service-build/front/nginx-conf diff --git a/examples/service-build/back/Dockerfile b/examples/service-build/back/Dockerfile new file mode 100644 index 000000000..2da98bd67 --- /dev/null +++ b/examples/service-build/back/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:alpine AS build +ARG MESSAGE +WORKDIR /go/src +COPY main.go . +RUN CGO_ENABLED=0 go build -o /server -ldflags="-X main.Message=${MESSAGE} -s -w" main.go + +FROM scratch AS run +ENTRYPOINT ["/server"] +COPY --from=build /server /server diff --git a/examples/service-build/back/main.go b/examples/service-build/back/main.go new file mode 100644 index 000000000..4f83ca4c2 --- /dev/null +++ b/examples/service-build/back/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +var ( + // Message is the text to serve + Message string +) + +func main() { + if Message == "" { + Message = "

Hello from Docker App build demo!

" + } + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Serve request from: %s\n", r.RemoteAddr) + fmt.Fprintf(w, Message) + }) + log.Fatal(http.ListenAndServe(":5000", nil)) +} diff --git a/examples/service-build/build-demo.dockerapp/docker-compose.yml b/examples/service-build/build-demo.dockerapp/docker-compose.yml new file mode 100644 index 000000000..f5c22b20d --- /dev/null +++ b/examples/service-build/build-demo.dockerapp/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.7" + +services: + front: + build: + context: front/ + dockerfile: Dockerfile + ports: + - "${front.port}:80" + + back: + build: + context: back/ + dockerfile: Dockerfile + args: + - MESSAGE + diff --git a/examples/service-build/build-demo.dockerapp/metadata.yml b/examples/service-build/build-demo.dockerapp/metadata.yml new file mode 100644 index 000000000..568483383 --- /dev/null +++ b/examples/service-build/build-demo.dockerapp/metadata.yml @@ -0,0 +1,10 @@ +# Version of the application +version: 0.1.0 +# Name of the application +name: build-demo +# A short description of the application +description: +# List of application maintainers with name and email for each +maintainers: + - name: chris + email: diff --git a/examples/service-build/build-demo.dockerapp/parameters.yml b/examples/service-build/build-demo.dockerapp/parameters.yml new file mode 100644 index 000000000..7e606def5 --- /dev/null +++ b/examples/service-build/build-demo.dockerapp/parameters.yml @@ -0,0 +1,2 @@ +front: + port: 8080 diff --git a/examples/service-build/front/Dockerfile b/examples/service-build/front/Dockerfile new file mode 100644 index 000000000..1e77bf2d2 --- /dev/null +++ b/examples/service-build/front/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:alpine +COPY nginx-conf /etc/nginx/conf.d/default.conf diff --git a/examples/service-build/front/nginx-conf b/examples/service-build/front/nginx-conf new file mode 100644 index 000000000..9aa8d8a95 --- /dev/null +++ b/examples/service-build/front/nginx-conf @@ -0,0 +1,9 @@ +server { + listen 80; + server_name localhost; + + location / { + proxy_pass http://back:5000/; + proxy_set_header Host "localhost"; + } +}