Skip to content

Commit

Permalink
#45 Fixing links between components
Browse files Browse the repository at this point in the history
  • Loading branch information
wpernath committed Feb 15, 2023
1 parent 4939dd6 commit 7ae3f43
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 12 deletions.
2 changes: 1 addition & 1 deletion kubernetes-config/base/client-depl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
app.openshift.io/connects-to: '[{"apiVersion":"apps/v1","kind":"Deployment","name":"cat-server"}]'
app.openshift.io/connects-to: '[{"apiVersion":"apps/v1","kind":"Deployment","name":"cat-server"}, {"apiVersion":"apps/v1","kind":"Deployment","name":"cat-multiplayer"}]'
app.openshift.io/route-disabled: "false"
labels:
app: cat-client
Expand Down
6 changes: 5 additions & 1 deletion kubernetes-config/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ kind: Kustomization

resources:
- ns.yaml
- kafka-broker.yaml
- postgresql.yaml
- deployment.yaml
- service.yaml
- route.yaml
- client-depl.yaml
- client-route.yaml
- client-service.yaml
- kafka-broker.yaml
- kafka-topic.yaml
- mp-depl.yaml
- mp-service.yaml
- mp-route.yaml

99 changes: 99 additions & 0 deletions kubernetes-config/base/mp-depl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
app.openshift.io/connects-to: "[{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\"\
,\"name\":\"grumpy-kafka-entity-operator\"},{\"apiVersion\":\"apps/v1\",\"kind\"\
:\"StatefulSet\",\"name\":\"cat-repo-host\"}]"
app.openshift.io/route-disabled: "false"
app.quarkus.io/commit-id: 4939dd6eec0b157aff443a1fe5684c07625094c8
app.quarkus.io/build-timestamp: 2023-02-10 - 10:27:11 +0000
prometheus.io/scrape: "true"
prometheus.io/path: /q/metrics
prometheus.io/port: "8080"
prometheus.io/scheme: http
labels:
app: cat-multiplayer
app.kubernetes.io/component: cat-multiplayer
app.kubernetes.io/instance: cat-multiplayer
app.kubernetes.io/name: cat-multiplayer
app.kubernetes.io/part-of: grumpycat-app
app.kubernetes.io/version: 0.7.0
name: cat-multiplayer
spec:
replicas: 1
selector:
matchLabels:
app: cat-multiplayer
app.kubernetes.io/name: cat-multiplayer
app.kubernetes.io/version: 0.7.0
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations:
app.quarkus.io/commit-id: 4939dd6eec0b157aff443a1fe5684c07625094c8
app.quarkus.io/build-timestamp: 2023-02-10 - 10:27:11 +0000
prometheus.io/scrape: "true"
prometheus.io/path: /q/metrics
prometheus.io/port: "8080"
prometheus.io/scheme: http
labels:
app: cat-multiplayer
app.kubernetes.io/name: cat-multiplayer
app.kubernetes.io/version: 0.7.0
spec:
containers:
- envFrom:
- prefix: DB_
secretRef:
name: cat-pguser-cat
- configMapRef:
name: multiplayer-config
image: quay.io/wpernath/cat-multiplayer:v0.7.0
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
httpGet:
path: /q/health/live
port: 8080
scheme: HTTP
initialDelaySeconds: 0
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
name: cat-multiplayer
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /q/health/ready
port: 8080
scheme: HTTP
initialDelaySeconds: 0
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
resources:
limits:
cpu: 1000m
memory: 1024Mi
requests:
cpu: 100m
memory: 512Mi
startupProbe:
failureThreshold: 3
httpGet:
path: /q/health/started
port: 8080
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
25 changes: 25 additions & 0 deletions kubernetes-config/base/mp-route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
annotations:
app.openshift.io/connects-to: "[{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\"\
,\"name\":\"grumpy-kafka-entity-operator\"},{\"apiVersion\":\"apps/v1\",\"kind\"\
:\"StatefulSet\",\"name\":\"cat-repo-host\"}]"
app.quarkus.io/commit-id: 4939dd6eec0b157aff443a1fe5684c07625094c8
app.quarkus.io/build-timestamp: 2023-02-10 - 10:27:11 +0000
labels:
app: cat-multiplayer
app.kubernetes.io/component: cat-multiplayer
app.kubernetes.io/instance: cat-multiplayer
app.kubernetes.io/name: cat-multiplayer
app.kubernetes.io/part-of: grumpycat-app
app.kubernetes.io/version: 0.7.0
name: cat-multiplayer
spec:
port:
targetPort: 8080-tcp
to:
kind: Service
name: cat-multiplayer
weight: 100
wildcardPolicy: None
37 changes: 37 additions & 0 deletions kubernetes-config/base/mp-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: v1
kind: Service
metadata:
annotations:
app.openshift.io/connects-to: "[{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\"\
,\"name\":\"grumpy-kafka-entity-operator\"},{\"apiVersion\":\"apps/v1\",\"kind\"\
:\"StatefulSet\",\"name\":\"cat-repo-host\"}]"
app.quarkus.io/commit-id: 4939dd6eec0b157aff443a1fe5684c07625094c8
app.quarkus.io/build-timestamp: 2023-02-10 - 10:27:11 +0000
prometheus.io/scrape: "true"
prometheus.io/path: /q/metrics
prometheus.io/port: "8080"
prometheus.io/scheme: http
labels:
app: cat-multiplayer
app.kubernetes.io/component: cat-multiplayer
app.kubernetes.io/instance: cat-multiplayer
app.kubernetes.io/name: cat-multiplayer
app.kubernetes.io/part-of: grumpycat-app
app.kubernetes.io/version: 0.7.0
name: cat-multiplayer
spec:
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: cat-multiplayer
app.kubernetes.io/name: cat-multiplayer
app.kubernetes.io/version: 0.7.0
sessionAffinity: None
type: ClusterIP
14 changes: 12 additions & 2 deletions kubernetes-config/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ images:
# generate a configmap
configMapGenerator:
# Cat - Client ConfigMap, note that the client app runs entirely on the browser,
# so we need to use the external URL of the grumpycat server service
# so we need to use the external URL of the grumpycat server and multiplayer server service
#
# NOTE: This will automatically be read from client config map
- name: client-config
literals:
- APPLICATION_BASESERVERURL=http://cat-server-grumpycat.apps.cat.ocp.lan/
# Grumpycat Server configmap, just point to the internal service name of the kafka service
- APPLICATION_BASEMULTIPLAYERSERVERURL=http://cat-multiplayer-grumpycat.apps.cat.ocp.lan/

# GrumpyCat Server configmap, just point to the internal service name of the kafka service
- name: server-config
literals:
- KAFKA_BOOTSTRAP_SERVERS=grumpy-kafka-kafka-bootstrap:9092

# GrumpyCat Multiplayer Server config map
- name: multiplayer-config
literals:
- INFINISPAN_SERVER=paul
- INFINISPAN_USER=kuhn
- INFINISPAN_PASS=karl
4 changes: 4 additions & 0 deletions melonjs-client/src/main/client/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const CONFIG = {
appVersion: "{{applicationVersion}}",

baseURL: "",
baseMPURL: "",

// if we are running in development, we are going to use a
// baseURL from local settings.
Expand All @@ -14,13 +15,16 @@ const CONFIG = {
// Use a real IP address if you want to do multiplayer testing
baseURL: "http://192.168.2.198:8080/",
//baseURL: "http://192.168.2.171:8080/",

baseMPURL: "http://192.168.2.198:8086/",
},

// use this one for the quarkus engine on production systems
// {{baseURL}} will be replaced with the corresponding
// ENVIRONMENT parameter, provided via ConfigMap
prod: {
baseURL: "{{baseURL}}",
baseMPURL: "{{baseMPURL}}",
},
};

Expand Down
13 changes: 10 additions & 3 deletions melonjs-client/src/main/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ device.onReady(() => {
}

let baseURL;
let baseMPURL;

if (environment === "local") baseURL = CONFIG.local.baseURL;
else if (environment === "prod") baseURL = CONFIG.prod.baseURL;

if (environment === "local") {
baseURL = CONFIG.local.baseURL;
baseMPURL = CONFIG.local.baseMPURL;
}
else if (environment === "prod") {
baseURL = CONFIG.prod.baseURL;
baseMPURL= CONFIG.prod.baseMPURL;
}
loader.setBaseURL("tmx", baseURL);
CONFIG.baseURL = baseURL;
CONFIG.baseMPURL = baseMPURL;

loader.crossOrigin = "anonymous";

Expand Down
11 changes: 11 additions & 0 deletions melonjs-client/src/main/client/js/stage/title-back.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export default class TitleBackground extends Container {
});
this.subVersionText.pos.x = this.titleText.pos.x + 40;

this.multiVersionText = new BitmapText(126, 200, {
font: "12Outline",
size: "1",
fillStyle: "white",
textAlign: "left",
text: "Multiplayer API: " + GlobalGameState.globalServerVersion.appName + "@" + GlobalGameState.globalServerVersion.appVersion + " at " + CONFIG.baseMPURL,
offScreenCanvas: false,
});
this.multiVersionText.pos.x = this.titleText.pos.x + 40;

// add to the world container
this.addChild(this.backgroundImage, 0);
this.addChild(this.catLeftImage, 5);
Expand All @@ -107,6 +117,7 @@ export default class TitleBackground extends Container {

this.addChild(this.subTitleText,5 );
this.addChild(this.subVersionText, 5);
this.addChild(this.multiVersionText, 5);

this.addChild( new TextScroller(
"QUARKUS GRUMPYCAT. A GAME WRITTEN BY WANJA PERNATH, INSPIRED BY FAT CAT AND PAC MAN. THIS GAME IS USING A QUARKUS BACKEND TO LOAD AND STORE DATA FROM/TO A SERVER................................"
Expand Down
3 changes: 3 additions & 0 deletions melonjs-client/src/main/client/js/util/global-game-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const GlobalGameState = {
globalServerGame: null,
globalServerVersion: null,

// global multiplayer version
globalMultiplayerVersion: null,

// For replaying an allready played game
gameToReplay: null,
replayActions: null,
Expand Down
5 changes: 3 additions & 2 deletions melonjs-client/src/main/client/js/util/multiplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ export class MultiplayerMessage {
}

constructor() {
let baseURL = CONFIG.baseURL;

let baseURL = CONFIG.baseMPURL;
console.log("Base URL for Multiplayer: " + baseURL);

this.networkManager = NetworkManager.getInstance();
this.levelManager = LevelManager.getInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class ClientRenderResource {
@ConfigProperty(name = "application.baseServerURL")
String baseURL;

@ConfigProperty(name = "application.baseMultiplayerServerURL")
String baseMPURL;

@ConfigProperty(name = "quarkus.application.name")
String appName;

Expand All @@ -45,6 +48,7 @@ void init() throws IOException {

line = sb.toString();
this.rewrittenBundle = line.replaceAll("\\{\\{baseURL\\}\\}", baseURL)
.replaceAll("\\{\\{baseMPURL\\}\\}", baseMPURL)
.replaceAll("\\{\\{applicationName\\}\\}", appName)
.replaceAll("\\{\\{applicationVersion\\}\\}", appVersion);

Expand Down
2 changes: 1 addition & 1 deletion melonjs-client/src/main/kubernetes/kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
app.openshift.io/connects-to: '[{"apiVersion":"apps/v1","kind":"Deployment","name":"cat-server"}]'
app.openshift.io/connects-to: '[{"apiVersion":"apps/v1","kind":"Deployment","name":"cat-server"}, {"apiVersion":"apps/v1","kind":"Deployment","name":"cat-multiplayer"}]'
app.openshift.io/route-disabled: "false"
labels:
app: cat-client
Expand Down
3 changes: 2 additions & 1 deletion melonjs-client/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ quarkus.http.port=8088
application.version=v${quarkus.application.version}

# BaseURL to be injected into /config.js via Qute
application.baseServerURL=http://localhost:8080/
application.baseServerURL=http://localhost:8080/
application.baseMultiplayerServerURL=http://localhost:8086/
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.wanja.fatcat.mp;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("/")
public class VersionService {
@ConfigProperty(name = "application.version")
String versionString;

@ConfigProperty(name = "quarkus.application.name")
String appName;

@GET
@Path("/version")
// @Produces("text/plain")
public AppVersion version() {
return new AppVersion("grumpycat-server", this.appName, this.versionString);
}

final class AppVersion {
public String appName;
public String internalName;
public String appVersion;

public AppVersion() {
}

public AppVersion(String n, String i, String v) {
this.appName = n;
this.appVersion = v;
this.internalName = i;
}
}

}
2 changes: 1 addition & 1 deletion quarkus-multiplayer/src/main/kubernetes/kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
name: cat-pguser-cat
prefix: DB_
- configMapRef:
name: server-config
name: multiplayer-config
ports:
- containerPort: 8080
protocol: TCP
Expand Down
Loading

0 comments on commit 7ae3f43

Please sign in to comment.