Skip to content

Commit

Permalink
Voorbereiden voor Google Cloud Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
rschellius committed Sep 20, 2016
1 parent f34e838 commit dc8f80e
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 13 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
#
# This is the image for plain X86 machines.
#
FROM java:8
# FROM java:8
# VOLUME /tmp
#
# The image to run the app on Google Cloud App Engine
#
FROM gcr.io/google_appengine/java-compat
VOLUME /tmp

# Install maven
Expand All @@ -31,6 +36,9 @@ ADD src /code/src
RUN ["mvn", "compile"]
RUN ["mvn", "package"]

ADD spring-boot-thymeleaf-1.0.jar app.jar
EXPOSE 8080
CMD ["java", "-jar", "target/spring-boot-thymeleaf-1.0.jar"]
# CMD ["java", "-jar", "target/spring-boot-thymeleaf-1.0.jar"]
CMD ["java", "-jar", "/app.jar"]

# done
32 changes: 32 additions & 0 deletions Google-Cloud-readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Draai je app op Google Cloud

Om deze of een andere app op Google Cloud te draaien doe je het volgende:
1. Maak een account aan op https://cloud.google.com/. Je moet daarvoor wel
betaalgegevens (creditcard) ingeven. Je krijgt een budget voor 300 euro gratis.

2. gcloud SDK op je laptop installeren
Hiermee kun je lokaal de instellingen op je cloud environment instellen.
Op de https://cloud.google.com/ site vind je meer info, of zoek in Google.

3. Maak een nieuw project. Als je een account hebt doe je dit online.
Let op: je project moet in US-central draaien; nergens anders. Anders kun je
je app later niet deployen (we maken gebruik van beta versies van GCloud; sept 2016).

Op je lokale machine:
4. pom.xml aanpassen zodat hij google engine herkent. Zie Spring Bieb voorbeeld.
5. Juiste mappen aanmaken en app.yaml toevoegen in de juiste map. Zie Spring Bieb voor locatie en inhoud.
6. Zet je Dockerfile in de map [project]/dockerfile.
Hierin hoef je geen rekening te houden met compileren en downloaden van benodigde
software, wat je normaal bij een dockerfile wel moet doen. Alleen de juiste
OS image, een goede naam voor je app, en de startup commands. Zie voorbeeld Bieb.

7. Vanuit een command line venster:
mvn clean install appengine:deploy

Hiermee installeer je je app.jar bestand en het Dockerfile op Google Cloud. Kijk goed naar evt. foutmeldingen.


Het draaien van je app in de cloud vraagt om het instellen van verschillende profiles
in Spring. Je hebt nl. settings nodig voor de cloud-omgeving die waarschijnlijk afwijken
van je localhost omgeving - zoals database host en portnr. Zie daarvoor ook de Bieb app,
en de verschillende resources/application-[].profile bestanden.
2 changes: 1 addition & 1 deletion library.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- --------------------------------------------------------

DROP SCHEMA IF EXISTS `library` ;
CREATE SCHEMA IF NOT EXISTS `library` DEFAULT CHARACTER SET utf8 ;
CREATE SCHEMA IF NOT EXISTS `library` DEFAULT CHARACTER SET utf8;
USE `library` ;

--
Expand Down
50 changes: 45 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<modelVersion>4.0.0</modelVersion>
<groupId>nl.avans.ivh5.example.springmvc</groupId>
<artifactId>spring-boot-thymeleaf</artifactId>
<version>1.0</version>
<name>spring-boot-thymeleaf</name>
<packaging>jar</packaging>

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source> <!-- REQUIRED -->
<maven.compiler.target>1.8</maven.compiler.target> <!-- REQUIRED -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<failOnMissingWebXml>false</failOnMissingWebXml> <!-- REQUIRED -->
<appengine.maven.plugin>0.1.2</appengine.maven.plugin>
<!-- <jetty.maven.plugin>9.3.7.v20160115</jetty.maven.plugin> -->
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>

<prerequisites> <!-- Optional, but suggested -->
<maven>3.3.9</maven> <!-- Recommended minimum maven version -->
</prerequisites>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -91,18 +106,43 @@
<version>2.53.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
<java.version>1.8</java.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin}</version>
<configuration>
<!-- deploy configuration -->
<!--
<deploy.promote>true</deploy.promote> <!~~ DEFAULT value ~~>
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion> <!~~ DEFAULT value ~~>
-->
</configuration>
</plugin>

</plugins>
</build>

Expand Down
5 changes: 5 additions & 0 deletions src/main/appengine/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# app.yaml - configuratiebestand voor Google Cloud App Engine
#
runtime: custom
vm: true
44 changes: 44 additions & 0 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# This is the image for RaspberryPi on ARM architecture.
# See https://hub.docker.com/r/hypriot
#
# FROM hypriot/rpi-java

#
# This is the image for plain X86 machines.
#
# FROM java:8
# VOLUME /tmp
#
# The image to run the app on Google Cloud App Engine
#
FROM gcr.io/google_appengine/java-compat
VOLUME /tmp

# Install maven
# RUN apt-get update
# RUN apt-get install -y maven

# WORKDIR /code

# Warning: JAVA_HOME environment variable is not set.
# ENV JAVA_HOME /usr/java/default
# ENV PATH $PATH:$JAVA_HOME/bin

# Prepare by downloading dependencies
# ADD pom.xml *.iml /code/pom.xml
# RUN ["mvn", "dependency:resolve"]
# RUN ["mvn", "verify"]

# Adding source, compile and package into a fat jar
# ADD src /code/src
# RUN ["mvn", "clean"]
# RUN ["mvn", "compile"]
# RUN ["mvn", "package"]

ADD spring-boot-thymeleaf-1.0.jar app.jar
EXPOSE 8080
# CMD ["java", "-jar", "target/spring-boot-thymeleaf-1.0.jar"]
CMD ["java", "-jar", "/app.jar"]

# done
34 changes: 34 additions & 0 deletions src/main/resources/application-development.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# De port waar de app gaat draaien.
server.port = 8080

# Set the error path
# error.path=/error

# Hiermee zet je het globale (voor alles geldende) logging level.
# Logging voor onze eigen packages wordt ingesteld in resources/logback.xml
logging.file=myapplication.log
# logging.level.org.springframework=DEBUG
# logging.level.org.springframework.web=DEBUG

spring.datasource.url=jdbc:mysql://localhost:3306/library
spring.datasource.username=spring
spring.datasource.password=test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.thymeleaf.cache=false
spring.thymeleaf.check-template-location=true
spring.thymeleaf.summary-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

# Bol.com OpenAPI version 4 ApiKey - op naam van Robin Schellius
# Als je hier iets mee wilt doen, vraag dan je eigen code via
# https://developers.bol.com
bol.com.openapi.v4.apikey = 25C4742A92BF468EB2BD888FC8FBFF40

# de API van onze eigen server.
avans.library.bookserver.url = http://localhost:8090/api/book
34 changes: 34 additions & 0 deletions src/main/resources/application-production.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# De port waar de app gaat draaien.
server.port = 8080

# Set the error path
# error.path=/error

# Hiermee zet je het globale (voor alles geldende) logging level.
# Logging voor onze eigen packages wordt ingesteld in resources/logback.xml
logging.file=myapplication.log
# logging.level.org.springframework=DEBUG
# logging.level.org.springframework.web=DEBUG

spring.datasource.url=jdbc:mysql://localhost:3306/library
spring.datasource.username=spring
spring.datasource.password=test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.thymeleaf.cache=false
spring.thymeleaf.check-template-location=true
spring.thymeleaf.summary-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

# Bol.com OpenAPI version 4 ApiKey - op naam van Robin Schellius
# Als je hier iets mee wilt doen, vraag dan je eigen code via
# https://developers.bol.com
bol.com.openapi.v4.apikey = 25C4742A92BF468EB2BD888FC8FBFF40

# de API van onze eigen server.
avans.library.bookserver.url = http://localhost:8090/api/book
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import nl.avans.ivh5.example.springmvc.Application;
import pl.codeleak.selenium.support.SeleniumTest;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebIntegrationTest(value = "server.port=9000")
// @SpringApplicationConfiguration(classes = Application.class)
// @WebIntegrationTest(value = "server.port=9000")
@SeleniumTest(driver = FirefoxDriver.class, baseUrl = "http://localhost:9000")
public class HomeControllerTest {

Expand Down

0 comments on commit dc8f80e

Please sign in to comment.