Configuration
Relevant source files
The following files were used as context for generating this wiki page:Configuration in huskyCI is managed through environment variables, command-line arguments, and configuration files. The system is divided into two main components: the server-side API and the client-side CLI, each with its own configuration mechanism. The server-side components are primarily configured via environment variables, often orchestrated using Docker Compose. The client-side tools use a combination of environment variables and a local configuration file to manage API targets and credentials.
This document outlines the configuration for both the server and client components, detailing the required variables, file structures, and the startup validation processes that ensure the environment is correctly set up.
Server-Side Configuration
The server-side of huskyCI, which includes the API, database, and container runtime environment, is configured primarily through environment variables. The docker-compose.yml file provides a clear reference for setting up a development or production environment.
Service Orchestration with Docker Compose
The docker-compose.yml file defines the core services required to run huskyCI: dockerapi, api, and mongodb. It orchestrates their setup, networking, and configuration.
The diagram below illustrates the services and their dependencies as defined in the docker-compose.yml file.
Sources: deployments/docker-compose.yml
The api service is the central component, and its configuration is managed through a set of environment variables passed in the docker-compose.yml file.
# deployments/docker-compose.yml:18-32
api:
container_name: huskyCI_API
environment:
# required envs
HUSKYCI_DATABASE_DB_ADDR: mongodb
HUSKYCI_DATABASE_DB_NAME: huskyCIDB
HUSKYCI_DATABASE_DB_USERNAME: huskyCIUser
HUSKYCI_DATABASE_DB_PASSWORD: huskyCIPassword
HUSKYCI_API_DEFAULT_USERNAME: huskyCIUser
HUSKYCI_API_DEFAULT_PASSWORD: huskyCIPassword
HUSKYCI_API_ALLOW_ORIGIN_CORS: "*"
HUSKYCI_DOCKERAPI_ADDR: dockerapi
HUSKYCI_DOCKERAPI_TLS_VERIFY: 0
HUSKYCI_DOCKERAPI_CERT_PATH: /go/src/github.com/globocom/huskyCI/
HUSKYCI_INFRASTRUCTURE_USE: docker
Sources: deployments/docker-compose.yml:18-32
API Startup and Requirement Checks
When the huskyCI API server starts, it performs a series of checks to ensure all dependencies and configurations are correctly set. This process is handled by the CheckHuskyRequirements function.
Sources: api/server.go:40-43, api/util/api/api.go:21-47
The following flowchart shows the sequence of checks performed during the API server's initialization.
Sources: api/util/api/api.go:21-47, api/server.go:40-43
Environment Variables
The API server relies on several environment variables for its core configuration. The checkEnvVars function validates their presence at startup.
| Variable | Description | Example from docker-compose.yml |
|---|---|---|
HUSKYCI_DATABASE_DB_ADDR | Address of the MongoDB instance. | mongodb |
HUSKYCI_DATABASE_DB_NAME | Name of the database to use. | huskyCIDB |
HUSKYCI_DATABASE_DB_USERNAME | Username for MongoDB authentication. | huskyCIUser |
HUSKYCI_DATABASE_DB_PASSWORD | Password for MongoDB authentication. | huskyCIPassword |
HUSKYCI_API_DEFAULT_USERNAME | Default username for the API. | huskyCIUser |
HUSKYCI_API_DEFAULT_PASSWORD | Default password for the API. | huskyCIPassword |
HUSKYCI_API_ALLOW_ORIGIN_CORS | CORS configuration for allowed origins. | * |
HUSKYCI_INFRASTRUCTURE_USE | Specifies the container infrastructure (docker or kubernetes). | docker |
HUSKYCI_DOCKERAPI_ADDR | Address of the Docker API. (Required if HUSKYCI_INFRASTRUCTURE_USE is docker) | dockerapi |
HUSKYCI_DOCKERAPI_CERT_PATH | Path to Docker API TLS certificates. (Required if HUSKYCI_INFRASTRUCTURE_USE is docker) | /go/src/github.com/globocom/huskyCI/ |
Sources: api/util/api/api.go:73-90, deployments/docker-compose.yml:21-32
Security Test Configuration
On startup, huskyCI ensures that default configurations for all supported security tools are present in the database. The checkEachSecurityTest function iterates through a predefined list of tools and upserts their configuration.
The following security tests are configured by default:
enrygitauthorsgosecbrakemanbanditnpmaudityarnauditspotbugsgitleakssafetytfsecsecuritycodescan
Sources: api/util/api/api.go:173-183, cli/analysis/analysis.go:198-218
Client-Side Configuration
The huskyCI client (huskyci-client and huskyci) is used to interact with the API, primarily to trigger and monitor security analyses.
Client Execution Flow
The client's main function orchestrates the analysis process, from configuration checks to printing the final results.
This sequence diagram shows the client's startup and analysis process.
Sources: client/cmd/main.go:21-147
CLI Configuration (huskyci)
The huskyci CLI tool (distinct from huskyci-client) uses a local configuration file to manage multiple API targets.
Configuration File
The CLI stores its configuration in ~/.huskyci/config.yaml. This file is created automatically if it doesn't exist. It contains a map of targets, where each target represents a huskyCI API endpoint.
Sources: cli/config/config.go:49-75
The GetCurrentTarget function reads this file to determine which API endpoint to communicate with. It can also be configured via environment variables, which take precedence.
| Method | Configuration |
|---|---|
| Environment Variables | HUSKYCI_CLIENT_API_ADDR and HUSKYCI_CLIENT_TOKEN are used directly. |
| Config File | If environment variables are not set, the CLI looks for the target marked with current: true in ~/.huskyci/config.yaml. |
Sources: cli/config/config.go:16-47
The Target struct defines the properties of an API target:
// cli/types/types.go:21-26
type Target struct {
Label string
Endpoint string
TokenStorage string
Token string
}
Sources: cli/types/types.go:21-26
huskyci-client Configuration
The huskyci-client is a simpler client focused on running an analysis in a CI/CD environment. It is configured solely through environment variables, which are checked by config.CheckEnvVars().
Sources: client/cmd/main.go:29-35