Skip to content

Commit

Permalink
ci: scan images (#1875)
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Rancourt <kent.rancourt@microsoft.com>
  • Loading branch information
krancour authored Mar 21, 2022
1 parent 51a3bd9 commit c8607d7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
90 changes: 83 additions & 7 deletions .brigade/brigade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,40 @@ class BuildImageJob extends JobWithSource {
}
}

class ScanJob extends MakeTargetJob {
constructor(image: string, event: Event) {
const env = {}
const secrets = event.project.secrets
if (secrets.unstableImageRegistry) {
env["DOCKER_REGISTRY"] = secrets.unstableImageRegistry
}
if (secrets.unstableImageRegistryOrg) {
env["DOCKER_ORG"] = secrets.unstableImageRegistryOrg
}
super(`scan-${image}`, [`scan-${image}`], dockerClientImg, event, env)
this.fallible = true
}
}

class PublishSBOMJob extends MakeTargetJob {
constructor(image: string, event: Event, version: string) {
const secrets = event.project.secrets
const env = {
"GITHUB_ORG": secrets.githubOrg,
"GITHUB_REPO": secrets.githubRepo,
"GITHUB_TOKEN": secrets.githubToken,
"VERSION": version
}
if (secrets.stableImageRegistry) {
env["DOCKER_REGISTRY"] = secrets.stableImageRegistry
}
if (secrets.stableImageRegistryOrg) {
env["DOCKER_ORG"] = secrets.stableImageRegistryOrg
}
super(`publish-sbom-${image}`, [`publish-sbom-${image}`], dockerClientImg, event, env)
}
}

// A map of all jobs. When a ci:job_requested event wants to re-run a single
// job, this allows us to easily find that job by name.
const jobs: {[key: string]: (event: Event, version?: string) => Job } = {}
Expand Down Expand Up @@ -202,42 +236,84 @@ const buildArtemisJob = (event: Event, version?: string) => {
}
jobs[buildArtemisJobName] = buildArtemisJob

const scanArtemisJobName = "scan-artemis"
const scanArtemisJob = (event: Event) => {
return new ScanJob("artemis", event)
}
jobs[scanArtemisJobName] = scanArtemisJob

const buildAPIServerJobName = "build-apiserver"
const buildAPIServerJob = (event: Event, version?: string) => {
return new BuildImageJob("apiserver", event, version)
}
jobs[buildAPIServerJobName] = buildAPIServerJob

const scanAPIServerJobName = "scan-apiserver"
const scanAPIServerJob = (event: Event) => {
return new ScanJob("apiserver", event)
}
jobs[scanAPIServerJobName] = scanAPIServerJob

const buildGitInitializerJobName = "build-git-initializer"
const buildGitInitializerJob = (event: Event, version?: string) => {
return new BuildImageJob("git-initializer", event, version)
}
jobs[buildGitInitializerJobName] = buildGitInitializerJob

const scanGitInitializerJobName = "scan-git-initializer"
const scanGitInitializerJob = (event: Event) => {
return new ScanJob("git-initializer", event)
}
jobs[scanGitInitializerJobName] = scanGitInitializerJob

const buildLoggerLinuxJobName = "build-logger"
const buildLoggerLinuxJob = (event: Event, version?: string) => {
return new BuildImageJob("logger", event, version)
}
jobs[buildLoggerLinuxJobName] = buildLoggerLinuxJob

const scanLoggerLinuxJobName = "scan-logger"
const scanLoggerLinuxJob = (event: Event) => {
return new ScanJob("logger", event)
}
jobs[scanLoggerLinuxJobName] = scanLoggerLinuxJob

const buildObserverJobName = "build-observer"
const buildObserverJob = (event: Event, version?: string) => {
return new BuildImageJob("observer", event, version)
}
jobs[buildObserverJobName] = buildObserverJob

const scanObserverJobName = "scan-observer"
const scanObserverJob = (event: Event) => {
return new ScanJob("observer", event)
}
jobs[scanObserverJobName] = scanObserverJob

const buildSchedulerJobName = "build-scheduler"
const buildSchedulerJob = (event: Event, version?: string) => {
return new BuildImageJob("scheduler", event, version)
}
jobs[buildSchedulerJobName] = buildSchedulerJob

const scanSchedulerJobName = "scan-scheduler"
const scanSchedulerJob = (event: Event) => {
return new ScanJob("scheduler", event)
}
jobs[scanSchedulerJobName] = scanSchedulerJob

const buildWorkerJobName = "build-worker"
const buildWorkerJob = (event: Event, version?: string) => {
return new BuildImageJob("worker", event, version)
}
jobs[buildWorkerJobName] = buildWorkerJob

const scanWorkerJobName = "scan-worker"
const scanWorkerJob = (event: Event) => {
return new ScanJob("worker", event)
}
jobs[scanWorkerJobName] = scanWorkerJob

const buildBrigadierJobName = "build-brigadier"
const buildBrigadierJob = (event: Event) => {
return new MakeTargetJob(buildBrigadierJobName, ["build-brigadier"], jsImg, event)
Expand Down Expand Up @@ -347,13 +423,13 @@ events.on("brigade.sh/github", "ci:pipeline_requested", async event => {
validateExamplesJob(event)
),
new ConcurrentGroup( // Build everything
buildArtemisJob(event),
buildAPIServerJob(event),
buildGitInitializerJob(event),
buildLoggerLinuxJob(event),
buildObserverJob(event),
buildSchedulerJob(event),
buildWorkerJob(event),
new SerialGroup(buildArtemisJob(event), scanArtemisJob(event)),
new SerialGroup(buildAPIServerJob(event), scanAPIServerJob(event)),
new SerialGroup(buildGitInitializerJob(event), scanGitInitializerJob(event)),
new SerialGroup(buildLoggerLinuxJob(event), scanLoggerLinuxJob(event)),
new SerialGroup(buildObserverJob(event), scanObserverJob(event)),
new SerialGroup(buildSchedulerJob(event), scanSchedulerJob(event)),
new SerialGroup(buildWorkerJob(event), scanWorkerJob(event)),
buildBrigadierJob(event),
buildCLIJob(event)
),
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ build-cli:
../scripts/build-cli.sh \
'

################################################################################
# Image security #
################################################################################

.PHONY: scan-%
scan-%:
grype $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) -f medium

################################################################################
# Publish #
################################################################################
Expand Down

0 comments on commit c8607d7

Please sign in to comment.