-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main: Use configuration file instead of flags and simplify app extens…
…ion. Clair will now use a YAML configuration file instead of command line arguments as the number of parameters grows. Also, Clair now exposes a Boot() func that allows everyone to easily create their own project and load dynamically their own fetchers/updaters.
- Loading branch information
Showing
67 changed files
with
11,493 additions
and
4,108 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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,74 @@ | ||
// Copyright 2015 clair authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package clair implements the ability to boot Clair with your own imports | ||
// that can dynamically register additional functionality. | ||
package clair | ||
|
||
import ( | ||
"math/rand" | ||
"os" | ||
"os/signal" | ||
"time" | ||
|
||
"github.com/coreos/clair/api" | ||
"github.com/coreos/clair/config" | ||
"github.com/coreos/clair/database" | ||
"github.com/coreos/clair/notifier" | ||
"github.com/coreos/clair/updater" | ||
"github.com/coreos/clair/utils" | ||
"github.com/coreos/pkg/capnslog" | ||
) | ||
|
||
var log = capnslog.NewPackageLogger("github.com/coreos/clair", "main") | ||
|
||
// Boot starts Clair. By exporting this function, anyone can import their own | ||
// custom fetchers/updaters into their own package and then call clair.Boot. | ||
func Boot(config *config.Config) { | ||
rand.Seed(time.Now().UnixNano()) | ||
st := utils.NewStopper() | ||
|
||
// Open database | ||
err := database.Open(config.Database) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer database.Close() | ||
|
||
// Start notifier | ||
st.Begin() | ||
notifier := notifier.New(config.Notifier) | ||
go notifier.Serve(st) | ||
|
||
// Start API | ||
st.Begin() | ||
go api.Run(config.API, st) | ||
st.Begin() | ||
go api.RunHealth(config.API, st) | ||
|
||
// Start updater | ||
st.Begin() | ||
go updater.Run(config.Updater, st) | ||
|
||
// Wait for interruption and shutdown gracefully. | ||
waitForSignals(os.Interrupt) | ||
log.Info("Received interruption, gracefully stopping ...") | ||
st.Stop() | ||
} | ||
|
||
func waitForSignals(signals ...os.Signal) { | ||
interrupts := make(chan os.Signal, 1) | ||
signal.Notify(interrupts, signals...) | ||
<-interrupts | ||
} |
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,77 @@ | ||
// Copyright 2015 clair authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"runtime/pprof" | ||
"strings" | ||
|
||
"github.com/coreos/clair" | ||
"github.com/coreos/clair/config" | ||
|
||
"github.com/coreos/pkg/capnslog" | ||
|
||
// Register components | ||
_ "github.com/coreos/clair/updater/fetchers" | ||
_ "github.com/coreos/clair/worker/detectors/os" | ||
_ "github.com/coreos/clair/worker/detectors/packages" | ||
) | ||
|
||
var log = capnslog.NewPackageLogger("github.com/coreos/clair/cmd/clair", "main") | ||
|
||
func main() { | ||
// Parse command-line arguments | ||
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) | ||
flagConfigPath := flag.String("config", "", "Load configuration from the specified file.") | ||
flagCPUProfilePath := flag.String("cpu-profile", "", "Write a CPU profile to the specified file before exiting.") | ||
flagLogLevel := flag.String("log-level", "info", "Define the logging level.") | ||
flag.Parse() | ||
// Load configuration | ||
config, err := config.Load(*flagConfigPath) | ||
if err != nil { | ||
log.Fatalf("failed to load configuration: %s", err) | ||
} | ||
|
||
// Initialize logging system | ||
logLevel, err := capnslog.ParseLevel(strings.ToUpper(*flagLogLevel)) | ||
capnslog.SetGlobalLogLevel(logLevel) | ||
capnslog.SetFormatter(capnslog.NewPrettyFormatter(os.Stdout, false)) | ||
|
||
// Enable CPU Profiling if specified | ||
if *flagCPUProfilePath != "" { | ||
startCPUProfiling(*flagCPUProfilePath) | ||
defer stopCPUProfiling() | ||
} | ||
|
||
clair.Boot(config) | ||
} | ||
|
||
func startCPUProfiling(path string) { | ||
f, err := os.Create(path) | ||
if err != nil { | ||
log.Fatalf("failed to create profile file: %s", err) | ||
} | ||
defer f.Close() | ||
|
||
pprof.StartCPUProfile(f) | ||
log.Info("started CPU profiling") | ||
} | ||
|
||
func stopCPUProfiling() { | ||
pprof.StopCPUProfile() | ||
log.Info("stopped CPU profiling") | ||
} |
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,37 @@ | ||
# The values specified here are the default values that Clair uses if no configuration file | ||
# is specified or if the keys are not defined. | ||
--- | ||
database: | ||
# Database backend. | ||
# | ||
# Possible values are "bolt", "leveldb", "memstore", "mongo", "sql". | ||
# | ||
# When running multiple instances is not desired, using BoltDB backend is the best choice as it is | ||
# lightning fast. However, using PostgreSQL enables running multiple instances concurrently. | ||
# The default is just an ephemeral database. | ||
type: memstore | ||
# Path to the database. | ||
# | ||
# Can be a file or a connection string. | ||
path: | ||
api: | ||
# Port on which the main API and the health API will listen on. | ||
port: 6060 | ||
healthport: 6061 | ||
# Maximum time that API requests may take before they time-out with a HTTP 503 error. | ||
timeout: 900s | ||
# Paths to certificates to secure the main API with TLS and client certificate auth. | ||
cafile: | ||
keyfile: | ||
certfile: | ||
updater: | ||
# Frequency at which the vulnerability updater will run. | ||
# Use 0 to disable the updater entirely. | ||
interval: 2h | ||
notifier: | ||
# HTTP endpoint that will receive notifications with POST requests. | ||
endpoint: | ||
# Path to certificates to call the endpoint securely with TLS and client certificate auth. | ||
cafile: | ||
keyfile: | ||
certfile: |
Oops, something went wrong.