# Cheat Sheets

Here are some commonly used commands and links.

## gcloud

### Basics

| Task                          |                                                                          |
| ----------------------------- | ------------------------------------------------------------------------ |
| Enable an API                 | `gcloud services enable ${API}`                                          |
| Current Project ID            | `gcloud config get-value project`                                        |
| Export to PROJECT\_ID         | `PROJECT_ID=$(gcloud config get-value project)`                          |
| Authentication                | `gcloud auth login`                                                      |
| Application Credentials Login | `gcloud auth application-default login`                                  |
| Default Zone                  | `gcloud config set compute/zone us-central1-c`                           |
| Default Region                | `gcloud config set compute/region us-central1`                           |
| All Regions and Zones         | [Regions and Zones](https://cloud.google.com/compute/docs/regions-zones) |

### Identity Access Management

| Task                              |                                                                                                                                                                              |
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Create a Service Account          | <p><code>gcloud iam service-accounts create \</code></p><p>  <code>${SA\_NAME}</code></p>                                                                                    |
| Service Account E-Mail            | `${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com`                                                                                                                           |
| Add Permission                    | <p><code>gcloud projects add-iam-policy-binding ${PROJECT\_ID} \</code></p><p>  <code>--member serviceAccount:${SA\_EMAIL} \</code></p><p>  <code>--role ${ROLES}</code></p> |
| Create a Service Account Key File | <p><code>gcloud iam service-accounts keys create \</code></p><p>  <code>$HOME/sa-key.json \</code></p><p>  <code>--iam-account ${SA\_EMAIL}</code></p>                       |
| All Possible Roles                | [Understanding roles](https://cloud.google.com/iam/docs/understanding-roles)                                                                                                 |

### Serverless Deployments

| Task           |                                                                                                                                                                                                                                                                                                                                                           |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| App Engine     | `gcloud app deploy ${JAR_FILE}`                                                                                                                                                                                                                                                                                                                           |
|                | `gcloud app deploy ${JAR_FILE} --appyaml app.yaml`                                                                                                                                                                                                                                                                                                        |
|                | [Maven plugin](https://cloud.google.com/appengine/docs/standard/java11/using-maven#setting_up_maven)                                                                                                                                                                                                                                                      |
|                | [Gradle Plugin](https://cloud.google.com/appengine/docs/standard/java11/using-gradle)                                                                                                                                                                                                                                                                     |
| Cloud Run      | <p><code>gcloud run deploy ${NAME} \</code></p><p>  <code>--platform=managed \</code></p><p>  <code>--allow-unauthenticated \</code></p><p>  <code>--image=gcr.io/${PROJECT\_ID}/${IMAGE\_NAME}</code></p>                                                                                                                                                |
|                | <p><code>gcloud run deploy ${NAME} \</code></p><p>  <code>--platform=managed \</code></p><p>  <code>--allow-unauthenticated \</code></p><p>  <code>--cpu=2 \</code></p><p>  <code>--memory=512M \</code></p><p>  <code>--set-env-vars="JAVA\_TOOL\_OPTIONS=-Dproperty=value"</code></p><p>  <code>--image=gcr.io/${PROJECT\_ID}/${IMAGE\_NAME}</code></p> |
| Cloud Function | <p><code>gcloud functions deploy ${NAME}</code></p><p>  <code>--trigger-http \</code></p><p>  <code>--runtime=java11 \</code></p><p>  <code>--allow-unauthenticated \</code></p><p>  <code>--entry-point=${FUNCTION\_CLASS\_FQN}</code></p>                                                                                                               |
|                | [Maven plugin](https://github.com/GoogleCloudPlatform/functions-framework-java#running-a-function-with-the-maven-plugin)                                                                                                                                                                                                                                  |

## Jib

| Task                                               |                                                                                                                                                                            |
| -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Create a remote Image                              | `mvn jib:build`                                                                                                                                                            |
|                                                    | `gradle jib`                                                                                                                                                               |
| Create a local image                               | `mvn jib:dockerBuild`                                                                                                                                                      |
|                                                    | `gradle jibDockerBuild`                                                                                                                                                    |
| <p>Run Jib without</p><p>pre-configured plugin</p> | <p><code>mvn compile \</code></p><p><code>com.google.cloud.tools:jib-maven-plugin:2.4.0:build \</code></p><p><code>-Dimage=gcr.io/${PROJECT\_ID}/${IMAGE\_NAME}</code></p> |
| Jib READMEs                                        | [Maven plugin](https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin)                                                                                   |
|                                                    | [Gradle plugin](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin)                                                                                 |

## Spring Initializer

| Task                                              |                                                                                                                                                                                                                 |
| ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>Create a new app w/</p><p>Spring Cloud GCP</p> | <p><code>curl <https://start.spring.io/starter.zip>  \</code></p><p>  <code>-d dependencies=web,cloud-gcp \</code></p><p>  <code>-d bootVersion=2.3.1.RELEASE \</code></p><p>  <code>-d baseDir=demo</code></p> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://spring-gcp.saturnism.me/additional-resources/cheet-sheets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
