-
Notifications
You must be signed in to change notification settings - Fork 21
feat(antivirusCI): Add bridge to swx-jenkins-lib's antivirus var #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
orbalayla-nvidia
wants to merge
3
commits into
Mellanox:master
Choose a base branch
from
orbalayla-nvidia:feat/antivirus
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3ebfa36
feat(antivirusCI): Add bridge to swx-jenkins-lib's antivirus var
orbalayla-nvidia f21597d
TEMP: load swx-jenkins-lib from the antivirus var's fork branch
orbalayla-nvidia eaafa7b
fix(antivirusCI): harden arg validation and interruption handling
orbalayla-nvidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| # Example matrix that runs the GLIT antivirus scanner via the `antivirus` | ||
| # var in Mellanox-lab/swx-jenkins-lib. The executing container must have | ||
| # /auto/GLIT mounted (hostPath volume below). | ||
|
|
||
| job: antivirus-example | ||
|
|
||
| failFast: false | ||
| timeout_minutes: 30 | ||
|
|
||
| env: | ||
| # Default keeps the example self-contained; override for a real release path. | ||
| RELEASE_PATH: '/auto/GLIT' | ||
|
|
||
| kubernetes: | ||
| cloud: swx-k8s | ||
| nodeSelector: 'kubernetes.io/arch=amd64' | ||
|
|
||
| volumes: | ||
| - {mountPath: /auto/GLIT, hostPath: /auto/GLIT} | ||
|
|
||
| runs_on_dockers: | ||
| - url: 'ubuntu:22.04' | ||
| name: 'av_runner' | ||
| tag: '22.04' | ||
| arch: 'x86_64' | ||
|
|
||
| steps: | ||
| - name: Antivirus scan | ||
| shell: action | ||
| module: antivirusCI | ||
| run: scan | ||
| containerSelector: '{name:"av_runner"}' | ||
| args: | ||
| path: '${RELEASE_PATH}' | ||
| skipIfMissing: true | ||
| archiveArtifacts: 'logs/antivirus_*.log' | ||
This file contains hidden or 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,58 @@ | ||
| #!/usr/bin/env groovy | ||
|
|
||
| // Matrix-side bridge to the `antivirus` var in Mellanox-lab/swx-jenkins-lib. | ||
| // Modeled on slurmCI. | ||
|
|
||
| int call(ctx, oneStep, config) { | ||
| def args = (oneStep.args ?: [:]).clone() | ||
|
|
||
| def libRef = args.remove('ref') | ||
| if (libRef) { | ||
| library(identifier: "swx-jenkins-lib@${libRef}") | ||
| } else { | ||
| // TEMP: load swx-jenkins-lib from the fork branch carrying the | ||
| // antivirus var (https://github.com/Mellanox-lab/swx-jenkins-lib/pull/4). | ||
| // Revert to library('swx-jenkins-lib') before merging. | ||
| library('github.com/orbalayla-nvidia/swx-jenkins-lib@feat/antivirus') | ||
| } | ||
|
|
||
| if (!(args?.containsKey('path') || args?.containsKey('paths'))) { | ||
| ctx.reportFail(oneStep.name, "antivirusCI: 'path' or 'paths' arg required") | ||
| return 1 | ||
| } | ||
|
|
||
| // Resolve ${VAR} on String values only; lists pass through. | ||
| for (def entry in ctx.entrySet(args)) { | ||
| if (!(entry.value instanceof String)) continue | ||
| def resolved = ctx.resolveTemplate(['env': env], entry.value, config) | ||
| def pass2 = resolved | ||
| def safety = 0 | ||
| while (pass2.contains('${') && safety++ < 20) { | ||
| def start = pass2.indexOf('${') | ||
| def end = pass2.indexOf('}', start) | ||
| if (end == -1) break | ||
| def name = pass2.substring(start + 2, end) | ||
| def val = env."${name}" | ||
| if (val == null) break | ||
| pass2 = pass2.substring(0, start) + val + pass2.substring(end + 1) | ||
| } | ||
| args[entry.key] = pass2 | ||
| } | ||
|
|
||
| def vars = [] | ||
| vars += ctx.toEnvVars(config, config.env) | ||
| vars += ctx.toEnvVars(config, oneStep.env) | ||
|
|
||
| int rc = 0 | ||
| withEnv(vars) { | ||
| try { | ||
| antivirus.scan(args) | ||
| } catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException fie) { | ||
| throw fie | ||
| } catch (Exception e) { | ||
| ctx.reportFail(oneStep.name, "antivirus.scan failed: ${e.message}") | ||
| rc = 1 | ||
| } | ||
| } | ||
| return rc | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.