Merge pull request #606 from tjovicic/cloudrun-support
Cloud Run support
This commit is contained in:
commit
7146223ec7
115
docs/learn/106-cloudrun.md
Normal file
115
docs/learn/106-cloudrun.md
Normal file
@ -0,0 +1,115 @@
|
||||
---
|
||||
slug: /learn/106-cloudrun
|
||||
---
|
||||
|
||||
# Dagger 106: deploy to Cloud Run
|
||||
|
||||
This tutorial illustrates how to use Dagger to build, push and deploy Docker images to Cloud Run.
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
## Initialize a Dagger Workspace and Environment
|
||||
|
||||
### (optional) Setup example app
|
||||
|
||||
You will need the local copy of the [Dagger examples repository](https://github.com/dagger/examples) used in previous guides
|
||||
|
||||
```shell
|
||||
git clone https://github.com/dagger/examples
|
||||
```
|
||||
|
||||
Make sure that all commands are being ran from the todoapp directory:
|
||||
|
||||
```shell
|
||||
cd examples/todoapp
|
||||
```
|
||||
|
||||
### (optional) Initialize a Cue module
|
||||
|
||||
In this guide we will use the same directory as the root of the Dagger workspace and the root of the Cue module; but you can create your Cue module anywhere inside the Dagger workspace.
|
||||
|
||||
```shell
|
||||
cue mod init
|
||||
```
|
||||
|
||||
### Organize your package
|
||||
|
||||
Let's create a new directory for our Cue package:
|
||||
|
||||
```shell
|
||||
mkdir cue.mod/gcpcloudrun
|
||||
```
|
||||
|
||||
### Create a basic plan
|
||||
|
||||
```cue title="todoapp/cue.mod/gcpcloudrun/source.cue"
|
||||
package gcpcloudrun
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/docker"
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/gcp/cloudrun"
|
||||
"alpha.dagger.io/gcp/gcr"
|
||||
)
|
||||
|
||||
// Source code of the sample application
|
||||
src: dagger.#Artifact & dagger.#Input
|
||||
|
||||
// GCR full image name
|
||||
imageRef: string & dagger.#Input
|
||||
|
||||
image: docker.#Build & {
|
||||
source: src
|
||||
}
|
||||
|
||||
gcpConfig: gcp.#Config
|
||||
|
||||
creds: gcr.#Credentials & {
|
||||
config: gcpConfig
|
||||
}
|
||||
|
||||
push: docker.#Push & {
|
||||
target: imageRef
|
||||
source: image
|
||||
auth: {
|
||||
username: creds.username
|
||||
secret: creds.secret
|
||||
}
|
||||
}
|
||||
|
||||
deploy: cloudrun.#Service & {
|
||||
config: gcpConfig
|
||||
image: push.ref
|
||||
}
|
||||
```
|
||||
|
||||
## Set up the environment
|
||||
|
||||
### Create a new environment
|
||||
|
||||
Now that your Cue package is ready, let's create an environment to run it:
|
||||
|
||||
```shell
|
||||
dagger new 'gcpcloudrun' -m cue.mod/gcpcloudrun
|
||||
```
|
||||
|
||||
### Configure user inputs
|
||||
|
||||
```shell
|
||||
dagger input dir src . -e gcpcloudrun
|
||||
dagger input text deploy.name todoapp -e gcpcloudrun
|
||||
dagger input text imageRef gcr.io/<your-project>/todoapp -e gcpcloudrun
|
||||
dagger input text gcpConfig.region us-west2 -e gcpcloudrun
|
||||
dagger input text gcpConfig.project <your-project> -e gcpcloudrun
|
||||
dagger input secret gcpConfig.serviceKey -f ./gcp-sa-key.json -e gcpcloudrun
|
||||
```
|
||||
|
||||
## Deploy
|
||||
|
||||
Now that everything is properly set, let's deploy on Cloud Run:
|
||||
|
||||
```shell
|
||||
dagger up -e gcpcloudrun
|
||||
```
|
@ -14,6 +14,7 @@
|
||||
- [docker](./docker/README.md) - Docker container operations
|
||||
- [docker/compose](./docker/compose.md) - Docker-compose operations
|
||||
- [gcp](./gcp/README.md) - Google Cloud Platform
|
||||
- [gcp/cloudrun](./gcp/cloudrun.md) - -
|
||||
- [gcp/gcr](./gcp/gcr.md) - Google Container Registry
|
||||
- [gcp/gcs](./gcp/gcs.md) - Google Cloud Storage
|
||||
- [gcp/gke](./gcp/gke.md) - Google Kubernetes Engine
|
||||
|
29
docs/reference/universe/gcp/cloudrun.md
Normal file
29
docs/reference/universe/gcp/cloudrun.md
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
sidebar_label: cloudrun
|
||||
---
|
||||
|
||||
# alpha.dagger.io/gcp/cloudrun
|
||||
|
||||
```cue
|
||||
import "alpha.dagger.io/gcp/cloudrun"
|
||||
```
|
||||
|
||||
## cloudrun.#Service
|
||||
|
||||
Service deploys a Cloud Run service based on provided GCR image
|
||||
|
||||
### cloudrun.#Service Inputs
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*config.region* | `string` |GCP region |
|
||||
|*config.project* | `string` |GCP project |
|
||||
|*config.serviceKey* | `dagger.#Secret` |GCP service key |
|
||||
|*name* | `string` |Cloud Run service name |
|
||||
|*image* | `string` |GCR image ref |
|
||||
|*platform* | `*"managed" \| string` |Cloud Run platform |
|
||||
|*port* | `*"80" \| string` |Cloud Run service exposed port |
|
||||
|
||||
### cloudrun.#Service Outputs
|
||||
|
||||
_No output._
|
20
examples/cloudrun-app/main.cue
Normal file
20
examples/cloudrun-app/main.cue
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/gcp"
|
||||
"dagger.io/gcp/cloudrun"
|
||||
)
|
||||
|
||||
// Cloud Run service name
|
||||
serviceName: *"cloudrun-test" | string @dagger(input)
|
||||
|
||||
// Image name
|
||||
image: string @dagger(input)
|
||||
|
||||
gcpConfig: gcp.#Config
|
||||
|
||||
deploy: cloudrun.#Deploy & {
|
||||
"serviceName": serviceName
|
||||
"image": image
|
||||
config: gcpConfig
|
||||
}
|
2
stdlib/.dagger/env/google-cloudrun/.gitignore
vendored
Normal file
2
stdlib/.dagger/env/google-cloudrun/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# dagger state
|
||||
state/**
|
31
stdlib/.dagger/env/google-cloudrun/values.yaml
vendored
Normal file
31
stdlib/.dagger/env/google-cloudrun/values.yaml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
plan:
|
||||
module: ./gcp/cloudrun/
|
||||
package: ./tests
|
||||
name: google-cloudrun
|
||||
inputs:
|
||||
TestConfig.gcpConfig.project:
|
||||
text: dagger-ci
|
||||
TestConfig.gcpConfig.region:
|
||||
text: us-west2
|
||||
TestConfig.gcpConfig.serviceKey:
|
||||
secret: ENC[AES256_GCM,data:ienSBYZujZDgs6U72/FY+DvfDr8802y+YruTcbwJc3JCOir6mavED8/cimWFffxCJyxyfP2Wm91gE4tfT5hqdA3+MwZWcdYPBfT7Ojoj80ywdHa3uJVrdS9K4k457fc2Kfo4LeQglv1mBqOF9hw1qXGwE8zCCbxqWJsWLDptv/PEugi1CbOvcGmMPWDkRTYnSXjfAPmHTSl+tl6wJIW/1AsRVEBo+oCFJNo18J+RKFrLQVYIJxy5+BLzeJb8tx7ffD+Mkkx4raHFPP8yli5wMdlTqGq4HqXwa25q0g+AOZBXSppwLQyG2WWlDYYWdp2oHdZnlgVXp4rJXrKSuiKW2+I5DnokEQLo9hkLAw7J8yL7+ZM0lpHk8X1N6JeB8r/MO2BwLAbsGFaL3MEGzD0a1s4qaVMKVdWmpgntXlKSuQJZ87SXtkyl3DENKHKdLl6UL/mOqA3Ga38BBScnbheMra1zroK6SeAq8ggGOIz/PrrpmhRSIiNfhN74P3EN2Yvq+IXFpk8/wyhu405Nt9rOPp6QJc2IetO5tz0sXRJMLsSdSsX4tjDJtVaE+M8odzYODLSQ+tM4wYF8rW37Ju7TCyUYpAN80UQuyeEocvdP9Wln0SYFGtpbJlfZxzWoXr1BvCWMkMbIfpYbq1FeKx/j7XLp5dHXa99PsL/po5oXOjqagZoTfDly52pS2F8CjnqZdQf+OLd2eGauIdiSecDI4tC9J/FzcpGZDl9VJENqNOJLtbv+4WODFBW55mJsJvh31Pt5Egyt9VwblKoGEjJJ1gUvN8vq3YXR8f04IVFaWG3/coyLGy6hKLLvmnQcIDZMFqgYhPEvnkCLOJxIXqBFBxYvCH3hYTSjc5+8n6l2x7oeP8Q8+R3w1zeRFK4JgwwyM1MB4tgHb8NgBZZ14g+LXYh1MWXxG/s29PWlh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fsje0UwuCqJZ5FShrMM=,iv:4TEnsQAMYuk8x4EYkT+i1ibsIovbt6pzYGv685SKBjI=,tag:JV4R9kOnAYefNjDiXNUzdA==,type:str]
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
azure_kv: []
|
||||
hc_vault: []
|
||||
age:
|
||||
- recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
|
||||
enc: |
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBFMkRmY0dVcWVieEg5QWNw
|
||||
MVRxMXVjZXBqTnQ4bmNEK1FBSTdZckdJZWhzCmk4ZFhrUUJVYXU0V2V1MmdPVDIz
|
||||
LzlBSHFrR0xIVFlMblNHN3EyZ2lHNWsKLS0tIFZPNVVDUUFzclRXYUwrdnVuUTJW
|
||||
MS9KVmtwczR3R3luU3pzaExXdEVMck0KBDEHK2xu5xnaIuX3vxJV5kUVJvtdWXbs
|
||||
UU1xOdXor67vnppQuydXjmS4KHj9sUuv7ZieJdb6ncnuNxClizlWYA==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
lastmodified: "2021-07-01T07:05:02Z"
|
||||
mac: ENC[AES256_GCM,data:JToQ5grcEkfvUPxMKTdSW2lx3B6oRJdOwduQA7/F+7GJweaAcsxc7LjMRCvEv2uoeUcWS7et/T3Nei9tk59lEPNjqLhHjF+Mc1lBJFZN2BXZiOhX58TEr+klfnmxAsLOiWFFubnlQxSoVv/GiiE9KCE7/sYo4Fs9siIhps4T+bM=,iv:YxLqCwJWGYkBtzC6XcAsuRGfszhYc0D50PyAbiLuXn4=,tag:ZXaPOH75+BSJWL0DOxsecw==,type:str]
|
||||
pgp: []
|
||||
encrypted_suffix: secret
|
||||
version: 3.7.1
|
53
stdlib/gcp/cloudrun/cloudrun.cue
Normal file
53
stdlib/gcp/cloudrun/cloudrun.cue
Normal file
@ -0,0 +1,53 @@
|
||||
package cloudrun
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/gcp"
|
||||
)
|
||||
|
||||
// Service deploys a Cloud Run service based on provided GCR image
|
||||
#Service: {
|
||||
// GCP Config
|
||||
config: gcp.#Config
|
||||
|
||||
// Cloud Run service name
|
||||
name: string @dagger(input)
|
||||
|
||||
// GCR image ref
|
||||
image: string @dagger(input)
|
||||
|
||||
// Cloud Run platform
|
||||
platform: *"managed" | string @dagger(input)
|
||||
|
||||
// Cloud Run service exposed port
|
||||
port: *"80" | string @dagger(input)
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: gcp.#GCloud & {
|
||||
"config": config
|
||||
}
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
gcloud run deploy "$SERVICE_NAME" --image "$IMAGE" --region "$REGION" --port "$PORT" --platform "$PLATFORM" --allow-unauthenticated
|
||||
"""#,
|
||||
]
|
||||
env: {
|
||||
SERVICE_NAME: name
|
||||
PLATFORM: platform
|
||||
REGION: config.region
|
||||
IMAGE: image
|
||||
PORT: port
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
14
stdlib/gcp/cloudrun/tests/cloudrun.cue
Normal file
14
stdlib/gcp/cloudrun/tests/cloudrun.cue
Normal file
@ -0,0 +1,14 @@
|
||||
package cloudrun
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/gcp/cloudrun"
|
||||
)
|
||||
|
||||
TestConfig: gcpConfig: gcp.#Config
|
||||
|
||||
TestCloudRun: deploy: cloudrun.#Service & {
|
||||
config: TestConfig.gcpConfig
|
||||
name: "todoapp"
|
||||
image: "gcr.io/dagger-ci/todoapp:latest"
|
||||
}
|
@ -152,6 +152,10 @@ setup() {
|
||||
dagger -e google-gke up
|
||||
}
|
||||
|
||||
@test "google cloud: cloudrun" {
|
||||
dagger -e google-cloudrun up
|
||||
}
|
||||
|
||||
@test "terraform" {
|
||||
# it must fail because of a missing var
|
||||
run dagger -e terraform up
|
||||
|
@ -3,7 +3,7 @@
|
||||
## TL;DR
|
||||
|
||||
```shell
|
||||
# Install dependancies
|
||||
# Install dependencies
|
||||
yarn install
|
||||
|
||||
# Install gnu parallel if needed
|
||||
|
Reference in New Issue
Block a user