/cloud-run-button

Let anyone deploy your GitHub repos to Google Cloud Run with a single click

Primary LanguageGoApache License 2.0Apache-2.0

Cloud Run Button

If you have a public repository, you can add this button to your README.md and let anyone deploy your application to Google Cloud Run with a single click.

Try it out with a "hello, world" Go application (source):

Run on Google Cloud

Demo

Cloud Run Button Demo

Add the Cloud Run Button to Your Repo's README

  1. Copy & paste this markdown:

    [![Run on Google Cloud](https://deploy.cloud.run/button.svg)](https://deploy.cloud.run)
    
  2. If the repo contains a Dockerfile, it will be built using the docker build command. If the repo uses Maven for the build and it contains the Jib plugin, then the container image will be built with Jib (Jib Spring Boot Sample). Otherwise, CNCF Buildpacks (i.e. the pack build command) will attempt to build the repo (buildpack samples). Alternatively, you can skip these built-in build methods using the build.skip field (see below) and use a prebuild or postbuild hook to build the container image yourself.

Customizing source repository parameters

  • When no parameters are passed, the referer is used to detect the git repo and branch
  • To specify a git repo, add a git_repo=URL query parameter
  • To specify a git branch, add a revision=BRANCH_NAME query parameter.
  • To run the build in a subdirectory of the repo, add a dir=SUBDIR query parameter.

Customizing deployment parameters

If you include an app.json at the root of your repository, it allows you customize the experience such as defining an alternative service name, or prompting for additional environment variables.

For example:

{
    "name": "foo-app",
    "env": {
        "BACKGROUND_COLOR": {
            "description": "specify a css color",
            "value": "#fefefe",
            "required": false
        },
        "TITLE": {
            "description": "title for your site"
        },
        "APP_SECRET": {
            "generator": "secret"
        }
    },
    "options": {
        "allow-unauthenticated": false,
        "memory": "512Mi",
        "cpu": "1"
    },
    "build": {
        "skip": false,
        "buildpacks": {
            "builder": "some/builderimage"
        }
    },
    "hooks": {
        "prebuild": {
            "commands": [
                "./my-custom-prebuild"
            ]
        },
        "postbuild": {
            "commands": [
                "./my-custom-postbuild"
            ]
        },
        "precreate": {
            "commands": [
                "echo 'test'"
            ]
        },
        "postcreate": {
            "commands": [
                "./setup.sh"
            ]
        }
    }
}

Reference:

  • name: (optional, default: repo name, or sub-directory name if specified) Name of the Cloud Run service and the built container image. Not validated for naming restrictions.
  • env: (optional) Prompt user for environment variables.
    • description: (optional) short explanation of what the environment variable does, keep this short to make sure it fits into a line.
    • value: (optional) default value for the variable, should be a string.
    • required, (optional, default: true) indicates if they user must provide a value for this variable.
    • generator, (optional) use a generator for the value, currently only support secret
  • options: (optional) Options when deploying the service
    • allow-unauthenticated: (optional, default: true) allow unauthenticated requests
    • memory: (optional) memory for each instance
    • cpu: (optional) cpu for each instance
  • build: (optional) Build configuration
    • skip: (optional, default: false) skips the built-in build methods (docker build, Maven Jib, and buildpacks), but still allows for prebuild and postbuild hooks to be run in order to build the container image manually
    • buildpacks: (optional) buildpacks config
      • builder: (optional, default: gcr.io/buildpacks/builder:v1) overrides the buildpack builder image
  • hooks: (optional) Run commands in separate bash shells with the environment variables configured for the application and environment variables GOOGLE_CLOUD_PROJECT (Google Cloud project), GOOGLE_CLOUD_REGION (selected Google Cloud Region), K_SERVICE (Cloud Run service name), IMAGE_URL (container image URL), APP_DIR (application directory). Command outputs are shown as they are executed.
    • prebuild: (optional) Runs the specified commands before running the built-in build methods. Use the IMAGE_URL environment variable to determine the container image name you need to build.
      • commands: (array of strings) The list of commands to run
    • postbuild: (optional) Runs the specified commands after running the built-in build methods. Use the IMAGE_URL environment variable to determine the container image name you need to build.
      • commands: (array of strings) The list of commands to run
    • precreate: (optional) Runs the specified commands before the service has been created
      • commands: (array of strings) The list of commands to run
    • postcreate: (optional) Runs the specified commands after the service has been created
      • commands: (array of strings) The list of commands to run

Notes

  • Disclaimer: This is not an officially supported Google product.
  • See LICENSE for the licensing information.
  • See Contribution Guidelines on how to contribute.