Как развернуть приложение Ktor в Google App Engine? - PullRequest
0 голосов
/ 15 марта 2020

Официальный учебник от Ktor.io не работает, я попробовал. Это мое первое развертывание. Спасибо за помощь.

Мой файл gradle (kts):

import com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlExtension

buildscript {
    dependencies {
        classpath("com.google.cloud.tools:appengine-gradle-plugin:2.2.0")
    }
}

apply {
    plugin("com.google.cloud.tools.appengine")
}

plugins {
    // Support for Kotlin
    id("org.jetbrains.kotlin.jvm") version "1.3.61"
    // Support for building a CLI application
    application
    // Documentation
    id("org.jetbrains.dokka") version "0.10.1"

    war
//    id("com.improve_future.harmonica") version "1.1.24"
}

application {
    mainClassName = "com.easythings.parkkometr.AppKt"
    group = "com.easythings"
    version = "0.0.1"
}

sourceSets {
    main {
        java.srcDir("app/main/src")
        resources.srcDir("app/main/resources")
    }
    test {
        java.srcDir("app/test/src/")
        resources.srcDir("app/test/resources/")
    }
}

repositories {
    jcenter()
    maven { setUrl("https://kotlin.bintray.com/ktor") }
}

dependencies {
    val ktorVersion: String by project
    val logbackVersion: String by project
    val exposedVersion: String by project
    val pgVersion: String by project
    val spekVersion: String by project
    val sendGridVersion: String by project
    val assertJVersion: String by project

    // Kotlin ============================================================================
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

    // Libs ============================================================================
    // Ktor - framework
    implementation("io.ktor", "ktor-server-jetty", ktorVersion)
    implementation("io.ktor", "ktor-server-core", ktorVersion)
    implementation("io.ktor", "ktor-server-host-common", ktorVersion)
    implementation("io.ktor", "ktor-auth", ktorVersion)
    implementation("io.ktor", "ktor-auth-jwt", ktorVersion)
    implementation("io.ktor", "ktor-gson", ktorVersion)
    implementation("io.ktor", "ktor-network-tls-certificates", ktorVersion)

    // Logback - application logger
    implementation("ch.qos.logback", "logback-classic", logbackVersion)

    // Exposed - orm
    implementation("org.jetbrains.exposed", "exposed-core", exposedVersion)
    implementation("org.jetbrains.exposed", "exposed-dao", exposedVersion)
    implementation("org.jetbrains.exposed", "exposed-jdbc", exposedVersion)
    implementation("org.jetbrains.exposed", "exposed-jodatime", exposedVersion)

    // Postgresql - database driver
    implementation("org.postgresql", "postgresql", pgVersion)

    // SendGrid - mailer
    implementation("com.sendgrid", "sendgrid-java", sendGridVersion)

    // Deploy ============================================================================
    providedCompile("com.google.appengine", "appengine", "1.9.60")

    // Tests ============================================================================
}

tasks {
    dokka {
        outputDirectory = "$buildDir/docs/dokka"
        outputFormat = "html"
    }

    test {
        useJUnitPlatform {
            includeEngines("spek2")
        }
    }
}

configure<AppEngineAppYamlExtension> {
    deploy {
        setAppEngineDirectory(".")
        version = "1"
        projectId = "XYZ-placeholder"
        stopPreviousVersion = true  // default - stop the current version
        promote = true              // default - & make this the current version
    }
    stage {
        setAppEngineDirectory(".")
    }
}

Мой файл app.yaml:

runtime: java
env: flex

handlers:
  - url: /.*
    script: this field is required, but ignored

Я получаю информацию, что развертывание успешно завершено , но я получаю ошибку 403 при вызове gcloud app browse.

HTTP ERROR 403 Проблема доступа /. Причина:

Forbidden

Я думаю, что мое приложение не запускается, и это ошибка Jetty, но я не знаю, как проверить / подтвердить и исправить ее.

Задача appengineRun не существует в этой версии GAE.

1 Ответ

1 голос
/ 17 марта 2020

Прежде всего, предоставленное руководство по Ktor для среды App Engine Standard, но у вас есть "flex" env в файле app.yaml. Также я хотел бы рекомендовать вам следовать официальной более информативной Google Cloud документации для Ktor .

...