Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 6bc0a3f

Browse files
committed
Add service image build example
Signed-off-by: Christopher Crone <[email protected]>
1 parent 6267dc4 commit 6bc0a3f

File tree

7 files changed

+72
-0
lines changed

7 files changed

+72
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:alpine AS build
2+
ARG MESSAGE
3+
WORKDIR /go/src
4+
COPY main.go .
5+
RUN CGO_ENABLED=0 go build -o /server -ldflags="-X main.Message=${MESSAGE} -s -w" main.go
6+
7+
FROM scratch AS run
8+
ENTRYPOINT ["/server"]
9+
COPY --from=build /server /server

examples/service-build/back/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
)
8+
9+
var (
10+
// Message is the text to serve
11+
Message string
12+
)
13+
14+
func main() {
15+
if Message == "" {
16+
Message = "<h1>Hello from Docker App build demo!</h1>"
17+
}
18+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
19+
fmt.Printf("Serve request from: %s\n", r.RemoteAddr)
20+
fmt.Fprintf(w, Message)
21+
})
22+
log.Fatal(http.ListenAndServe(":5000", nil))
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3.7"
2+
3+
services:
4+
front:
5+
build:
6+
context: front/
7+
dockerfile: Dockerfile
8+
ports:
9+
- "${front.port}:80"
10+
11+
back:
12+
build:
13+
context: back/
14+
dockerfile: Dockerfile
15+
args:
16+
- MESSAGE
17+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Version of the application
2+
version: 0.1.0
3+
# Name of the application
4+
name: build-demo
5+
# A short description of the application
6+
description:
7+
# List of application maintainers with name and email for each
8+
maintainers:
9+
- name: chris
10+
email:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
front:
2+
port: 8080
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx:alpine
2+
COPY nginx-conf /etc/nginx/conf.d/default.conf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
location / {
6+
proxy_pass http://back:5000/;
7+
proxy_set_header Host "localhost";
8+
}
9+
}

0 commit comments

Comments
 (0)