Skip to content

Commit cb4c97c

Browse files
authored
feat: perform env subst on image for the generate_sbom command (#53)
Allow providing the environment variable as the value of the `image` parameter for the `generate_sbom` command. Useful for cases when image name is not known upfront.
1 parent 6be7004 commit cb4c97c

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

.circleci/test-deploy.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ jobs:
6161
tag: v1
6262
path: ./sample
6363
docker-context: ./sample
64+
- run:
65+
name: Export image as env
66+
command: echo "export IMAGE_TO_USE=docker.io/security-sample:v1" >> "${BASH_ENV}"
6467
- security/generate_sbom:
65-
image: docker.io/security-sample:v1
68+
image: ${IMAGE_TO_USE}
6669
out_path: /tmp/sample-sbom.json
6770
- run:
6871
name: Check SBOM output

src/commands/generate_sbom.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ parameters:
1313
The Docker image to generate SBOM from. Support following schemes
1414
(1) repo-name/image-name:tag (2) /path/to/image.tar. Bases on provided scheme
1515
it will either use local Docker daemon or tarball archive from disk as a source.
16+
Performs environment variable substitution before using the value of this parameter.
1617
format:
1718
type: enum
1819
enum:

src/examples/image_sbom.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ usage:
1414
jobs:
1515
sbom:
1616
executor: security/node
17+
environment:
18+
TARGET_IMAGE: studiondev/node-security:lts
1719
steps:
1820
- checkout
1921
- security/generate_sbom:
20-
image: studiondev/node-security:lts
22+
image: ${TARGET_IMAGE}
2123
format: github-json
2224
out_path: /tmp/reports/lts-sbom.json
2325
exclude: /etc /home/**/*.json

src/scripts/generate-sbom.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ if [[ -z "${PARAM_STR_IMAGE}" ]]; then
66
exit 1
77
fi
88

9+
PARAM_STR_IMAGE=$(circleci env subst "${PARAM_STR_IMAGE}")
10+
911
IMAGE_SOURCE="docker"
1012

1113
if [[ "${PARAM_STR_IMAGE}" == *.tar ]]; then

0 commit comments

Comments
 (0)