diff --git a/codefresh/deploy.yaml b/codefresh/deploy.yaml index eb2137d..2d804b0 100644 --- a/codefresh/deploy.yaml +++ b/codefresh/deploy.yaml @@ -40,15 +40,10 @@ steps: working_directory: /deploy/ commands: # Announce the release version - - "echo 'Preparing to deploy version ${{CF_RELEASE_TAG}}'" - # Fetch the build-harness - - "curl -sSL -o Makefile https://git.io/build-harness" - # Initialize the build-harness - - "make init" - # Install or upgrade tiller - - "make helm/toolbox/upsert" - # Deploy chart to cluster using helmfile - - "helmfile --namespace ${{NAMESPACE}} --selector color=blue sync" + - "echo 'Preparing to deploy ${{CF_REPO_NAME}}:${{CF_RELEASE_TAG}}'" + - echo dev > .ctlenv + # Deploy chart to cluster + - "/deploy/ctl --namespace=${{NAMESPACE}} blue-green" set_github_deployment_status_to_success: title: Set GitHub deployment status to "success" diff --git a/main.go b/main.go index fc45dd1..35dda65 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,10 @@ package main import ( + "context" "fmt" "io/ioutil" + "log" "net/http" "os" ) @@ -14,33 +16,45 @@ func main() { } count := 0 + m := http.NewServeMux() + s := http.Server{Addr: ":8080", Handler: m} + + log.Printf("Server started\n") + // Healthcheck endpoint - http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + m.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "OK") }) - // Take one for the team - boom, _ := ioutil.ReadFile("public/boom.html") - http.HandleFunc("/boom", func(w http.ResponseWriter, r *http.Request) { + // Simulate failure + boom, _ := ioutil.ReadFile("public/shutdown.html") + m.HandleFunc("/shutdown", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, string(boom)) - fmt.Printf("Goodbye\n") - //os.Exit(0) + log.Printf("Received shutdown request\n") + go func() { + if err := s.Shutdown(context.Background()); err != nil { + log.Fatal(err) + } + }() }) // Dashboard dashboard, _ := ioutil.ReadFile("public/dashboard.html") - http.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) { + m.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, string(dashboard)) - fmt.Printf("GET %s\n", r.URL.Path) + log.Printf("GET %s\n", r.URL.Path) }) // Default index, _ := ioutil.ReadFile("public/index.html") - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { count += 1 fmt.Fprintf(w, string(index), c, count) - fmt.Printf("GET %s\n", r.URL.Path) + //log.Printf("GET %s\n", r.URL.Path) }) - http.ListenAndServe(":8080", nil) + if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatal(err) + } + log.Printf("Exiting") } diff --git a/public/index.html b/public/index.html index f187446..fd5e662 100644 --- a/public/index.html +++ b/public/index.html @@ -1,4 +1,4 @@ - +