The Flexible Environment of Google App Engine has been released for a long time, but it is a memo because I could not find a sample that deploys and runs the spring-boot ** project with ** gradle. The official documentation is ** maven ** centered
I'll put it on github appenginetest
OS Windows10 pro Java Java SE 1.8.0_121 Gradle 3.4.1 Eclipse Pleiades All in One 4.6.3.v20170323
Creating a Google Cloud Platform account is omitted here.
Official document is easy to understand, so omitted
After completing the SDK initialization, throw the following command to install the SDK for Java
gcloud components install app-engine-java
Create a new project on Google Cloud Platform This time I will make it with the name ** spring boot test ** Make a note of the project ID as you will use it later.
I will make it using Eclipse
Select Gradle project from File-> New-> Other The project name is ** appenginetest **
On the next screen, specify the Gradle you have installed Could I keep the default depending on the Eclipse settings?
Check the configuration on the next screen, and if there is no warning, it is completed I get a warning if the gradle settings are not correct
After completion, Library.java and LibraryTest.java are created under src, but they will not be used, so delete them.
Open build.gradle and configure various settings
Refer to this area Officially, I use a plugin called ** gretty **, but this time I'm going to use Spring-Boot, so I will remove it.
Well, I just didn't know how to use it ...
And here is the setting of spring-boot
build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.1.1'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.+'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'eclipse'
def defaultEncoding = 'UTF-8'
[compileJava, compileTestJava]*.options*.encoding = defaultEncoding
def jdkVersion = 1.8
sourceCompatibility = jdkVersion
targetCompatibility = jdkVersion
jar {
baseName = 'appenginetest'
version = '1.0-SNAPSHOT'
}
repositories {
maven {
url 'https://maven-central.storage.googleapis.com'
}
jcenter()
mavenCentral()
}
dependencies {
compile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'com.google.appengine:appengine:+'
compile('org.springframework.boot:spring-boot-starter-web:1.5.+'){
exclude module: 'spring-boot-starter-tomcat'
}
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty', version: '1.5.+'
}
For the time being, I just deploy it and display something, so it's like this
Next java file to use in Spring-Boot
Application.java
package appenginetest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@RequestMapping(value = "/")
String hello() {
return "Hello World!";
}
}
I can only see "Hello World!" Because I just want to see it deploy and work.
Next, write the configuration file for App Engine The location will be * src / main / appengine *
app.yaml
runtime: custom
env: flex
runtime_config:
jdk: openjdk8
automatic_scaling:
min_num_instances: 1
max_num_instances: 1
If you use standard java8 + jetty, specify * runtime * as * java *, but this time it is a custom environment of * Spring-Boot + jetty *, so specify * custom *
There are many others, but see Official
Write settings for Docker running on App Engine The location will be * src / main / Docker *
Dockerfile
FROM gcr.io/google_appengine/openjdk8
VOLUME /tmp
ADD appenginetest-1.0-SNAPSHOT.jar app.jar
CMD [ "java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Go to the root of the project created at the command prompt and execute the following command
gradle appengineStage
If the settings are correct, exit with * BUILD SUCCESSFUL *
Make settings for this project Create the settings with the following command
gcloud config configurations create [NAME]
Give [NAME] a descriptive name
After setting, enable the setting
gcloud config configurations activate [NAME]
Enable the setting and link the project created on Google Cloud Platform So, note here, please use the project name ** project ID ** In the red part here, if you specify the project name incorrectly, you will not get an error, but it will fail in the final deployment.
gcloud config set project [PROJECT]
Setting the project default zone
gcloud config set compute/zone us-east1-b
To display the settings, use the following command
gcloud config configurations describe [NAME]
You can check what the valid settings are with the following command
gcloud config list
Log in once you have the valid settings
gcloud auth login
A browser will open and a list of accounts to log in will appear, so select an account that you can log in with Google Cloud Platform. On the next screen, the Google Cloud SDK will ask for permission, so allow it.
I'm a little unsure about the procedure around here Maybe I'm throwing extra commands ...
The official documentation is here
If you can confirm the valid settings, it is finally deployed Execute the following command from the root of the project
gradle appengineDeploy
Wait for a while after executing the command Even this small sample project takes about 5 minutes
When the deploy command comes back, you'll see a link in the upper right corner of the App Engine dashboard, so let's check it out. If "Hello World!" Is displayed, it is successful.
This is the minimum Next is DB related, but I will give it separately
Recommended Posts