diff --git a/ReadMe.md b/ReadMe.md index 4804f41..9d67aa5 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -37,6 +37,9 @@ The docker build context. Default: `.` ### `target` If you use multi-stage build and want to stop builing at a certain image, you can use this field. Default value is empty. +### `build_args` +Pass a list of env vars as build-args for docker-build, separated by commas. ie: `HOST=db.default.svc.cluster.local:5432,USERNAME=db_user` + ## Example usage Put desired yml section in the `.github/workflows/build.yml` file ### [`To perform build & push on every git push`](https://github.com/RafikFarhad/example/build.yml) diff --git a/action.yml b/action.yml index 9833826..ed4c1af 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: registry: description: The registry where the image should be pushed required: false - default: gcr.io + default: 'gcr.io' project_id: description: The project id required: true @@ -31,11 +31,14 @@ inputs: context: description: Docker build context required: false - default: . + default: '.' target: description: Mutli-staged build target required: false default: "" + build_args: + description: "Pass a list of env vars as build-args for docker-build, separated by commas" + required: false runs: using: docker image: Dockerfile diff --git a/entrypoint.sh b/entrypoint.sh index bcf7582..b2ffc8f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -46,9 +46,17 @@ echo "Building image ..." [ -z $INPUT_DOCKERFILE ] && FILE_ARG="" || FILE_ARG="--file $INPUT_DOCKERFILE" -echo "docker build $TARGET_ARG -t $TEMP_IMAGE_NAME $INPUT_CONTEXT $FILE_ARG" -if docker build $TARGET_ARG -t $TEMP_IMAGE_NAME $INPUT_CONTEXT $FILE_ARG; then +if [ ! -z "$INPUT_BUILD_ARGS" ]; then + for ARG in $(echo "$INPUT_BUILD_ARGS" | tr ',' '\n'); do + BUILD_PARAMS="$BUILD_PARAMS --build-arg ${ARG}" + done +fi + +echo "docker build $BUILD_PARAMS $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT" + + +if docker build $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT; then echo "Image built ..." else echo "Image building failed. Exiting ..." diff --git a/example/build_all_option.yml b/example/build_all_option.yml index 4357a3a..5ca6d92 100644 --- a/example/build_all_option.yml +++ b/example/build_all_option.yml @@ -14,3 +14,5 @@ jobs: dockerfile: ./docker/Dockerfile.prod target: prod context: ./docker + build_args: A=foo,B=bar +