Skip to content

Commit 1000755

Browse files
authored
Fix shutdown (#2)
1 parent 120bb00 commit 1000755

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

codefresh/deploy.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,10 @@ steps:
4040
working_directory: /deploy/
4141
commands:
4242
# Announce the release version
43-
- "echo 'Preparing to deploy version ${{CF_RELEASE_TAG}}'"
44-
# Fetch the build-harness
45-
- "curl -sSL -o Makefile https://git.io/build-harness"
46-
# Initialize the build-harness
47-
- "make init"
48-
# Install or upgrade tiller
49-
- "make helm/toolbox/upsert"
50-
# Deploy chart to cluster using helmfile
51-
- "helmfile --namespace ${{NAMESPACE}} --selector color=blue sync"
43+
- "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'"
44+
- echo dev > .ctlenv
45+
# Deploy chart to cluster
46+
- "/deploy/ctl --namespace=${{NAMESPACE}} blue-green"
5247

5348
set_github_deployment_status_to_success:
5449
title: Set GitHub deployment status to "success"

main.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"io/ioutil"
7+
"log"
68
"net/http"
79
"os"
810
)
@@ -14,33 +16,45 @@ func main() {
1416
}
1517
count := 0
1618

19+
m := http.NewServeMux()
20+
s := http.Server{Addr: ":8080", Handler: m}
21+
22+
log.Printf("Server started\n")
23+
1724
// Healthcheck endpoint
18-
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
25+
m.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
1926
fmt.Fprintf(w, "OK")
2027
})
2128

22-
// Take one for the team
23-
boom, _ := ioutil.ReadFile("public/boom.html")
24-
http.HandleFunc("/boom", func(w http.ResponseWriter, r *http.Request) {
29+
// Simulate failure
30+
boom, _ := ioutil.ReadFile("public/shutdown.html")
31+
m.HandleFunc("/shutdown", func(w http.ResponseWriter, r *http.Request) {
2532
fmt.Fprintf(w, string(boom))
26-
fmt.Printf("Goodbye\n")
27-
//os.Exit(0)
33+
log.Printf("Received shutdown request\n")
34+
go func() {
35+
if err := s.Shutdown(context.Background()); err != nil {
36+
log.Fatal(err)
37+
}
38+
}()
2839
})
2940

3041
// Dashboard
3142
dashboard, _ := ioutil.ReadFile("public/dashboard.html")
32-
http.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) {
43+
m.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) {
3344
fmt.Fprintf(w, string(dashboard))
34-
fmt.Printf("GET %s\n", r.URL.Path)
45+
log.Printf("GET %s\n", r.URL.Path)
3546
})
3647

3748
// Default
3849
index, _ := ioutil.ReadFile("public/index.html")
39-
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
50+
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
4051
count += 1
4152
fmt.Fprintf(w, string(index), c, count)
42-
fmt.Printf("GET %s\n", r.URL.Path)
53+
//log.Printf("GET %s\n", r.URL.Path)
4354
})
4455

45-
http.ListenAndServe(":8080", nil)
56+
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
57+
log.Fatal(err)
58+
}
59+
log.Printf("Exiting")
4660
}

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html onclick="window.location.href = '/boom'">
1+
<html onclick="window.location.href = '/shutdown'">
22
<head>
33
<meta http-equiv="refresh" content="2">
44
<style type="text/css">
File renamed without changes.

0 commit comments

Comments
 (0)