Skip to content

Commit

Permalink
Merge pull request #30 from jondavidjohn/image-cache-from
Browse files Browse the repository at this point in the history
Implement top level cache-from usage
  • Loading branch information
kciter authored Jun 30, 2021
2 parents 034328f + 7c7ca9c commit 79255b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This Action allows you to create Docker images and push into a ECR repository.
| `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) |
| `cache_from` | `string` | `""` | Images to use as cache for the docker build (see `--cache-from` argument docs.docker.com/engine/reference/commandline/build) |
| `path` | `string` | `.` | Path to Dockerfile, defaults to the working directory |
| `prebuild_script` | `string` | | Relative path from top-level to script to run before Docker build |

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ inputs:
extra_build_args:
description: Extra flags to pass to docker build (see docs.docker.com/engine/reference/commandline/build)
default: ''
cache_from:
description: Images to use as cache for the docker build (see `--cache-from` argument docs.docker.com/engine/reference/commandline/build)
default: ''
path:
description: Path to Dockerfile, defaults to the working directory
default: .
Expand Down
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ function docker_build() {
docker_tag_args="$docker_tag_args -t $2/$INPUT_REPO:$tag"
done

if [ -n "${INPUT_CACHE_FROM}" ]; then
for i in ${INPUT_CACHE_FROM//,/ }; do
docker pull $i
done

INPUT_EXTRA_BUILD_ARGS="$INPUT_EXTRA_BUILD_ARGS --cache-from=$INPUT_CACHE_FROM"
fi

docker build $INPUT_EXTRA_BUILD_ARGS -f $INPUT_DOCKERFILE $docker_tag_args $INPUT_PATH
echo "== FINISHED DOCKERIZE"
}
Expand Down

0 comments on commit 79255b7

Please sign in to comment.