Skip to content

Commit

Permalink
Merge pull request #32 from pablitoc/master
Browse files Browse the repository at this point in the history
Added ability to enable Image Scanning
  • Loading branch information
kciter authored Jul 7, 2021
2 parents 79255b7 + 0865f71 commit ad76cf4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This Action allows you to create Docker images and push into a ECR repository.
| `create_repo` | `boolean` | `false` | Set this to true to create the repository if it does not already exist |
| `set_repo_policy` | `boolean` | `false` | Set this to true to set a IAM policy on the repository |
| `repo_policy_file` | `string` | `repo-policy.json` | Set this to repository policy statement json file. only used if the set_repo_policy is set to true |
| `image_scanning_configuration:` | `boolean` | `false` | Set this to True if you want AWS to scan your images for vulnerabilities |
| `tags` | `string` | `latest` | Comma-separated string of ECR image tags (ex latest,1.0.0,) |
| `dockerfile` | `string` | `Dockerfile` | Name of Dockerfile to use |
| `extra_build_args` | `string` | `""` | Extra flags to pass to docker build (see docs.docker.com/engine/reference/commandline/build) |
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: AWS ECR
author: Lee Sun-Hyoup <kciter@naver.com>
author: Lee Sun-Hyoup <kciter@naver.com>, Pablo Castillo <pablo@castillo.is>
branding:
icon: upload-cloud
color: orange
Expand Down Expand Up @@ -36,6 +36,9 @@ inputs:
tags:
description: Comma-separated string of ECR image tags
default: latest
image_scanning_configuration:
description: Set this to True if you want AWS to scan your images for vulnerabilities
default: false
dockerfile:
description: Name of Dockerfile to use
default: Dockerfile
Expand Down
13 changes: 13 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ INPUT_TAGS="${INPUT_TAGS:-latest}"
INPUT_CREATE_REPO="${INPUT_CREATE_REPO:-false}"
INPUT_SET_REPO_POLICY="${INPUT_SET_REPO_POLICY:-false}"
INPUT_REPO_POLICY_FILE="${INPUT_REPO_POLICY_FILE:-repo-policy.json}"
INPUT_IMAGE_SCANNING_CONFIGURATION="${INPUT_IMAGE_SCANNING_CONFIGURATION:-false}"

function main() {
sanitize "${INPUT_ACCESS_KEY_ID}" "access_key_id"
sanitize "${INPUT_SECRET_ACCESS_KEY}" "secret_access_key"
sanitize "${INPUT_REGION}" "region"
sanitize "${INPUT_ACCOUNT_ID}" "account_id"
sanitize "${INPUT_REPO}" "repo"
sanitize "${INPUT_IMAGE_SCANNING_CONFIGURATION}" "image_scanning_configuration"

ACCOUNT_URL="$INPUT_ACCOUNT_ID.dkr.ecr.$INPUT_REGION.amazonaws.com"

Expand All @@ -25,6 +27,7 @@ function main() {
create_ecr_repo $INPUT_CREATE_REPO
set_ecr_repo_policy $INPUT_SET_REPO_POLICY
docker_push_to_ecr $INPUT_TAGS $ACCOUNT_URL
image_scanning_configuration $INPUT_IMAGE_SCANNING_CONFIGURATION

This comment has been minimized.

Copy link
@Dovchik

Dovchik Jul 7, 2021

Function name is deferent, put_image_scanning_configuration is declared, but no image_scanning_configuration which causes and fails the action:

/entrypoint.sh: line 30: image_scanning_configuration: command not found
}

function sanitize() {
Expand Down Expand Up @@ -96,6 +99,16 @@ function set_ecr_repo_policy() {
fi
}

function put_image_scanning_configuration() {
if [ "${1}" = true ]; then
echo "== START SET IMAGE SCANNING CONFIGURATION"
if [ -f "${INPUT_IMAGE_SCANNING_CONFIGURATION}" ]; then
aws ecr put-image-scanning-configuration --repository-name $INPUT_REPO --image-scanning-configuration scanOnPush=${INPUT_IMAGE_SCANNING_CONFIGURATION}
echo "== FINISHED SET IMAGE SCANNING CONFIGURATION"
fi
fi
}

function run_pre_build_script() {
if [ ! -z "${1}" ]; then
echo "== START PREBUILD SCRIPT"
Expand Down

0 comments on commit ad76cf4

Please sign in to comment.