GoogleCloudPlatform / app-gradle-plugin

The library has moved to https://github.com/GoogleCloudPlatform/appengine-plugins/tree/main/app-gradle-plugin
Apache License 2.0
153 stars 40 forks source link

Deployables filtering #135

Closed sparhomenko closed 2 years ago

sparhomenko commented 7 years ago

We are trying to use appengine-gradle-plugin for deploying a web app to GAE Flexible. The app is using Google Cloud Endpoints 2 and has this in app.yaml:

endpoints_api_service:
  name: ${cloudProject}.appspot.com
  config_id: ${cloudConfigId}

These parameters differ on different environments (test and production): name needs to have the correct project ID, and config_id needs to be set to the API version currently deployed to this particular environment. Both values are available in our Gradle build, but appengineStage task does not perform Gradle filtering (properties substitution) when copying deployables from appEngineDirectory to stagingDirectory.

We can work this around by pre-filtering with a custom Gradle task into a custom appEngineDirectory. But seeing how Gretty provides filtering for src/main/webapp it would be convenient to have the same capability here. It will likely be useful for other deployables, like env_variables in app.yaml and URLs in dispatch.yaml.

Any alternative suggestions are very welcome.

loosebazooka commented 7 years ago

Yeah so appengineStage is not a copy task because we share that code across gradle/maven plugins, so using the copy task filtering isn't possible. Your best bet right now is to use a custom task like you said and point stage to that directory.

If you haven't already done this, there are some ways you can wire it in directly into your build

appengine.stage.appEngineDirectory = "${buildDir}/filteredAppEngineDir"

task filterAppEngineDir(type: Copy) {
  from ("src/main/appengine") {
    filter { 
      it.replaceAll("@@some-token@@", "custom-value")
    }
  }
  // use closures for late evaluation
  into { 
    project.appengine.stage.appEngineDirectory 
  }
}

// make sure stage calls this filtering guy first
appengineStage.dependsOn filterAppEngineDir

Then run:

./gradlew appengineStage

OR You can inject the params from the command line using project properties

appengine.stage.appEngineDirectory = "${buildDir}/filteredAppEngineDir"

task filterAppEngineDir(type: Copy) {
  // add as input so that when changed it triggers a rebuild
  inputs.property("customProperty", project.customProperty)

  from ("src/main/appengine") {
    filter { 
      it.replaceAll("@@some-token@@", project.customProperty)
    }
  }
  // use closures for late evaluation
  into { 
    project.appengine.stage.appEngineDirectory 
  }
}

// make sure stage calls this filtering guy first
appengineStage.dependsOn filterAppEngineDir

Then run:

./gradlew appengineStage -PcustomProperty=foobar
patflynn commented 7 years ago

might be worth considering for the core library.

On Thu, May 11, 2017 at 3:16 PM, Appu Goundan notifications@github.com wrote:

Yeah so appengineStage is not a copy task because we share that code across gradle/maven plugins, so using the copy task filtering isn't possible. Your best bet right now is to use a custom task like you said and point stage to that directory.

If you haven't already done this, there are some ways you can wire it in directly into your build

appengine.stage.appEngineDirectory = "${buildDir}/filteredAppEngineDir"

task filterAppEngineDir(type: Copy) { from ("src/main/appengine") { filter { it.replaceAll("@@some-token@@", "custom-value") } } // use closures for late evaluation into { project.appengine.stage.appEngineDirectory } } // make sure stage calls this filtering guy first appengineStage.dependsOn filterAppEngineDir

Then run:

./gradlew appengineStage


OR You can inject the params from the command line using project properties

appengine.stage.appEngineDirectory = "${buildDir}/filteredAppEngineDir"

task filterAppEngineDir(type: Copy) { // add as input so that when changed it triggers a rebuild inputs.property("customProperty", project.customProperty)

from ("src/main/appengine") { filter { it.replaceAll("@@some-token@@", project.customProperty) } } // use closures for late evaluation into { project.appengine.stage.appEngineDirectory } } // make sure stage calls this filtering guy first appengineStage.dependsOn filterAppEngineDir

Then run:

./gradlew appengineStage -PcustomProperty=foobar

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues/135#issuecomment-300889902, or mute the thread https://github.com/notifications/unsubscribe-auth/AHf5HZHkLiIvuknHlKu2aTovz8gewlqcks5r416jgaJpZM4NXUUN .

sparhomenko commented 7 years ago

@loosebazooka We are already filtering in a build task, but thanks for the advice, property as an input to trigger a rebuild is a useful improvement. I understand that having to support both Maven and Gradle makes it complicated, so feel free to close if you feel like the benefit is not worth the effort.

marceloverdijk commented 6 years ago

@sparhomenko would you be able to share how you did this? I'm trying to accomplish something similar at the moment (https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues/195).