Skip to content

Commit b491399

Browse files
Merge pull request #16 from shipwright-io/sascha-add-docker-build-with-broken-final-stage
Add Docker build with broken final stage
2 parents 96afb41 + 4b8ca1f commit b491399

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# From https://github.com/homeport/gonut/tree/master/assets/sample-apps/golang
2+
3+
FROM ghcr.io/shipwright-io/shipwright-samples/golang:1.18 AS build
4+
5+
COPY main.go .
6+
ENV CGO_ENABLED=0
7+
RUN go build \
8+
-ldflags "-s -w -extldflags '-static'" \
9+
-o /tmp/helloworld \
10+
main.go
11+
12+
FROM scratch AS working-final
13+
COPY --from=build /tmp/helloworld ./helloworld
14+
ENTRYPOINT [ "./helloworld" ]
15+
EXPOSE 8080
16+
17+
# the following stage is INTENTIONALLY broken, one can only have a successful run when specifying working-final as target stage
18+
FROM scratch
19+
RUN non-existing-command
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright The Shipwright Contributors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package main
6+
7+
import (
8+
"context"
9+
"fmt"
10+
"log"
11+
"net/http"
12+
"os"
13+
"os/signal"
14+
"runtime"
15+
"strconv"
16+
"syscall"
17+
)
18+
19+
func main() {
20+
ctx := context.Background()
21+
signals := make(chan os.Signal, 1)
22+
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
23+
24+
port := 8080
25+
if strValue, ok := os.LookupEnv("PORT"); ok {
26+
if intValue, err := strconv.Atoi(strValue); err == nil {
27+
port = intValue
28+
}
29+
}
30+
31+
srv := &http.Server{Addr: fmt.Sprintf(":%d", port)}
32+
go func() {
33+
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
34+
fmt.Fprintf(w, "Hello, World! I am using %s by the way.", runtime.Version())
35+
})
36+
37+
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
38+
log.Fatalf("failed to start server: %v", err)
39+
}
40+
}()
41+
42+
<-signals
43+
log.Printf("shutting down server")
44+
if err := srv.Shutdown(ctx); err != nil {
45+
log.Fatalf("failed to shutdown server: %v", err)
46+
}
47+
}

0 commit comments

Comments
 (0)