Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// For all other dot-slash-prefixed requires, resolve as usual.
// NOTE: module-alias will not allow us to just return "." here, because
// it uses path.join under the hood, which collapses "./foo" down to just
// "foo", for which the module resolution semantics are different. So,
// return the directory of the requiring module, which gives the same result
// as ".".
return path.dirname(fromPath);
});
moduleAlias();
require(script);
}
// Log level may come in as lowercased 'log', 'info', etc., if run by the brig cli
const logLevel = LogLevel[process.env.BRIGADE_LOG_LEVEL.toUpperCase() || "LOG"];
const logger = new ContextLogger([], logLevel);
const version = require("../package.json").version;
logger.log(`brigade-worker version: ${version}`);
const requiredEnvVar = (name: string): string => {
if (!process.env[name]) {
logger.log(`Missing required env ${name}`);
process.exit(1);
}
return process.env[name];
};
const projectID: string = requiredEnvVar("BRIGADE_PROJECT_ID");
const projectNamespace: string = requiredEnvVar("BRIGADE_PROJECT_NAMESPACE");
const defaultULID = ulid().toLocaleLowerCase();
let e: events.BrigadeEvent = {
public init(job: T, e: BrigadeEvent, project: Project, allowSecretKeyRef: boolean = true) {
this.options = Object.assign({}, options);
this.event = e;
this.logger = new ContextLogger("k8s", e.logLevel);
this.job = job;
this.project = project;
this.client = defaultClient;
this.serviceAccount = job.serviceAccount || this.options.serviceAccount;
this.pod = undefined;
this.cancel = false;
this.reconnect = false;
// $JOB-$BUILD
this.name = `${job.name}-${this.event.buildID}`;
let commit = e.revision.commit || "master";
let secName = this.name;
let runnerName = this.name;
this.secret = newSecret(secName);
this.runner = newRunnerPod(
*
* App assumes that it has full control of the process. It acts as a top-level
* error handler and will exit the process with errors when uncaught resolutions
* and errors occur.
*/
export class App {
/**
* exitOnError controls whether the app will exit when an uncaught exception or unhandled rejection occurs.
*
* exitOnError can be set to false in order to run tests on the error handling.
* In general, though, it should be left on. In some cases, by the time the
* process trap is invoked, the runtime is not in a good state to continue.
*/
public exitOnError: boolean = true;
protected errorsHandled: boolean = false;
protected logger: Logger = new ContextLogger("app");
protected lastEvent: events.BrigadeEvent;
protected projectID: string;
protected projectNS: string;
// On project loading error, this value may be passed. In all other cases,
// it is overwritten by an actual project.
protected proj: events.Project = new events.Project();
// true if the "after" event has fired.
protected afterHasFired: boolean = false;
protected storageIsDestroyed: boolean = false;
/**
* loadProject is a function that loads projects.
*/
public loadProject: ProjectLoader = k8s.loadProject;
/**
* buildStorage controls the per-build storage layer.
return this.data;
}
}
/**
* BuildStorage manages per-build storage for a build.
*
* BuildStorage implements the app.BuildStorage interface.
*
* Storage is implemented as a PVC. The PVC backing it MUST be ReadWriteMany.
*/
export class BuildStorage {
proj: Project;
name: string;
build: string;
logger: ContextLogger = new ContextLogger("k8s");
options: KubernetesOptions = Object.assign({}, options);
/**
* create initializes a new PVC for storing data.
*/
public create(
e: BrigadeEvent,
project: Project,
size: string
): Promise {
this.proj = project;
this.name = e.workerID.toLowerCase();
this.build = e.buildID;
this.logger.logLevel = e.logLevel;
let pvc = this.buildPVC(size);