Skip to content

Commit

Permalink
Merge pull request #7 from dodizzle/master
Browse files Browse the repository at this point in the history
Added build-args for the docker build
  • Loading branch information
RafikFarhad authored Dec 18, 2020
2 parents 6f2b6bc + ad2c3f5 commit 0b2858b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
12 changes: 10 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."
Expand Down
2 changes: 2 additions & 0 deletions example/build_all_option.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ jobs:
dockerfile: ./docker/Dockerfile.prod
target: prod
context: ./docker
build_args: A=foo,B=bar

0 comments on commit 0b2858b

Please sign in to comment.