Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Add service image build example
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Crone <christopher.crone@docker.com>
  • Loading branch information
chris-crone committed Oct 30, 2019
1 parent 6267dc4 commit 1fcfa27
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/service-build/back/back.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions examples/service-build/back/main.go
Original file line number Diff line number Diff line change
@@ -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 = "<h1>Hello from Docker App build demo!</h1>"
}
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))
}
18 changes: 18 additions & 0 deletions examples/service-build/build-demo.dockerapp/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.7"

services:
front:
image: front
build:
context: front/
dockerfile: front.Dockerfile
ports:
- "${front.port}:80"

back:
image: back
build:
context: back/
dockerfile: back.Dockerfile
args:
- MESSAGE
10 changes: 10 additions & 0 deletions examples/service-build/build-demo.dockerapp/metadata.yml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 2 additions & 0 deletions examples/service-build/build-demo.dockerapp/parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
front:
port: 8080
2 changes: 2 additions & 0 deletions examples/service-build/front/front.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx:alpine
COPY nginx-conf /etc/nginx/conf.d/default.conf
9 changes: 9 additions & 0 deletions examples/service-build/front/nginx-conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;
server_name localhost;

location / {
proxy_pass http://back:5000/;
proxy_set_header Host "localhost";
}
}

0 comments on commit 1fcfa27

Please sign in to comment.