Wir implementieren "Rock, Paper, Scissors" als Cloud-Anwendung. Das Frontend stellen wir, ihr implementiert das Backend gegen eine vorhandene REST API Definition. Dazu nutzt ihr entweder Go (betreut von Jan Stamer) oder Java (betreut von Lena Grimm). Zum Abschluss tauschen wir die gewonnenen Erfahrungen in einer Fishbowl Session aus.
Die "Rock, Paper, Scissors"-Anwendung fängt klein an wird immer weiter ausgebaut:
Stufe 1: Einfache REST API, über die gegen den Computer gespielt wird. Das Backend wird von Beginn an cloud-native aufgesetzt, gemäß den 12 Prinzipien der "Twelve-Factor-App".
Stufe 2: Wir erstellen ein Spiel, das wir per Link mit einem anderen Spieler teilen. Dazu muss das Backend die laufenden Spiele verwalten. Wir fangen an und halten die Spiele im Hauptspeicher. Danach persistieren wir die Spiele in einer Datenbank. Die Verwaltung der Spiele muss skalierbar und auf den Betrieb in dynamischen Cloud-Umgebungen eingestellt sein.
Stufe 3: Wer noch mehr schafft, kann in Echtzeit gegen andere spielen und bspw. ein Leaderboard mit Highscores umsetzen.
3. The Plan
Build a RESTful API forRock, Paper, Scissors
Learn more about Go and Spring
Learn cloud-native Development
#
#
#
4. How?
2 Sessions: Go and Spring
Collaborative programming of the API
Frontend is provided
You may workin groups
Successive fishbowl fordiscussing results
#
#
#
#
#
15. Prerequisites Go Session
Editor
Clone ,
checkout branch go-start
Go
optional: forhot reload
go install github.com/cosmtrek/air@latest
Frontend
# Visual Studio Code
# Postman
# github.com/crossnative/cloudland-rps
# Go Compiler
# air
# Node.js
16. First Steps in Go
1. Get up and running
2. Complete REST API
3. oradd
Make Cloud Native yourFeatures
17. Go Cloud Native Path
...
# Configure Port from
Environment Variable
# Handle Errors properly
# Middleware forLogging
and Recovery
# Add a Health Check
# Run in Container
# Use PostgreSQL for
Storage
# Deploy to the cloud
# Add OpenTelemetry
#
18. Cheatsheet Middleware forLogging
and Recovery
Using middlewares from chi routerorothers.
What does the recovery middleware do?
Bonus: How can you set a request timeout using
middleware?
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
#
#
19. Cheatsheet Configure Port
from Environment Variable
Using the Standard Library
Using envconfig
github.com/kelseyhightower/envconfig
func main() {
http.ListenAndServe(fmt.Sprintf(":%v", os.Getenv("PORT")), r)
}
// Application Configuration
type Config struct {
Port string `envconfig:"PORT" default:"8080"`
}
func main() {
http.ListenAndServe(fmt.Sprintf(":%v", c.Port), r)
}
20. Cheatsheet Handle Errors properly
Using the Standard Library
Using Problem forHTTPAPIs
Use with schneider.vip/problem
if err != nil {
http.Error(w, "Oops, that went wrong!", http.StatusInternalServerError)
return
}
rfc7807
if err != nil {
problem.New(
problem.Wrap(err),
problem.Status(http.StatusInternalServerError)
).WriteTo(w)
return
}
21. Cheatsheet Run in Container
# 1. RPS Builder
FROM golang as builder
WORKDIR /app
ADD . /app
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o build/rps .
# 2. RPS Container
FROM gcr.io/distroless/static
COPY --from=builder /app/build/rps /usr/bin/
EXPOSE 8080
ENTRYPOINT ["/usr/bin/rps"]
22. Cheatsheet Add a Health Check
See github.com/hellofresh/health-go/v5.
// Register Health Check
h, _ := health.New(health.WithChecks(
health.Config{
Name: "db",
Timeout: time.Second * 2,
SkipOnErr: false,
Check: healthPgx.New(healthPgx.Config{
DSN: config.Db,
}),
},
))
// Register Health Check Handler Function
r.Get("/health", h.HandlerFunc)
23. Cheatsheet Use PostgreSQL for
Storage
Sample application
# SQL Tutorial with Go
# PostgreSQL DriverPGX
# offer
24. Cheatsheet Cloud Deployment
Example Deployment forrender
services:
- type: web
name: backend-go
env: go
plan: free
rootDir: backend-go
buildCommand: go build -o rps .
startCommand: ./rps
27. Prerequisites Spring Session
Install some IDE (e.g. or )
Install
Install Java JDK(e.g. )
Clone and checkout branch
spring-start
Frontend
(npm is included)
# IntelliJ Visual Studio Code
# Postman
# Temurin
# github.com/crossnative/cloudland-rps
# Node.js
28. First Steps Spring Session
1. Run local Frontend togetherwith example backend
https://backend-spring.onrender.com/api/v1
2. Build and Run Spring Backend
3. Implement REST API
4. oradd
Make Cloud Native furtherFeatures
29. Spring Cloud Native Path
...
# Configurable
Application Port
# Improve ErrorHandling
# Configure proper
Logging
# Health Check
# Run in Container
# Use Database for
persistence
# Deploy to the Cloud
# Add OpenTelemetry
#
31. Cheatsheet Run in Container
With Buildpacks run
./mvnw spring-boot:build-image -Dspring-
boot.build-image.imageName=myorg/myapp
# Spring Official Guide
# Baeldung: Dockerizing a Spring Boot Application
32. Feature Ideas Rock, Paper, Scissors
Add a leaderboard with top 10 Players
Make Game realtime (e.g. WebSocket, ...)
Enhance to
Add rooms people can play many Games in
...
#
#
# Rock, Paper, Scissors, Spock, Lizard
#
#
33. Interesting Links
# The Twelve FactorApp
# Beyond the Twelve FactorApp
# Cloud-native entwickeln mit Go
# Building a MultiplayerGame with API
Gateway+Websockets, Go and DynamoDB
34. Jan Stamer
Lena Grimm
Fynn JasparStempel
jan.stamer@crossnative.com
lena.grimm@crossnative.com
fynn.jaspar.stempel@crossnative.com