Commit 69c113fc authored by Thong Kuah's avatar Thong Kuah

Merge branch 'feature/gb/serverless-app-deployment-template' into 'master'

Deploy serverless apps with `gitlabktl`

Closes #64494

See merge request gitlab-org/gitlab-ce!30740
parents 7b784334 d2400a99
---
title: Deploy serverless apps with gitlabktl
merge_request: 30740
author:
type: added
...@@ -41,8 +41,7 @@ To run Knative on Gitlab, you will need: ...@@ -41,8 +41,7 @@ To run Knative on Gitlab, you will need:
external IP address or hostname for that domain. external IP address or hostname for that domain.
1. **`.gitlab-ci.yml`:** GitLab uses [Kaniko](https://github.com/GoogleContainerTools/kaniko) 1. **`.gitlab-ci.yml`:** GitLab uses [Kaniko](https://github.com/GoogleContainerTools/kaniko)
to build the application. We also use [gitlabktl](https://gitlab.com/gitlab-org/gitlabktl) to build the application. We also use [gitlabktl](https://gitlab.com/gitlab-org/gitlabktl)
and [TriggerMesh CLI](https://github.com/triggermesh/tm) CLIs to simplify the CLI to simplify the deployment of services and functions to Knative.
deployment of services and functions to Knative.
1. **`serverless.yml`** (for [functions only](#deploying-functions)): When using serverless to deploy functions, the `serverless.yml` file 1. **`serverless.yml`** (for [functions only](#deploying-functions)): When using serverless to deploy functions, the `serverless.yml` file
will contain the information for all the functions being hosted in the repository as well as a reference to the will contain the information for all the functions being hosted in the repository as well as a reference to the
runtime being used. runtime being used.
...@@ -249,7 +248,7 @@ Explanation of the fields used above: ...@@ -249,7 +248,7 @@ Explanation of the fields used above:
| Parameter | Description | | Parameter | Description |
|-----------|-------------| |-----------|-------------|
| `name` | Indicates which provider is used to execute the `serverless.yml` file. In this case, the TriggerMesh `tm` CLI. | | `name` | Indicates which provider is used to execute the `serverless.yml` file. In this case, the TriggerMesh middleware. |
| `environment` | Includes the environment variables to be passed as part of function execution for **all** functions in the file, where `FOO` is the variable name and `BAR` are he variable contents. You may replace this with you own variables. | | `environment` | Includes the environment variables to be passed as part of function execution for **all** functions in the file, where `FOO` is the variable name and `BAR` are he variable contents. You may replace this with you own variables. |
### `functions` ### `functions`
...@@ -343,27 +342,23 @@ Go to the **CI/CD > Pipelines** and click on the pipeline that deployed your app ...@@ -343,27 +342,23 @@ Go to the **CI/CD > Pipelines** and click on the pipeline that deployed your app
The output will look like this: The output will look like this:
```bash ```bash
Running with gitlab-runner 11.5.0~beta.844.g96d88322 (96d88322) Running with gitlab-runner 12.1.0-rc1 (6da35412)
on docker-auto-scale 72989761 on prm-com-gitlab-org ae3bfce3
Using Docker executor with image gcr.io/triggermesh/tm@sha256:e3ee74db94d215bd297738d93577481f3e4db38013326c90d57f873df7ab41d5 ... Using Docker executor with image registry.gitlab.com/gitlab-org/gitlabktl:latest ...
Pulling docker image gcr.io/triggermesh/tm@sha256:e3ee74db94d215bd297738d93577481f3e4db38013326c90d57f873df7ab41d5 ... Running on runner-ae3bfc-concurrent-0 via runner-ae3bfc ...
Using docker image sha256:6b3f6590a9b30bd7aafb9573f047d930c70066e43955b4beb18a1eee175f6de1 for gcr.io/triggermesh/tm@sha256:e3ee74db94d215bd297738d93577481f3e4db38013326c90d57f873df7ab41d5 ... Fetching changes...
Running on runner-72989761-project-4342902-concurrent-0 via runner-72989761-stg-srm-1541795796-27929c96... Authenticating with credentials from job payload (GitLab Registry)
Cloning repository... $ /usr/bin/gitlabktl application deploy
Cloning into '/builds/danielgruesso/knative'... Welcome to gitlabktl tool
Checking out 8671ad20 as master... time="2019-07-15T10:51:07Z" level=info msg="deploying registry credentials"
Skipping Git submodules setup Creating app-hello function
$ echo "$CI_REGISTRY_IMAGE" Waiting for app-hello ready state
registry.staging.gitlab.com/danielgruesso/knative Service app-hello URL: http://app-hello.serverless.example.com
$ tm -n "$KUBE_NAMESPACE" --config "$KUBECONFIG" deploy service "$CI_PROJECT_NAME" --from-image "$CI_REGISTRY_IMAGE" --wait
Deployment started. Run "tm -n knative-4342902 describe service knative" to see the details
Waiting for ready state.......
Service domain: knative.knative-4342902.example.com
Job succeeded Job succeeded
``` ```
The second to last line, labeled **Service domain** contains the URL for the deployment. Copy and paste the domain into your The second to last line, labeled **Service domain** contains the URL for the
browser to see the app live. deployment. Copy and paste the domain into your browser to see the app live.
![knative app](img/knative-app.png) ![knative app](img/knative-app.png)
......
...@@ -8,26 +8,23 @@ stages: ...@@ -8,26 +8,23 @@ stages:
- deploy - deploy
.serverless:build:image: .serverless:build:image:
stage: build
image: registry.gitlab.com/gitlab-org/gitlabktl:latest image: registry.gitlab.com/gitlab-org/gitlabktl:latest
stage: build
script: /usr/bin/gitlabktl app build script: /usr/bin/gitlabktl app build
.serverless:deploy:image: .serverless:deploy:image:
image: registry.gitlab.com/gitlab-org/gitlabktl:latest
stage: deploy stage: deploy
image: gcr.io/triggermesh/tm@sha256:3cfdd470a66b741004fb02354319d79f1598c70117ce79978d2e07e192bfb336 # v0.0.11
environment: development environment: development
script: script: /usr/bin/gitlabktl app deploy
- echo "$CI_REGISTRY_IMAGE"
- tm -n "$KUBE_NAMESPACE" --config "$KUBECONFIG" deploy service "$CI_PROJECT_NAME" --from-image "$CI_REGISTRY_IMAGE" --wait
.serverless:build:functions: .serverless:build:functions:
stage: build
environment: development
image: registry.gitlab.com/gitlab-org/gitlabktl:latest image: registry.gitlab.com/gitlab-org/gitlabktl:latest
stage: build
script: /usr/bin/gitlabktl serverless build script: /usr/bin/gitlabktl serverless build
.serverless:deploy:functions: .serverless:deploy:functions:
image: registry.gitlab.com/gitlab-org/gitlabktl:latest
stage: deploy stage: deploy
environment: development environment: development
image: registry.gitlab.com/gitlab-org/gitlabktl:latest
script: /usr/bin/gitlabktl serverless deploy script: /usr/bin/gitlabktl serverless deploy
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment