Skip to content

Commit

Permalink
feat(api): check downloadable binaries on startup (#4061)
Browse files Browse the repository at this point in the history
close #4059
  • Loading branch information
fsamin authored and bnjjj committed Mar 25, 2019
1 parent d120680 commit 16dc370
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions engine/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -484,6 +485,37 @@ func (a *API) Serve(ctx context.Context) error {

a.StartupTime = time.Now()

// Checking downloadable binaries
downloads := sdk.GetStaticDownloadsWithAvailability(a.Config.Directories.Download)
var hasWorker, hasCtl, hasEngine bool
for k, d := range downloads {
for ks := range downloads[k].OSArchs {
for _, a := range downloads[k].OSArchs[ks].Archs {
if a.Available {
switch d.Name {
case "worker":
hasWorker = true
case "cdsctl":
hasCtl = true
case "engine":
hasEngine = true
}
}
}
}
}
if !hasEngine {
log.Error("engine is unavailable for download, this may lead to a poor user experience. Please check your configuration file or the %s directory", a.Config.Directories.Download)
}
if !hasCtl {
log.Error("cdsctl is unavailable for download, this may lead to a poor user experience. Please check your configuration file or the %s directory", a.Config.Directories.Download)
}
if !hasWorker {
// If no worker, let's exit because CDS for run anything
log.Error("cdsctl is unavailable for download. Please check your configuration file or the %s directory", a.Config.Directories.Download)
return errors.New("worker binary unavailabe")
}

//Initialize secret driver
secret.Init(a.Config.Secrets.Key)

Expand Down

0 comments on commit 16dc370

Please sign in to comment.