Top Banner
@tvinke @koenusTweets @First8BV #Devoxx #grails3trek Web Application Development using Grails and Docker ` Workshop by Ted Vinke and Koen Aben First8
41

Devoxx 2015 - Web Application Development using Grails and Docker

Jan 21, 2018

Download

Technology

Ted Vinke
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Web Application Development

using Grails and Docker

`

Workshop by Ted Vinke and Koen Aben

First8

Page 2: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Who are we?

Ted Vinke@tvinke

Koen Aben@koenusTweets

First8@First8BV

Page 3: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Goal

• Get to know Grails 3 – The

Framework

• Acquire hands-on enough

practical knowledge to get

started with a project at

home or work

• Experience the Fun and Joy

of developing with Grails

Page 4: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Contents

• Overview

• Workshop

• Feedback

Page 5: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Updates & Feedback

We’d love to have some feedback afterwards!

www.first8.nl/grails3trek

Page 6: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Grails?

Page 7: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

groovy-lang.org

Page 8: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Much is optional

• Optional braces ( and )

• Optional semi-colons ;

• Less lines

• println instead of

System.out.println

Java

public static void main(String[] args) {System.out.println("Hello world!");

}

Groovy

println "Hello world!"

Page 9: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Less boilerplateParsing XML

def xmlSlurper = new XmlSlurper()

def list = xmlSlurper.parseText'''

<list>

<company>

<name>First8</name>

</company>

</list>

'''

assert

list.company.name == 'First8'

Parsing JSON

def jsonSlurper = new JsonSlurper()

def company =

jsonSlurper.parseText '{"name": "First8"}'

assert company instanceof Map

assert company.name == 'First8'

Page 10: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Duck typing

• Instead of a specific type name you can use def

• Usable instead of void in method definition

• Allows for easy tutorials, but also for "duck typing"

Java

int typed = 2

typed = "Some text"

// compiler error: type mismatch

Groovy

def dynamic = 2

dynamic = "Some text" // ok

Page 11: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

More Groovy

•Return keyword is

optional

• Classes, methods and

properties* are public by

default

• Getters and setters are

generated compile-time

Groovy

double calculateTotal(int number) {

number * 0.21

}

Groovy

class Spaceship {String nameboolean warpCapable

}

Page 12: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Groovy Closures

• Block of code; assign with curly braces { and }

Groovy

def clos = { println "Hello Duke!" }

println "Executing the Closure:"

clos() // prints "Hello Duke!"

def adder = { a, b -> print a+b }

adder(1, 2) // prints "3"

adder("m", "e") // prints "me"

with parameters

Page 13: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Lists

• Use [] expression to create a List

Java

List<Person> persons = new ArrayList<>();

persons.add(new Person());

Groovy

def persons = []

persons << new Person()

Page 14: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Maps

• Use [:] expression to create a Map

Java

Map<String, String> map = new HashMap<>();

map.put("name", "Ted");

Groovy

def map = [name:"Ted", id:1234]

assert map.get("name") == "Ted"

assert map["name"] == "Ted"

assert map.name == "Ted"

Page 15: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Groovy as-is

already rocks!

Page 16: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

grails.org

Page 17: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

“Grails is an Open Source, full stack, web

application framework for the JVM. It

takes advantage of the Groovy

programming language and convention

over configuration to provide a productive

and stream-lined development

experience.”

Page 18: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Distribution

• Latest official

release is 3.0.9

• Latest available

release is 3.1.0.M2

• We’ll be using

3.1.0.M1

For this workshop you don’t

have to download Grails.

Page 19: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Up ‘n running with Grails

1

Install JDK and

Grails

distribution

2

grails create-app MyFirstApp

3

grails run-app

Page 20: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Up ‘n running with Gradle

gradlewbootRun

grails run-app

Page 21: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Workshop Grails Trek

Page 22: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Step 1: grails-trek.zip

Extract zipped Star Trek

workshop application

from the USB stick.

You can keep it! Take your

time during the workshop –

you can always continue at

home.

Page 23: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Material

grails-trek3.zip

Eclipse Mars distributions (Win, Linux and Mac)

Docker Toolbox distributions (Win and Mac)

Documents

A - Getting Started.pdf

B - Eclipse Mars Instructions.pdf

C - Tasks in Eclipse.pdf

D - Docker Instructions.pdf

Page 24: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Step 2: Install IDE

Extract Eclipse Mars from

the USB stick. Install

some plugins and import

the Gradle project.

You can of course use Netbeans or

IntelliJ to import the project and run it with

the Gradle Wrapper, but you won’t be

able to follow the tasks easily…

Page 25: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Step 3: Tasks in Eclipse

Use the Tasks overview

to follow all assignments

in chronological order.

We’ve used the TODOs in such a

way so Eclipse can display them

nicely in chronological order.

Page 26: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Step 4: Docker

Instead of in-memory H2,

run integration test

against Postgres in

Docker container.

Windows and Mac users can install

Docker Toolbox from the USB drive.

Page 27: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Eclipse Mars

Page 28: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Eclipse Mars

Already has:

• Buildship plugin

(Gradle)

Add ourselves:

• Groovy compiler

• GSP editor

Page 29: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Eclipse Mars

• Import grails-

trek/trek as a

Gradle project

Page 30: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Eclipse Mars

• Interact with

Gradle

whenever you

have to -- with

the Gradle

Tasks view

Page 31: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Eclipse Mars

• Follow the

breadcrumbs

Page 32: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

What tasks can you encounter? (1)

Showcases of several features - just FYI

Page 33: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

What tasks can you encounter? (2)

Coding tasks - which invite you to actually implement

missing logic or fix a bug

• Solutions are present in the enclosed Git repository as tags

Page 34: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Sections

• The 40 tasks are divided in sections

• ENGINEER

• SECURITY

• PARTICLE

• MISSIONS

• AWAYTEAM

• A reference of all tasks and a FAQ can be found in the

Tasks in Eclipse PDF

Page 35: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Install & ENGINEERING

• Get the project up ‘n

running (max 10-20 min)

• Work ENGINEER tasks

• Review in 30 min

Page 36: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Review ENGINEER

1.Starting the app: bootRun

2.UrlMappings:

"/"(controller:"dashboard")

3.Use i18n messages

4.Scaffolding

5.Controller actions/views

6.Controller returning

model

7.GSP using model

8.Auto-reloading

9.404 error page

10.Groovy

Page 37: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

SECURITY

• Work SECURITY tasks

• Logging framework

• Testing with Spock

• GSP and TagLibs

• H2 and Hibernate

• Review in 30 min

Page 38: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Review SECURITY

1.Logback logging

framework

2.Testing with Spock

(UserController)

3.Groovy Expressions

4.GSP variables

5.TagLib FYI

6.TagLib impl change

7.TagLib test change

8.TagLib attributes

9.BootStrap

10.dbconsole

11.Dynamic Finders

12.PersonTagLib impl

change

Page 39: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

PARTICLE

• Work PARTICLE tasks

• Spring beans, Spring Boot Actuator

• Event processing

• Groovy class annotation

• Grails configuration

• JSON

Page 40: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Review PARTICLE

• Spring beans

instantiation & wiring

• Event processing with

Reactor

• Groovy class annotations

• Grails configuration

• JSON

• Health & metrics

Page 41: Devoxx 2015 - Web Application Development using Grails and Docker

@tvinke @koenusTweets @First8BV#Devoxx #grails3trek

Thank you

• first8.nl

• first8.nl/grails3trek

• twitter.com/First8BV

• linkedin.com/company/first8