From eba0839622fdb03f6248b188c1fcc9308532304c Mon Sep 17 00:00:00 2001 From: David O'Dell Date: Mon, 21 Sep 2020 12:39:34 -0700 Subject: [PATCH 1/6] added build args Signed-off-by: David O'Dell --- entrypoint.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9806912..c201bb3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -43,7 +43,14 @@ 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" +BUILD_PARAMS="--build-arg commit=$SHA" +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 $INPUT_CONTEXT $FILE_ARG" if docker build $TARGET_ARG -t $TEMP_IMAGE_NAME $INPUT_CONTEXT $FILE_ARG; then echo "Image built ..." From 10b426acda2484a69d29beb5ad7b0d68b04d0226 Mon Sep 17 00:00:00 2001 From: David O'Dell Date: Mon, 21 Sep 2020 14:25:55 -0700 Subject: [PATCH 2/6] add build args as an option Signed-off-by: David O'Dell --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 549bddd..89e194e 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,9 @@ inputs: 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 From 0a59ac3da73846d688e01b8d7c99ee54bac891aa Mon Sep 17 00:00:00 2001 From: David O'Dell Date: Thu, 17 Dec 2020 16:16:53 -0800 Subject: [PATCH 3/6] test build-args Signed-off-by: David O'Dell --- action.yml | 6 +++--- entrypoint.sh | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index 89e194e..c3fbba0 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 @@ -23,7 +23,7 @@ inputs: image_tag: description: Tag name required: false - default: latest + default: foobar dockerfile: description: Dockerfile that will build the image required: false @@ -31,7 +31,7 @@ inputs: context: description: Docker build context required: false - default: . + default: '.' target: description: Mutli-staged build target required: false diff --git a/entrypoint.sh b/entrypoint.sh index c201bb3..e34d264 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -19,7 +19,8 @@ function split_csv() { done unset IFS } - +echo "input_context $INPUT_CONTEXT" +env | grep INPUT ALL_IMAGE_TAG=() echo "Authenticating docker to gcloud ..." @@ -43,16 +44,17 @@ echo "Building image ..." [ -z $INPUT_DOCKERFILE ] && FILE_ARG="" || FILE_ARG="--file $INPUT_DOCKERFILE" -BUILD_PARAMS="--build-arg commit=$SHA" + 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 $INPUT_CONTEXT $FILE_ARG" +echo "docker build $BUILD_PARAMS $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT" + -if docker build $TARGET_ARG -t $TEMP_IMAGE_NAME $INPUT_CONTEXT $FILE_ARG; then +if docker build $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT; then echo "Image built ..." else echo "Image building failed. Exiting ..." From 21daaa6f9ab6cb8e4cc8ca80a7f8998ce96db009 Mon Sep 17 00:00:00 2001 From: David O'Dell Date: Thu, 17 Dec 2020 16:37:26 -0800 Subject: [PATCH 4/6] add build-args to examples Signed-off-by: David O'Dell --- entrypoint.sh | 3 +-- example/build_all_option.yml | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index e34d264..ca2ddbb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -19,8 +19,7 @@ function split_csv() { done unset IFS } -echo "input_context $INPUT_CONTEXT" -env | grep INPUT + ALL_IMAGE_TAG=() echo "Authenticating docker to gcloud ..." diff --git a/example/build_all_option.yml b/example/build_all_option.yml index 8436a83..b5876dd 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 + From 49fd704388d78462ec1ef9deece4cfddc598ebcc Mon Sep 17 00:00:00 2001 From: David O'Dell Date: Thu, 17 Dec 2020 16:42:29 -0800 Subject: [PATCH 5/6] updated readme Signed-off-by: David O'Dell --- ReadMe.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ReadMe.md b/ReadMe.md index 63baf5a..8a21cdb 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) From ad2c3f519271e0ef1a6c753149b9ada6eec3f3bf Mon Sep 17 00:00:00 2001 From: David O'Dell Date: Thu, 17 Dec 2020 16:47:17 -0800 Subject: [PATCH 6/6] removed test value from actions Signed-off-by: David O'Dell --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c3fbba0..0ebc3f9 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: image_tag: description: Tag name required: false - default: foobar + default: latest dockerfile: description: Dockerfile that will build the image required: false