Skip to content

Releases: RafikFarhad/push-to-gcr-github-action

v5-rc1 - Release Candidate 1

21 Dec 07:03
b372ed2
Compare
Choose a tag to compare
Pre-release

Fixed:

  • #46 - Using push_only option causes the job to fail

v5-beta :: Workload Identity Federation Support

23 Oct 18:13
658acb5
Compare
Choose a tag to compare

Push to GCR Github Action

Version 5-beta

Change log:

v4.1.0

18 Jun 07:24
2417078
Compare
Choose a tag to compare

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.

Reference 1

Reference 2

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

18 Jun 05:59
920e46c
Compare
Choose a tag to compare

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.

Reference 1

Reference 2

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

Full Changelog: v3.0.2...v4

Version 3.0.2

27 Feb 21:06
2e222c0
Compare
Choose a tag to compare

Push to GCR Github Action

Version 3.0.2

Change log:


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.

Reference 1

Reference 2

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

18 Dec 18:42
0b2858b
Compare
Choose a tag to compare

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

31 Jul 05:39
v3
8a692cc
Compare
Choose a tag to compare

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 using project_name as sometimes it is possible to they are different. I appreciate his time and effort in implementing this. Of course, v1 and v2 will always use project_name, so there is no change necessary for v1 and v2 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

03 Jul 14:43
v2
f70a211
Compare
Choose a tag to compare

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, with v2 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 with v2, 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

Version 1.0.0

03 May 18:05
632c4cb
Compare
Choose a tag to compare

Version 1

Updated on 04-05-2020