[JAVA] Until you deploy a SpringBoot project in Gradle on App Engine Flexible

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

Source for the time being

I'll put it on github appenginetest

environment

OS Windows10 pro Java Java SE 1.8.0_121 Gradle 3.4.1 Eclipse Pleiades All in One 4.6.3.v20170323

Preparation

Creating a Google Cloud Platform account is omitted here.

Install Google Cloud SDK

Official document is easy to understand, so omitted

Install App Engine SDK for Java

After completing the SDK initialization, throw the following command to install the SDK for Java

gcloud components install app-engine-java

Create a test project on GCP

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.

Spring-Boot project preparation

I will make it using Eclipse

Project creation

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.

gradle settings

Open build.gradle and configure various settings

App Engine plugin

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 ...

build.gradle sample

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

Sauce

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.

Settings for App Engine

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

Dockerfile settings

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"]

Try to build

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 *

Deploy to App Engine

Project settings

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 ** 2017-04-02_19h00_46.png 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

Deploy to App Engine

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

Take a look

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.

so

This is the minimum Next is DB related, but I will give it separately

Recommended Posts

Until you deploy a SpringBoot project in Gradle on App Engine Flexible
Until you create a new app in Django
Deploy a Django application on Google App Engine (Python3)
Until you run a Flask application on Google App Engine for the time being
How to deploy a Django app on heroku in just 5 minutes
Deploy a Python app on Google App Engine and integrate it with GitHub
Until you publish (deploy) a web application made with bottle on Heroku
Deploy a Python 3.6 / Django / Postgres web app on Azure
Until drawing a 3D graph in Python on windows10
Until you insert data into a spreadsheet in Python
Deploy a Django app made with PTVS on Azure
Do you have any recommendations for a commentary book on Google App Engine / Python development?
A solution when you can't start project Django on Windows
(Failure) Deploy a web app made with Flask on heroku
Deploy your Go app on Google App Engine with GitHub Actions
Deploy masonite app on Heroku 2020
Building a development environment with Maven on Google App Engine [Java]
Using properties files with Flexible Environment Java 8 on Google App Engine