How can I create a task that dynamically set app engine project id and run the appengineDeploy task?
On this example when I run deployStaging appengineDeploy is being executed with project 'a', how I can rewrite this code to make it run with project 'b'?
buildscript {
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.0.1")
}
}
apply plugin: 'com.google.cloud.tools.appengine'
def gcpProject = 'a'
appengine {
deploy {
projectId = gcpProject
}
}
task deployStaging() {
doLast {
gcpProject = 'b'
}
}
deployStaging.finalizedBy appengineDeploy
Answer provided by the gradle plugin folks:
appengine {
deploy {
version = "123"
// do not define projectId here
}
}
task deployStaging {
dependsOn appengineDeploy
}
task deployProduction {
dependsOn appengineDeploy
}
// here's the weird gradle logic, use at your own risk
if (project.gradle.startParameter.taskNames.contains("deployStaging")) {
appengine.deploy.projectId = "potato-stage"
}
else if(project.gradle.startParameter.taskNames.contains("deployProduction")) {
appengine.deploy.projectId = "tomato-prod"
}
How about using a project property instead? Project properties can be passed via -P command line parameters:
buildscript {
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.0.1")
}
}
apply plugin: 'com.google.cloud.tools.appengine'
def gcpProject = project.findProperty('stageName') ?: 'a'
appengine {
deploy {
projectId = gcpProject
}
}
Now if you just call ./gradlew appengineDeploy the gcpProject variable will have the value 'a'. If you call ./gradlew appengineDeploy -PstageName=b the gcpProject variable will have the value 'b'.
Related
I am trying to deploy my first app engine spring boot project using gradle and I am running into the following error when I run "gradle appengineDeploy":
ERROR: (gcloud.app.deploy) Error Response: [403] Operation not allowed
Details: [
[
{
"#type": "type.googleapis.com/google.rpc.ResourceInfo",
"description": "The \"appengine.applications.get\" permission is required.",
"resourceType": "gae.api"
}
]
]
Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
classpath("com.google.cloud.tools:appengine-gradle-plugin:+")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.google.cloud.tools.appengine'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
maven {
url 'https://maven-central.storage.googleapis.com'
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
// tag::tests[]
testCompile("org.springframework.boot:spring-boot-starter-test")
// end::tests[]
//compile("com.google.cloud.tools:appengine-maven-plugin:1.0.0")
//appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.50'
compile('com.google.appengine:appengine:+')
}
appengine {
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
Please let me know how to proceed.
I got this after updating the google cloud sdk. I just run gcloud init again and entered the same choices.
I recreated the app engine instance and the problem was fixed
A bit silly, but I got this error by mistyping the GCP project name:
$ gcloud app deploy app.yaml --project=wrong-project-name
I fixed this issue by enabling the 'google app engine' cloud api in their api console.
When I run the application with IntelliJ the image is visible but when ported to Android (6.0 & 4.4.2) it isn't. The Image object is instantiated with an URL (website).
Logcat
W/linker: /data/app/com.xxxx.xxxx.scan.application.scanner-2/lib/arm/libjavafx_iio.so: is missing DT_SONAME will use basename as a replacement: "libjavafx_iio.so"
W/System.err: java.io.IOException: Improper call to JPEG library in state 200
//##The error below is thrown at the new Image(url) operation
W/System.err: at com.xxxx.xxxx.scan.application.scanner.controllers.ProductController.updateImageView(ProductController.java:117)
Method that loads the image
private synchronized void updateImageView(ProductEntry product) {
if (product.getExtraInfo() != null && product.getExtraInfo().size() > 0) {
ExtraInfo extraInfo = product.getExtraInfo().get(0);
figLabel.setText(extraInfo.getInfo());
image = new Image(extraInfo.getUrl());
imageView.fitHeightProperty().bind(pane.heightProperty());
imageView.fitWidthProperty().bind(pane.widthProperty());
imageView.setPreserveRatio(true);
// imageView.setSmooth(true);
// imageView.setCache(true);
imageView.setImage(image);
}
}
build.gradle
buildscript {
repositories {
jcenter()
maven {
url 'http://xxxx.xxxx.com:8080/artifactory/plugins-release'
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:+"
}
}
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: "com.jfrog.artifactory"
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
maven = true
}
}
resolve {
repository {
repoKey = 'libs-release'
maven = true
}
}
}
repositories {
jcenter()
mavenLocal()
}
mainClassName = 'com.essers.pxl2016.scan.application.scanner.MainApplication'
dependencies {
compile(group: 'com.essers.pxl2016', name: 'scan-server-definition', version: '0.0.1-SNAPSHOT')
compile(group: 'com.xxxx.xxxx', name: 'client', version: '1.0-SNAPSHOT')
compile('com.google.code.gson:gson:2.2.4')
testCompile "junit:junit:4.12"
}
jfxmobile {
javafxportsVersion = '8.60.7'
ios {
forceLinkClasses = ['com.xxxx.xxxx.scan.**.*']
}
android {
applicationPackage = 'com.xxxx.xxxx.scan.application.scanner'
}
}
test {
exclude 'com/xxxx/xxxx/scan/application/scanner/**'
}
src/main/resources/java.custom.properties
# Solves crash when clicking the menu.
monocle.stackSize=128000
Kind regards
The cause of the problem appears to be the file size of the image. The image showed up after reducing the file size.
Is there a good way to execute the gcloud commands to deploy an app to GAE and see the stderr/stdout echoed back at the console? I've tried gulp-exec but it seems to batch up the output, dumping only upon completion. It also won't play nicely when trying to preview locally.
In the end I didn't want to have to use another npm, but loosely inspired by a portion of gulp-run, I came up with the following that assumes a 'clean' and 'build' task exists, and also overrides some constants per environment for a gulp-replace task that is part of my 'build', the key being the spawn of a subshell and piping its output to the current process's:
// gulp deploy [-a dev|staging|prod]
gulp.task('deploy', function() {
var commands = {
remote: 'gcloud preview app deploy app.yaml -q --set-default --project ',
local: 'gcloud preview app run app.yaml'
};
var environments = {
dev: {
app: 'myapp-dev',
},
staging: {
app: 'myapp-staging',
MY_ENDPOINT: 'https://staging.example.com'
},
prod: {
app: 'myapp',
MY_ENDPOINT: 'https://example.com'
}
};
var command = commands.local;
var env = environments[argv.a];
if (env) {
command = commands.remote + env.app;
constantsMap.MY_ENDPOINT = env.MY_ENDPOINT;
}
// Now that our constants are configured, kick off the build, then deploy.
runSequence('clean', 'build', function() {
var title = util.format('$ %s\n', $.util.colors.blue(command));
process.stdout.write(title);
// run the command in its own subshell and pipe the output to our own.
var subshell = childProcess.spawn('sh', ['-c', command]);
subshell.stdout.pipe(process.stdout);
subshell.stderr.pipe(process.stderr);
});
});
This relies on the npms: run-sequence, util, yargs, gulp-load-plugins
If you want to execute commands following code snippet will help you. I have wrapped it inside a promise as you are using gulp:
var cp = require('child_process');
function executeCommand(command, option) {
return new Promise(function (resolve, reject) {
var args = [option.something, option.something];
var ls = cp.spawn(command, args);
var output = "";
ls.on('error', function (err) {
reject(err);
});
ls.stdout.on('data', function (data) {
output += String(data);
console.log(output)
});
ls.on('exit', function (code) {
if (code === 0) {
resolve({
"output": output
});
} else {
reject(Error(output));
}
});
});
}
I am using gulp-gae and it seems it works well.
Supported commands are appcfg.py and dev_appserver.py (in current version). It can be also configured to override some values from the given app.yaml.
I m working on Mac, with Android Studio.
I m trying to build a Android App with a Google App Engine BackEnd.
I've installed Maven and Gradel and exported the M2_HOME et GRADLE_HOME
Whenever I run any of the Gradle commends I get this :
Error:(21, 0) Gradle: A problem occurred evaluating project
':backend'. Plugin with id 'appengine' not found.
the Build.gradle file :
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.3'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.0.+'
compile 'com.google.guava:guava:16.0.+'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
From description on plugin github page you need to define plugin JAR file in the classpath of your build script.
So here is how it can be done:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.3'
}
}
....
I have just started with gae plugin. The problem is that when I run gradle gaeRun I get the exception:
com.google.apphosting.utils.config.AppEngineConfigException: Could not locate ../myapp/build/exploded-war/WEB-INF/appengine-web.xml
So far I managed to get round the problem by adding the following in my gradle.build script:
gaeRun.doFirst{
copy {
from('war/WEB-INF/') {
include '**/*'
}
into 'build/exploded-war/WEB-INF/'
}
}
Is that the correct approach? Below is the whole script:
apply plugin: 'gae'
apply plugin: 'eclipse'
apply plugin: 'scala'
task wrapper(type: Wrapper) {
gradleVersion = '1.0'
}
buildscript {
repositories { mavenCentral() }
dependencies {
classpath 'org.gradle.api.plugins:gradle-gae-plugin:0.7.6'
}
}
repositories {
mavenCentral()
}
dependencies {
scalaTools 'org.scala-lang:scala-compiler:2.9.1'
scalaTools 'org.scala-lang:scala-library:2.9.1'
compile 'org.scala-lang:scala-library:2.9.1'
testCompile group: 'junit', name: 'junit', version: '4.8.2'
}
gae {
httpPort = 8085
optimizeWar = true
appcfg {
email = 'email#gmail.com'
passIn = true
logs {
severity = 1
outputFile = file('mylogs.txt')
}
app { id = 'sample-app' }
}
}
gaeRun.doFirst{
copy {
from('war/WEB-INF/') {
include '**/*'
}
into 'build/exploded-war/WEB-INF/'
}
}