Google App Engine
You first need to install the cli. You can grab it from here: https://cloud.google.com/sdk/docs/ and follow the described steps to install it.
After that, you can start a new shell, and you should have access to the gcloud
cli. For example:
> gcloud --version
Google Cloud SDK 194.0.0
bq 2.0.30
core 2018.03.16
gsutil 4.29
You will also need to install some components with the cli (gcloud components install app-engine-java
):
For your project, you can use gradle and the official appengine-gradle-plugin
. So a build.gradle
would look like this:
buildscript {
ext.appengine_version = '1.9.60'
ext.appengine_plugin_version = '1.3.4'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.cloud.tools:appengine-gradle-plugin:$appengine_plugin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
// appengine does not honor this property, so we are forced to use deep Maven tree layout
// webAppDirName = file('webapp')
sourceSets {
main.kotlin.srcDirs = [ 'src/main/kotlin' ]
repositories {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "io.ktor:ktor-server-servlet:$ktor_version"
compile "io.ktor:ktor-html-builder:$ktor_version"
compile "org.slf4j:slf4j-jdk14:$slf4j_version"
providedCompile "com.google.appengine:appengine:$appengine_version"
}
kotlin.experimental.coroutines = 'enable'
task run(dependsOn: appengineRun)
Once everything is configured, you can now run the application locally, using the gradle task appengineRun
:
It should start the server in 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
:
> gcloud projects create demo-demo-123456 --set-as-default
Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/demo-demo-123456].
Waiting for [operations/pc.7618150612308930095] to finish...done.
Updated property [core/project] to [demo-demo-123456].
And then we need to create an application using gcloud app create
:
Now we can deploy the application using gradle appengineDeploy
:
> gradle :google-appengine-standard:appengineDeploy
Starting a Gradle Daemon (subsequent builds will be faster)
Reading application configuration data...
Mar 23, 2018 6:32:09 AM com.google.apphosting.utils.config.IndexesXmlReader readConfigXml
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
Beginning interaction for module default...
0% Scanning for jsp files.
Success.
Services to deploy:
descriptor: [/Users/user/projects/ktor-samples/deployment/google-appengine-standard/build/staged-app/app.yaml]
source: [/Users/user/projects/ktor-samples/deployment/google-appengine-standard/build/staged-app]
target project: [demo-demo-123456]
target service: [default]
target version: [20180323t063212]
target url: [https://demo-demo-123456.appspot.com]
Beginning deployment of service [default]...
Some files were skipped. Pass `--verbosity=info` to see which ones.
You may also view the gcloud log file, found at
[/Users/user/.config/gcloud/logs/2018.03.23/06.32.10.739209.log].
#============================================================#
#= Uploading 38 files to Google Cloud Storage =#
#============================================================#
File upload done.
Updating service [default]...
..............done.
Setting traffic split for service [default]...
.......done.
Deployed service [default] to [https://demo-demo-123456.appspot.com]
You can stream logs from the command line by running:
$ gcloud app logs tail -s default
To view your application in the web browser run:
$ gcloud app browse
BUILD SUCCESSFUL in 42s