Google App Engine
You can check out a full google appengine sample, here:<https://github.com/ktorio/ktor-samples/tree/master/deployment/google-appengine-standard>
Preparing
You first need to install the gcloud cli. You can grab it from here:<https://cloud.google.com/sdk/docs/> and follow the described steps to install it.
For example, a macOS setup might look something like this:
1. > wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-194.0.0-darwin-x86_64.tar.gz
2. > tar -xzf google-cloud-sdk-194.0.0-darwin-x86_64.tar.gz
3. > cd google-cloud-sdk
5. > ./install.sh
6. Welcome to the Google Cloud SDK!
8. To help improve the quality of this product, we collect anonymized usage data
9. and anonymized stacktraces when crashes are encountered; additional information
10. is available at <https://cloud.google.com/sdk/usage-statistics>. You may choose
11. to opt out of this collection now (by choosing 'N' at the below prompt), or at
12. any time in the future by running the following command:
14. gcloud config set disable_usage_reporting true
16. Do you want to help improve the Google Cloud SDK (Y/n)? n
19. Your current Cloud SDK version is: 194.0.0
20. The latest available version is: 194.0.0
22. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
23. │ Components │
24. ├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
25. │ Status │ Name │ ID │ Size │
26. ├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
27. │ Not Installed │ App Engine Go Extensions │ app-engine-go │ 151.3 MiB │
28. │ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 4.0 MiB │
29. │ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 3.8 MiB │
30. │ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │
31. │ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 17.9 MiB │
32. │ Not Installed │ Cloud Datastore Emulator (Legacy) │ gcd-emulator │ 38.1 MiB │
33. │ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 33.4 MiB │
34. │ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │
35. │ Not Installed │ Google Container Local Builder │ container-builder-local │ 3.7 MiB │
36. │ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ 2.5 MiB │
37. │ Not Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │
38. │ Not Installed │ gcloud Beta Commands │ beta │ < 1 MiB │
39. │ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 118.9 MiB │
40. │ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │
41. │ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.2 MiB │
42. │ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 27.8 MiB │
43. │ Not Installed │ kubectl │ kubectl │ 12.2 MiB │
44. │ Installed │ BigQuery Command Line Tool │ bq │ < 1 MiB │
45. │ Installed │ Cloud SDK Core Libraries │ core │ 7.4 MiB │
46. │ Installed │ Cloud Storage Command Line Tool │ gsutil │ 3.4 MiB │
47. └───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
48. To install or remove components at your current SDK version [194.0.0], run:
49. $ gcloud components install COMPONENT_ID
50. $ gcloud components remove COMPONENT_ID
52. To update your SDK installation to the latest version [194.0.0], run:
53. $ gcloud components update
56. Modify profile to update your $PATH and enable shell command
57. completion?
59. Do you want to continue (Y/n)? Y
61. The Google Cloud SDK installer will now prompt you to update an rc
62. file to bring the Google Cloud CLIs into your environment.
64. Enter a path to an rc file to update, or leave blank to use
65. [/Users/user/.zshrc]:
66. Backing up [/Users/user/.zshrc] to [/Users/user/.zshrc.backup].
67. [/Users/user/.zshrc] has been updated.
69. ==> Start a new shell for the changes to take effect.
72. For more information on how to get started, please visit:
73. https://cloud.google.com/sdk/docs/quickstarts
After that, you can start a new shell, and you should have access to the gcloud cli. For example:
1. > gcloud --version
2. Google Cloud SDK 194.0.0
3. bq 2.0.30
4. core 2018.03.16
5. gsutil 4.29
You will also need to install some components with the cli (gcloud components install app-engine-java):
1. > gcloud components install app-engine-java
4. Your current Cloud SDK version is: 194.0.0
5. Installing components from version: 194.0.0
7. ┌────────────────────────────────────────────────────┐
8. │ These components will be installed. │
9. ├──────────────────────────────┬─────────┬───────────┤
10. │ Name │ Version │ Size │
11. ├──────────────────────────────┼─────────┼───────────┤
12. │ gRPC python library │ │ │
13. │ gRPC python library │ 1.9.1 │ 7.6 MiB │
14. │ gcloud app Java Extensions │ 1.9.63 │ 118.9 MiB │
15. │ gcloud app Python Extensions │ 1.9.67 │ 6.2 MiB │
16. └──────────────────────────────┴─────────┴───────────┘
18. For the latest full release notes, please visit:
19. https://cloud.google.com/sdk/release_notes
21. Do you want to continue (Y/n)? Y
23. ╔════════════════════════════════════════════════════════════╗
24. ╠═ Creating update staging area ═╣
25. ╠════════════════════════════════════════════════════════════╣
26. ╠═ Installing: gRPC python library ═╣
27. ╠════════════════════════════════════════════════════════════╣
28. ╠═ Installing: gRPC python library ═╣
29. ╠════════════════════════════════════════════════════════════╣
30. ╠═ Installing: gcloud app Java Extensions ═╣
31. ╠════════════════════════════════════════════════════════════╣
32. ╠═ Installing: gcloud app Python Extensions ═╣
33. ╠════════════════════════════════════════════════════════════╣
34. ╠═ Creating a backup and activating a new installation ═╣
35. ╚════════════════════════════════════════════════════════════╝
37. Performing post-processing steps...done.
39. Update done!
For your project, you can use gradle and the official appengine-gradle-plugin. So a build.gradle would look like this:
build.gradle
1. buildscript {
2. ext.appengine_version = '1.9.60'
3. ext.appengine_plugin_version = '1.3.4'
5. repositories {
6. jcenter()
7. }
8. dependencies {
9. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10. classpath "com.google.cloud.tools:appengine-gradle-plugin:$appengine_plugin_version"
11. }
12. }
14. apply plugin: 'kotlin'
15. apply plugin: 'war'
16. apply plugin: 'com.google.cloud.tools.appengine'
18. // appengine does not honor this property, so we are forced to use deep Maven tree layout
19. // webAppDirName = file('webapp')
21. sourceSets {
22. main.kotlin.srcDirs = [ 'src/main/kotlin' ]
23. }
25. repositories {
26. jcenter()
27. }
29. dependencies {
30. compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
31. compile "io.ktor:ktor-server-servlet:$ktor_version"
32. compile "io.ktor:ktor-html-builder:$ktor_version"
33. compile "org.slf4j:slf4j-jdk14:$slf4j_version"
35. providedCompile "com.google.appengine:appengine:$appengine_version"
36. }
38. kotlin.experimental.coroutines = 'enable'
40. task run(dependsOn: appengineRun)
Once everything is configured, you can now run the application locally, using the gradle task appengineRun:
In this case, these commands are executed in the root of the ktor-samples repository <https://github.com/ktorio/ktor-samples/>:
1. ./gradlew :google-appengine-standard:appengineRun
It should start the server in <http://localhost:8080/> and the admin in <http://localhost:8080/_ah/admin>.
Deploying
First, we need to create a project gcloud projects create demo-demo-123456 —set-as-default:
1. > gcloud projects create demo-demo-123456 --set-as-default
2. Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/demo-demo-123456].
3. Waiting for [operations/pc.7618150612308930095] to finish...done.
4. Updated property [core/project] to [demo-demo-123456].
And then we need to create an application using gcloud app create:
1. > gcloud app create
2. You are creating an app for the project [demo-demo-123456].
3. WARNING: Creating an App Engine application for a project is irreversible, and the region
4. cannot be changed. More information about regions is at
5. <https://cloud.google.com/appengine/docs/locations>.
7. Please choose the region where you want your App Engine application
8. located:
10. [1] europe-west2 (supports standard and flexible)
11. [2] us-central (supports standard and flexible)
12. [3] europe-west (supports standard and flexible)
13. [4] europe-west3 (supports standard and flexible)
14. [5] us-east1 (supports standard and flexible)
15. [6] us-east4 (supports standard and flexible)
16. [7] asia-northeast1 (supports standard and flexible)
17. [8] asia-south1 (supports standard and flexible)
18. [9] australia-southeast1 (supports standard and flexible)
19. [10] southamerica-east1 (supports standard and flexible)
20. [11] northamerica-northeast1 (supports standard and flexible)
21. [12] cancel
22. Please enter your numeric choice: 1
24. Creating App Engine application in project [demo-demo-123456] and region [europe-west2]....done.
25. Success! The app is now created. Please use `gcloud app deploy` to deploy your first app.
Now we can deploy the application using gradle appengineDeploy:
1. > gradle :google-appengine-standard:appengineDeploy
2. Starting a Gradle Daemon (subsequent builds will be faster)
3. Reading application configuration data...
4. Mar 23, 2018 6:32:09 AM com.google.apphosting.utils.config.IndexesXmlReader readConfigXml
5. INFORMATION: Successfully processed /Users/user/projects/ktor-samples/deployment/google-appengine-standard/build/exploded-google-appengine-standard/WEB-INF/appengine-generated/datastore-indexes-auto.xml
8. Beginning interaction for module default...
9. 0% Scanning for jsp files.
10. 0% Generated git repository information file.
11. Success.
12. Temporary staging for module default directory left in /Users/user/projects/ktor-samples/deployment/google-appengine-standard/build/staged-app
13. Services to deploy:
15. descriptor: [/Users/user/projects/ktor-samples/deployment/google-appengine-standard/build/staged-app/app.yaml]
16. source: [/Users/user/projects/ktor-samples/deployment/google-appengine-standard/build/staged-app]
17. target project: [demo-demo-123456]
18. target service: [default]
19. target version: [20180323t063212]
20. target url: [https://demo-demo-123456.appspot.com]
23. Beginning deployment of service [default]...
24. Some files were skipped. Pass `--verbosity=info` to see which ones.
25. You may also view the gcloud log file, found at
26. [/Users/user/.config/gcloud/logs/2018.03.23/06.32.10.739209.log].
27. #============================================================#
28. #= Uploading 38 files to Google Cloud Storage =#
29. #============================================================#
30. File upload done.
31. Updating service [default]...
32. ..............done.
33. Setting traffic split for service [default]...
34. .......done.
35. Deployed service [default] to [https://demo-demo-123456.appspot.com]
37. You can stream logs from the command line by running:
38. $ gcloud app logs tail -s default
40. To view your application in the web browser run:
41. $ gcloud app browse
43. BUILD SUCCESSFUL in 42s
44. 6 actionable tasks: 2 executed, 4 up-to-date
Now you can view your application in your browser with gcloud app browse. It will openthe application. In this case: <https://demo-demo-123456.appspot.com>
