Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Docker Flags support #42

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,58 @@ This action can be used to perform on every git `push` or every `tag` creation.
## Inputs

### `gcloud_service_key`
The service account key of google cloud. The JSON file can be encoded in base64 or in plain text.

The service account key of google cloud. The JSON file can be encoded in base64 or in plain text.

Prior to version 4.1 - This field is required.

From version 5 - This field is optional when you are using workload identity with [google-github-actions/auth](https://github.com/google-github-actions/auth)

### `registry`

The registry where the image should be pushed. Default `gcr.io`.

### `project_id`

The project id. This field is required.

### `image_name`

The image name. This field is required.

### `image_tag`

The tag for the image. To create multiple tags of the same image, provide a comma (`,`) separated tag name (e.g. `v2.1,v2,latest`).

Default: `latest`.

To use the pushed `Tag Name` as image tag, see the [example](https://github.com/RafikFarhad/push-to-gcr-github-action/blob/master/examples/build_only_tags.yml).

### `dockerfile`
The image building Dockerfile.

The image building Dockerfile.
If the context is not the root of the repository, `Dockerfile` from the context folder will be used.

Default: `./Dockerfile`.

### `context`

The docker build context. Default: `.`

### `target`

If you use a multi-stage build and want to stop building at a certain image, you can use this field. The 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`

### `push_only`

If you want to skip the build step and just push the image built by any previous step, use this option. The default for this is `false`.

## Permissions

The service key you provided must have the `Storage Admin` permission to push the image to GCR.
It is possible to use a lower access level `Storage Object Admin`, but it will work only if the registry is already created. You must also add the `Storage Legacy Bucket Reader` permission to the `artifacts.<project id>.appspot.com` bucket for the given service account.

Expand All @@ -57,9 +69,11 @@ It is possible to use a lower access level `Storage Object Admin`, but it will w
To create service key/account visit [here](https://console.cloud.google.com/iam-admin/serviceaccounts)

### Workload Identity Federation

If you want to use [Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation), follow the steps from [here](https://github.com/google-github-actions/auth#setting-up-workload-identity-federation) to set up **Workload Identity Federation**

## Example usage

```yaml
name: Push to GCR GitHub Action
on: [push]
Expand Down Expand Up @@ -87,11 +101,13 @@ jobs:
dockerfile: ./docker/Dockerfile.prod
context: ./docker
```

[A complete workflow example](https://github.com/RafikFarhad/push-to-gcr-github-action/tree/master/.github/workflows) with all type of authentication flavour

[More Example](https://github.com/RafikFarhad/push-to-gcr-github-action/tree/master/examples)

## Contribution

- Fork
- Implement your awesome idea or fix a bug
- Create PR 🎉
Expand Down
12 changes: 8 additions & 4 deletions action.yaml
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,7 +31,7 @@ inputs:
context:
description: Docker build context
required: false
default: '.'
default: "."
target:
description: Multi-staged build target
required: false
Expand All @@ -42,7 +42,11 @@ inputs:
push_only:
description: Skip the build step and just push an image
required: false
default: false
default: "false"
docker_flags:
description: An optional param to pass flags & other build parameters to docker
required: false
default: ""
runs:
using: docker
image: docker://ghcr.io/rafikfarhad/push-to-gcr-action:1.0.0
image: docker://ghcr.io/nextstepguru/push-to-gcr-action:v1.0.0
8 changes: 4 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#version :2.0.1
#usage :./entrypoint.sh
#notes :Required env values are: INPUT_REGISTRY,INPUT_PROJECT_ID,INPUT_IMAGE_NAME
# Optional env values are: INPUT_GCLOUD_SERVICE_KEY,INPUT_IMAGE_TAG,INPUT_DOCKERFILE,INPUT_TARGET,INPUT_CONTEXT,INPUT_BUILD_ARGS
# Optional env values are: INPUT_GCLOUD_SERVICE_KEY,INPUT_IMAGE_TAG,INPUT_DOCKERFILE,INPUT_TARGET,INPUT_CONTEXT,INPUT_BUILD_ARGS,INPUT_DOCKER_FLAGS
#bash_version :5.0.17(1)-release
###################################################

Expand Down Expand Up @@ -53,7 +53,7 @@ fi
ALL_IMAGE_TAG=($(python3 -c "print(' '.join(list(set([v for v in [v.strip() for v in '$INPUT_IMAGE_TAG'.split(',')] if v]))))"))

# default to 'latest' when $ALL_IMAGE_TAG is empty
if [ ${#ALL_IMAGE_TAG[@]} -eq 0 ] ; then
if [ ${#ALL_IMAGE_TAG[@]} -eq 0 ]; then
echo "INPUT_IMAGE_TAG tag is not parsable. Using latest by default"
ALL_IMAGE_TAG=(latest)
fi
Expand All @@ -73,9 +73,9 @@ else
done
fi

echo "docker build $BUILD_PARAMS $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT"
echo "docker build $INPUT_DOCKER_FLAGS $BUILD_PARAMS $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT"

if docker build $BUILD_PARAMS $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT; then
if docker build $INPUT_DOCKER_FLAGS $BUILD_PARAMS $TARGET_ARG -t $TEMP_IMAGE_NAME $FILE_ARG $INPUT_CONTEXT; then
echo "Image built ..."
else
echo "Image building failed. Exiting ..."
Expand Down