Skip to content

Commit

Permalink
Add support to enable ECR image scan (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
hari2192 authored and 72636c committed Nov 14, 2019
1 parent 116a092 commit 67551e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ steps:

Name of the ECR repository.

- `scan-on-push` (optional, boolean)

Whether to [automatically scan images](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html#scanning-repository) pushed to the ECR repository for vulnerabilities.

Omitting this option will leave the existing image scanning configuration untouched.

- `repository-policy` (optional, string)

Path in local repository to the repository policy file.
Expand Down
16 changes: 15 additions & 1 deletion hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ecr_exists() {
--query 'repositories[0].registryId'
}

upsert_ecr() {
upsert_ecr() {
local repository_name="${1}"

if ! ecr_exists "${repository_name}"; then
Expand All @@ -37,6 +37,20 @@ upsert_ecr() {
aws ecr put-lifecycle-policy \
--repository-name "${repository_name}" \
--lifecycle-policy-text "file://${lifecycle_policy_file}"

if [[ "${BUILDKITE_PLUGIN_CREATE_ECR_SCAN_ON_PUSH:-}" =~ ^(true|on|1)$ ]]; then
echo '--- Setting ECR image scanning configuration as enabled'
aws ecr put-image-scanning-configuration \
--repository-name "${repository_name}" \
--image-scanning-configuration \
scanOnPush=true
elif [[ "${BUILDKITE_PLUGIN_CREATE_ECR_SCAN_ON_PUSH:-}" =~ ^(false|off|0)$ ]]; then
echo '--- Setting ECR image scanning configuration as disabled'
aws ecr put-image-scanning-configuration \
--repository-name "${repository_name}" \
--image-scanning-configuration \
scanOnPush=false
fi
}

if [[ -z ${BUILDKITE_PLUGIN_CREATE_ECR_NAME:-} ]]; then
Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ configuration:
type: string
name:
type: string
scan-on-push:
type: boolean
repository-policy:
type: string
required: ['name']

0 comments on commit 67551e9

Please sign in to comment.