Code Monkey home page Code Monkey logo

cloud-run-button's Introduction

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, a fully populated app.json file looks like this:

{
    "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"
        },
        "ORDERED_ENV": {
            "description": "control the order env variables are prompted",
            "order": 100
        }
    },
    "options": {
        "allow-unauthenticated": false,
        "memory": "512Mi",
        "cpu": "1",
        "port": 80,
        "http2": false,
        "concurrency": 80,
        "max-instances": 10
    },
    "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
    • order, (optional) if specified, used to indicate the order in which the variable is prompted to the user. If some variables specify this and some don't, then the unspecified ones are prompted last.
  • 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
    • port: (optional) if your application doesn't respect the PORT environment variable provided by Cloud Run, specify the port number it listens on
    • http2: (optional) use http2 for the connection
    • concurrency: (optional) concurrent requests for each instance
    • max-instances: (optional) autoscaling limit (max 1000)
  • 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 (Note: Additional Buildpack config can be specified using a project.toml file. See the spec for details.)
      • 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; the SERVICE_URL environment variable provides the URL of the deployed Cloud Run service
      • 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.

cloud-run-button's People

Contributors

ahmetb avatar chanseokoh avatar geshan avatar glasnt avatar jamesward avatar keisukeyamashita avatar pokutuna avatar poy avatar steren avatar toshi0607 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloud-run-button's Issues

Feature Request: Allow Verbose Mode

Maybe when we first start running we display something like:
Running in terse output mode - hit "v" to enter verbose mode

In verbose mode we should show the gcloud commands we are running but not necessarily their output.

Use pack CLI in Cloud Shell

Cloud Shell will soon ship the most recent pack CLI (v0.4.1) for Buildpacks. There have been many changes to the Buildpacks spec; hopefully nothing breaks.

Also, the binary will be placed under /usr/local/bin/pack where the current Dockerfile tries to create a symlink. The symlink command will probably break by then.

Handling When No Projects Exist

When no projects exist, create one for them, like:

PROJECT_NAME="$1-$((1 + RANDOM % 10000))"
    gcloud projects create $PROJECT_NAME --set-as-default --quiet 2> /dev/null
    if [[ "$?" -eq 0 ]]; then
      break
    fi
    sleep 1

Prompt just before deploying the application (for security)?

This is primarily because Cloud Run default service account currently has broad capabilities (Editor) on user’s GCP project.

So if someone clicks to the button to deploy a malicious repository, they might just go with it which would’ve ended up stealing their tokens.

Right now we show this indicator:

[ ✓ ] Cloned git repository https://github.com/foo/bar.
[ ✓ ] Queried list of your GCP projects
[ ✓ ] Found 3044 projects in your GCP account.

and then definitely prompt for input at least once once for a GCP project.

Does this give user enough chance to review the git repo being deployed –or should we show the user another confirmation like:

[ ? ] Do you allow application at https://github.com/foo/bar to be deployed? (Y/n) 

I'm not sure.

app.json support for "Require authentication"

I'm working on an app that'd be nice to buttonize but it is one that should set the "Require authentication" flag on the service. I think if we allow the app.json to have a property like:

{
    "require-auth": true
}

Then maybe prompt for the roles to allow.

This might be related to #33 but I'm not totally sure.

Collect usage metrics

If there's a way to collect analytics and determine top public repositories used with the button, it would be great to keep a tab on those.
cc: @jamesward

Tell me how to remove it, or what happens if I don't

The script output tells me how to change the image and deploy a new version, but it doesn't tell me how to remove it.

It also doesn't tell me what happens if I don't - will it live forever? Will it expire? Will I have to pay anything

Handling When Billing Not Enabled

Like:

  gcloud services enable run.googleapis.com 2> /dev/null

  if [[ $? -eq 1 ]]; then
    echo "Your account needs to have billing setup to continue. Visit:"
    echo "https://console.developers.google.com/billing/linkedaccount?project=$PROJECT_ID\n"
    read -p "After setting up billing, press enter to continue."
    gcloud services enable run.googleapis.com
  fi

Indicate -dir somewhere in the output

Right now if someone specified ?cloudshell_working_dir, we have no indication of it working or not. If specified, we can quickly print

[ checkmark ] Checked out directory **$dir**

More Lenient app.json Parsing

Trying the button on:
https://github.com/bkimminich/juice-shop.git

I get:

james_demo@cloudshell:~$ cloudshell_open --repo_url "https://github.com/bkimminich/juice-shop.git"
[ ✓ ] Cloned git repository https://github.com/bkimminich/juice-shop.git.
Error: error attempting to read the app.json from the cloned repository: failed to parse app.json file: failed to parse app.json: json: unknown field "description"

Reproduce with:
https://console.cloud.google.com/cloudshell/editor?shellonly=true&cloudshell_image=gcr.io/cloudrun/button&cloudshell_git_repo=https://github.com/bkimminich/juice-shop.git

Support cloudbuild.yaml

It seems like we want to support cloudbuild.yaml in addition to Dockerfiles, and there's a plan to support buildpacks via app.json (#3).

@jamesward What's the primary reason we want to have cloudbuild.yaml? Does it do something potentially we can’t do via docker build with multi-stage Dockerfiles?

I suppose it enables tools where you don't want to use docker and still end up with a docker image (ko, pack etc.), but should we treat this as a priority –especially given the adoption levels of cloudbuild.yaml vs Dockerfiles?

Smaller button image for use in lists

Lists of deployable apps look better with a smaller button, but to resize the image on GitHub requires leaving markdown for HTML. Add a smaller image that can be referenced to keep it simple.

This is what I'm currently experimenting with:

<img src="https://storage.googleapis.com/cloudrun/button.svg" alt="Run on Google Cloud" height="20">

Project List More

It wasn't clear in the UI that there were more project IDs beyond those listed. After scrolling it is clear but I'd be nice to have a visual indicator as such.

Option to create a new project

Received via internal bug feedback tool:

This is my second run trying out the Run Deploy and I figured it out so this screenshot isn't relevant but I think it'd be helpful if:

  1. After you select a project and get an error message, you can select another one instead of just being stuck trying to fix payment options for that project
  2. Be clearer about how to add a payment method and how much that payment will be. Just link to it more directly

tl;dr consider adding "New Project" option to the project selector, and handle billing errors in a more friendly way.

Handling When Image Not Trusted

Quick fix: Provide an error message and ask the user to try again and trust the image
Nicer fix: Have the user login, then continue

Add buildpack support

If there is no Dockerfile, fallback to trying buildpacks. See #3 for an add-on / related discussion.

Ability to provision external services consumed by the deployed application

I'd be cool if external services that need to be provisioned can be as part of the button deploy. Ideally we use app.json to specify these. Maybe they are based on the API names that need to be enabled? Should we have some way to select an existing resource? Examples GCS, Cloud SQL, etc.

End goal: An app that needs something like Cloud SQL can be deployed to 100% functionality from the button.

Provide a command I can run to re-deploy after making changes

After clicking the button and following prompts, I now have a deployed app, and the source for that app cloned in my Cloud Shell.

I'd love to be able to modify the source and redeploy to the app again, but I don't know how. Looking in history, it looks like I originally deployed using cloudshell_open but it takes a -repo_url which will presumably re-clone the repo, instead of just deploying my changes.

Is it possible to deploy a container directly ?

If I have a public image in gcr.io, can I give the button required parameters and when clicked, it opens the window for cloud run and the image name is already filled out ?

I don't want user to build the repo or so, just autofill the image name in Cloud run and if possible add some env variables ?

Allow app.json to list required IAM roles

This feature would allow users to run with non-default service accounts created just for that application.

@mchmarny said that the default Run app identity doesn't have enough permissions to create a PubSub topic to one-click-deploy his app. (Ideally it should, since GCE default svc account has Editor role, so I'll investigate that separately).

But if we needed this someday, the strawman design would be like:

app.json:

{ 
  "roles": [
     "roles/storage.objectAdmin",
     "roles/pubsub.subscriber"
  ]
}

When this field specifies, we should prompt the user with a confirmation saying a "service account with permissions [..., ...] will be created or re-used by the deployed application".

Then we would create a Cloud IAM Service Account that has the same name as the Run app name. (It would assign the listed roles on the project-level to that service account. It wouldn't remove extra role bindings that are already there, as they may be added by the user.)

If the account exists, we should have a way of verifying it was created by cloud-run-button (somehow through a marker). If so, we can reuse it (by making sure the role bindings listed in app.json exist).

But I'm not sure if we need this feature just yet, since technically GCE Default Service Account is an Editor and it should be able to bootstrap its needs just fine.

git_branch unsupported flag

Set via the cloudshell_git_branch query param.

jlward4th@cloudshell:~$ cloudshell_open --repo_url "https://github.com/jamesward/hello-micronaut.git" --git_branch "dockerfile"
Incorrect Usage. flag provided but not defined: -git_branch

NAME:
   cloudshell_open - This tool is only meant to be invoked by Google Cloud Shell

USAGE:
   cloudshell_open [global options] command [command options] [arguments...]

VERSION:
   0.0.0

DESCRIPTION:
   Specialized cloudshell_open for the Cloud Run Button

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --repo_url value
   --help, -h        show help
   --version, -v     print the version
Error: flag provided but not defined: -git_branch

Deploy Redirector (deploy.cloud.run)

I think we should create a service (on Cloud Run) which gives us a short and custom URL we can link to for the button so that we can:

  • be isolated from underlying URL which we redirect to
  • possibly support the referrer so the git URL is optional
  • track deploy metrics (#13)
  • set current or future defaults

So the button href cloud be just something like:
https://cloud.run/deploy

Maybe @steren can chime in on possibly using the existing cloud.run domain.

Document Local Development

The CONTRIBUTING doc includes info on using Docker for local development, which is probably good for some methods of testing. But it is slow (see #90). We should document how to do local development directly with Go. Also there are some tests and we should document how to run them.

Build Script to Enable Jib and Other Builds

It'd be nice if we could enable a way to run Jib builds via Maven or Gradle. The app.json could include something like:

{
    "scripts": {
        "build": "./mvnw compile jib:build -Dimage=gcr.io/${PROJECT_ID}/hello-springboot"
    }
}

If that is set, we run the command instead of docker build or buildpack stuff. We'd have to set the PROJECT_ID env var when we run the build command.

Note that this example requires a JVM which Cloud Shell has, but if the user needs other system deps they could add a build shell script to install them, and then specify that script.

What Next?

So the user has deployed their first app, now what? Maybe help them setup GCB for CI/CD.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.