-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Docker build with broken final stage
Signed-off-by: Sascha Schwarze <[email protected]>
- Loading branch information
1 parent
96afb41
commit 22656fb
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# From https://github.com/homeport/gonut/tree/master/assets/sample-apps/golang | ||
|
||
FROM ghcr.io/shipwright-io/shipwright-samples/golang:1.18 AS build | ||
|
||
COPY main.go . | ||
ENV CGO_ENABLED=0 | ||
RUN go build \ | ||
-ldflags "-s -w -extldflags '-static'" \ | ||
-o /tmp/helloworld \ | ||
main.go | ||
|
||
FROM scratch AS working-final | ||
COPY --from=build /tmp/helloworld ./helloworld | ||
ENTRYPOINT [ "./helloworld" ] | ||
EXPOSE 8080 | ||
|
||
# the following stage is INTENTIONALLY broken, one can only have a successful run when specifying final as target stage | ||
FROM scratch | ||
RUN non-existing-command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"runtime" | ||
"strconv" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
signals := make(chan os.Signal, 1) | ||
signal.Notify(signals, os.Interrupt, syscall.SIGTERM) | ||
|
||
port := 8080 | ||
if strValue, ok := os.LookupEnv("PORT"); ok { | ||
if intValue, err := strconv.Atoi(strValue); err == nil { | ||
port = intValue | ||
} | ||
} | ||
|
||
srv := &http.Server{Addr: fmt.Sprintf(":%d", port)} | ||
go func() { | ||
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { | ||
fmt.Fprintf(w, "Hello, World! I am using %s by the way.", runtime.Version()) | ||
}) | ||
|
||
if err := srv.ListenAndServe(); err != http.ErrServerClosed { | ||
log.Fatalf("failed to start server: %v", err) | ||
} | ||
}() | ||
|
||
<-signals | ||
log.Printf("shutting down server") | ||
if err := srv.Shutdown(ctx); err != nil { | ||
log.Fatalf("failed to shutdown server: %v", err) | ||
} | ||
} |