Releases: RafikFarhad/push-to-gcr-github-action
v5-rc1 - Release Candidate 1
Fixed:
- #46 - Using push_only option causes the job to fail
v5-beta :: Workload Identity Federation Support
Push to GCR Github Action
Version 5-beta
Change log:
- Feature: support of Workload Identity Federation #26
- Bug fix: #30 - Unable to parse JSON key when it is empty
v4.1.0
Push to GCR Github Action
Version 4.1
Change log:
- Feature:
gcloud_service_key
now supports plan text along with base64 encoded value - #25 - Sanitize image_tags (remove whitepsaces and empty values) - #20
- Removed unnecessary steps
google-github-actions/setup-gcloud
- #21
An action that builds docker image and pushes to Google Cloud Registry.
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. This field is required.
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.
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.
To create service key/account visit here
Example usage
name: Push to GCR GitHub Action
on: [push]
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: RafikFarhad/push-to-gcr-github-action@v4.1
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }} # can be base64 encoded or plain text
registry: gcr.io
project_id: my-awesome-project
image_name: backend
image_tag: latest,v1
dockerfile: ./docker/Dockerfile.prod
context: ./docker
[More Example] (https://github.com/RafikFarhad/push-to-gcr-github-action/tree/master/example)
[Workflow Example] (https://github.com/RafikFarhad/push-to-gcr-github-action/tree/master/.github/workflows)
Contribution
- Fork
- Implement your awesome idea or fix a bug
- Create PR 🎉
NB: The included workflow which tests the action's basic functionalities needs a Github secret named JSON_GCLOUD_SERVICE_ACCOUNT_JSON
.
Currently, the workflow is not testable for forked repositories but I have an action item to enable this.
Version 4.0.0
Push to GCR Github Action
Version 4
Change log:
- Feature: Building docker image can be skipped with
push_only
input #17 - Thanks @twoversionsofme - Gcloud installation replaced by
google-github-actions/setup-gcloud
- Solved #19 - From this version using the following step is mandatory:
- uses: google-github-actions/setup-gcloud@master
Push to GCR GitHub Action
An action that build docker image and push to Google Cloud Registry.
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 service accout json file must be encoded in base64. This field is required.
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 tag of the same image, provide comma (,
) separeted tag name (e.g. v2.1,v2,latest
).
Default: latest
.
To use the pushed Tag Name
as image tag, see the example.
dockerfile
The image building Dockerfile.
If context is changed, Dockerfile
from context folder will be used.
Default: ./Dockerfile
.
context
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
push_only
If you want to skip the build step and just push the image built by any previous step, use this option. 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 for already created registry. You must also add the Storage Legacy Bucket Reader
permission to the artifacts.<project id>.appspot.com
bucket for the given service account.
To create service key/account visit here
Example usage
Put desired yml section in the .github/workflows/build.yml
file
To perform build & push on every git push
name: Push to GCR GitHub Action
on: [push]
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@master
- uses: RafikFarhad/push-to-gcr-github-action@v4
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_id: my-awesome-project
image_name: server-end
To perform build & push only on tag publish
name: Push to GCR GitHub Action
on:
push:
tags:
- '*'
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@master
- name: Get the version
id: get_tag_name
run: echo ::set-output name=GIT_TAG_NAME::${GITHUB_REF/refs\/tags\//}
- uses: RafikFarhad/push-to-gcr-github-action@v4
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_id: my-awesome-project
image_name: server-end
image_tag: ${{ steps.get_tag_name.outputs.GIT_TAG_NAME}}
dockerfile: ./build/Dockerfile
To just push an image on every git push
name: Push image to GCR GitHub Action
on: [push]
jobs:
just-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@master
- uses: RafikFarhad/push-to-gcr-github-action@v4
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_id: my-awesome-project
image_name: server-end
push_only: true
What's Changed
- Add Storage Legacy Bucket Reader permission instructions by @jdddog in #13
- Add option to just push an already built image by @twoversionsofme in #18
New Contributors
- @jdddog made their first contribution in #13
- @twoversionsofme made their first contribution in #18
Full Changelog: v3.0.2...v4
Version 3.0.2
Push to GCR Github Action
Version 3.0.2
Change log:
- Fixed broken support for
--build-arg
pointed out by @jsnb - #8 - Update ReadMe for more clarity - Thanks @nrfribeiro and @krtk6160 - #9
Push to GCR GitHub Action
An action that build docker image and push to Google Cloud Registry.
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 service accout json file must be encoded in base64. This field is required.
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 tag of the same image, provide comma (,
) separeted tag name (e.g. v2.1,v2,latest
).
Default: latest
.
To use the pushed Tag Name
as image tag, see the example.
dockerfile
The image building Dockerfile.
If context is changed, Dockerfile
from context folder will be used.
Default: ./Dockerfile
.
context
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
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 for already created registry.
To create service key/account visit here
Example usage
Put desired yml section in the .github/workflows/build.yml
file
To perform build & push on every git push
name: Push to GCR GitHub Action
on: [push]
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: RafikFarhad/push-to-gcr-github-action@v3.0.2
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_id: my-awesome-project
image_name: server-end
To perform build & push only on tag publish
name: Push to GCR GitHub Action
on:
push:
tags:
- '*'
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get the version
id: get_tag_name
run: echo ::set-output name=GIT_TAG_NAME::${GITHUB_REF/refs\/tags\//}
- uses: RafikFarhad/push-to-gcr-github-action@v3.0.2
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_id: my-awesome-project
image_name: server-end
image_tag: ${{ steps.get_tag_name.outputs.GIT_TAG_NAME}}
dockerfile: ./build/Dockerfile
Version 3.0.1
Push to GCR Github Action
Version 3.0.1
Change log:
Added support for --build-arg
- Thanks to @hwmrocker for the feature request and very very thanks to @dodizzle for his contribution.
Push to GCR Github Action is an action that build docker image and push to Google Cloud Registry.
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 service accout json file must be encoded in base64. This field is required.
registry
The registry where the image should be pushed. Default gcr.io
.
project_name
The project name. This field is required.
image_name
The image name. This field is required.
image_tag
The tag for the image. To create multiple tag of the same image, provide comma (,
) separeted tag name (eg:v2.1,v2,latest
).
Default: latest
.
To use the pushed Tag Name
as image tag, see the example.
dockerfile
The image building Dockerfile.
If context is changed, Dockerfile
from context folder will be used.
Default: ./Dockerfile
.
context
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.
Example usage
Put desired yml section in the .github/workflows/build.yml
file
To perform build & push on every git push
name: Push to GCR Github Action
on: [push]
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: RafikFarhad/push-to-gcr-github-action@v3.0.1
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_name: my-awesome-project
image_name: server-end
To perform build & push only on tag publish
name: Push to GCR Github Action
on:
push:
tags:
- '*'
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- name: Get the version
id: get_tag_name
run: echo ::set-output name=GIT_TAG_NAME::${GITHUB_REF/refs\/tags\//}
- uses: RafikFarhad/push-to-gcr-github-action@v3.0.1
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_name: my-awesome-project
image_name: server-end
image_tag: ${{ steps.get_tag_name.outputs.GIT_TAG_NAME}}
dockerfile: ./build/Dockerfile
Version 3.0.0
Push to GCR Github Action
Version 3.0.0
Change log:
project_name
changed to project_id
- @dodizzle proposed that using
project_id
is more meaningful than usingproject_name
as sometimes it is possible to they are different. I appreciate his time and effort in implementing this. Of course,v1
andv2
will always useproject_name
, so there is no change necessary forv1
andv2
users.
Push to GCR Github Action is an action that build docker image and push to Google Cloud Registry.
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 service accout json file must be encoded in base64. This field is required.
registry
The registry where the image should be pushed. Default gcr.io
.
project_name
The project name. This field is required.
image_name
The image name. This field is required.
image_tag
The tag for the image. To create multiple tag of the same image, provide comma (,
) separeted tag name (eg:v2.1,v2,latest
).
Default: latest
.
To use the pushed Tag Name
as image tag, see the example.
dockerfile
The image building Dockerfile.
If context is changed, Dockerfile
from context folder will be used.
Default: ./Dockerfile
.
context
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.
Example usage
Put desired yml section in the .github/workflows/build.yml
file
To perform build & push on every git push
name: Push to GCR Github Action
on: [push]
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: RafikFarhad/push-to-gcr-github-action@v2
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_name: my-awesome-project
image_name: server-end
To perform build & push only on tag publish
name: Push to GCR Github Action
on:
push:
tags:
- '*'
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- name: Get the version
id: get_tag_name
run: echo ::set-output name=GIT_TAG_NAME::${GITHUB_REF/refs\/tags\//}
- uses: RafikFarhad/push-to-gcr-github-action@v2
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_name: my-awesome-project
image_name: server-end
image_tag: ${{ steps.get_tag_name.outputs.GIT_TAG_NAME}}
dockerfile: ./build/Dockerfile
Version 2.0.0
Push to GCR Github Action
Version 2.0.0
Change log:
Multi-staging target build support
- If you are maintaining multi-staging dockerfile and want to build a specific image to push on
gcr.io
, withv2
you can do that easily by a single step, just provide the intermediate image name you want to build.
Multiple tag name support
- Previously this tool only supported only one tag name at a time. So if you want to use multiple image tag for same image, you have to write multiple
build.yml
file. But withv2
, you can provide multiple image name separated by comma (,
).
An action that build docker image and push to Google Cloud Registry.
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 service accout json file must be encoded in base64. This field is required.
registry
The registry where the image should be pushed. Default gcr.io
.
project_name
The project name. This field is required.
image_name
The image name. This field is required.
image_tag
The tag for the image. To create multiple tag of the same image, provide comma (,
) separeted tag name (eg:v2.1,v2,latest
).
Default: latest
.
To use the pushed Tag Name
as image tag, see the example.
dockerfile
The image building Dockerfile.
If context is changed, Dockerfile
from context folder will be used.
Default: ./Dockerfile
.
context
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.
Example usage
Put desired yml section in the .github/workflows/build.yml
file
To perform build & push on every git push
name: Push to GCR Github Action
on: [push]
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- uses: RafikFarhad/push-to-gcr-github-action@v2
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_name: my-awesome-project
image_name: server-end
To perform build & push only on tag publish
name: Push to GCR Github Action
on:
push:
tags:
- '*'
jobs:
build-and-push-to-gcr:
runs-on: ubuntu-latest
steps:
- name: Get the version
id: get_tag_name
run: echo ::set-output name=GIT_TAG_NAME::${GITHUB_REF/refs\/tags\//}
- uses: RafikFarhad/push-to-gcr-github-action@v2
with:
gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
registry: gcr.io
project_name: my-awesome-project
image_name: server-end
image_tag: ${{ steps.get_tag_name.outputs.GIT_TAG_NAME}}
dockerfile: ./build/Dockerfile