Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example to use cloudrun deployer + local build #8983

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions docs-v2/content/en/docs/deployers/cloudrun.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,47 @@ The following `deploy` section instructs Skaffold to deploy the artifacts under

{{% readfile file="samples/deployers/cloud-run/cloud-run.yaml" %}}

{{< alert title="Note" >}}
Images listed to be deployed with the Cloud Run deployer must be present in Google Artifact
Registry or Google Container Registry. If you are using Skaffold to build the images, ensure `push` is
set to true.
{{< /alert >}}
## Cloud Run deployer + Skaffold Local build

With Skaffold you can configure your project to [locally build]({{< relref "docs/builders/build-environments/local" >}}) your images and deploy them to Cloud Run. The following example demonstrates how to set up Skaffold for this:

With the following project folder structure:
```yaml
resources/
service.yaml
skaffold.yaml
Dockerfile
```

`skaffold.yaml` file content:
{{% readfile file="samples/deployers/cloud-run/local-build-image.yaml" %}}


`resources/service.yaml` file content:
```yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: cloud-run-service
spec:
template:
spec:
containers:
- image: my-img # <- Same image name from skaffold.yaml file
```

A simple `Dockerfile` file:
```docker
FROM gcr.io/cloudrun/hello
```

Running a Skaffold command like `skaffold run --default-repo=gcr.io/your-registry` will build your local images, push them to the specified registry, and deploy them to Cloud Run. Please notice the following from the previous example:

### Build local push option
When you use [Skaffold Local build]({{< relref "docs/builders/build-environments/local#avoiding-pushes" >}}), the `push` option is set to `false` by default. However, Cloud Run will need your images published in a registry that it has access to. Therefore, we need to set this to `true`.

### Platform
According to the [Cloud Run runtime contract](https://cloud.google.com/run/docs/container-contract#languages), your images must be compiled for a specific architecture. Skaffold can help us with this by using its [Cross/multi-platform build support]({{< relref "docs/builders/cross-platform" >}}).

### Registry
You'll need to specify a registry so Skaffold can push your images. For this, we can use the `--default-repo` flag when running a command to include it in all your local images.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: skaffold/v4beta6
kind: Config

build:
local:
push: true # <- We need to push the images so Cloud Run can deploy them

platforms: ["linux/amd64"] # <- Specific platform supported by Cloud Run

artifacts:
- image: my-img # <- Should match the image name in the Cloud Run service.yaml
docker:
dockerfile: ./Dockerfile

manifests:
rawYaml:
- resources/service.yaml

deploy:
cloudrun:
projectid: YOUR-GCP-PROJECT
region: GCP-REGION