Skip to content

Commit

Permalink
Back to exec, with port
Browse files Browse the repository at this point in the history
  • Loading branch information
taiidani committed Aug 19, 2023
1 parent 53a77cb commit 21935e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
15 changes: 10 additions & 5 deletions .github/deploy/guess-my-word.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ job "guess-my-word" {

group "app" {
task "app" {
driver = "docker"
driver = "exec"

config {
image = var.artifact_url
args = ["/app"]
ports = ["web"]
command = "guess-my-word"
args = [
"--port=${NOMAD_PORT_web}",
]
}

artifact {
source = var.artifact_url
}

env {
Expand Down Expand Up @@ -116,7 +121,7 @@ job "guess-my-word" {

network {
mode = "bridge"
port "web" { to = 3000 }
port "web" {}
port "redirect" { to = 81 }
}

Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"github.com/gin-gonic/gin"
)

const defaultAddress = ":3000"

func main() {
port := flag.Int("port", 3000, "port to listen on")
help := flag.Bool("help", false, "displays help text and exits")
flag.Parse()
bind := fmt.Sprintf(":%d", *port)

if help != nil && *help {
fmt.Fprintln(os.Stderr, "This application serves the Guess My Word app at "+defaultAddress)
fmt.Fprintf(os.Stderr, "This application serves the Guess My Word app at %s\n", bind)
os.Exit(0)
}

Expand Down Expand Up @@ -58,8 +58,8 @@ func main() {
os.Exit(1)
}

fmt.Printf("Listening and serving HTTP on %s\n", defaultAddress)
srv := http.Server{Addr: defaultAddress, Handler: r}
fmt.Printf("Listening and serving HTTP on port %s\n", bind)
srv := http.Server{Addr: bind, Handler: r}

done := make(chan interface{})
go gracefulShutdown(ctx, &srv, done)
Expand Down Expand Up @@ -125,6 +125,7 @@ func gracefulShutdown(ctx context.Context, srv *http.Server, done chan<- interfa

// Wait for the process to be interrupted
<-ctx.Done()
fmt.Fprintf(os.Stderr, "Interrupted. Shutting down\n")

// Gracefully drain all connections
drainCtx, cancel := context.WithTimeout(context.Background(), drainTimeout)
Expand Down

0 comments on commit 21935e0

Please sign in to comment.