Repository: googleforgames/global-multiplayer-demo (language: cpp)

Issue:
Authenticating, Custom Front End
The custom front end will need to authenticate all API requests and pass them through to other services in the same cluster, such as the profile service, inventory, leaderboard (?). and open match requests.


Discussion / hints:
FYI - @kennycoder pretty sure your work on #34 is covering this, yeah?
@markmandel correct :)
Awesome - just triple checking 👍🏻 
Authentication flow has been improved to be more "true to life".

Game Launcher -> Request auth url from frontend_api -> get redirected to Google's Oauth2 page -> Login -> Receive authorization_token back in frontend_api -> Request basic profile info from Google's API (most importantly the unique user ID) -> Generate our own JWT token valid for 30 days -> Store in game launcher.

Then the game launcher can open the game client providing JWT token for further comms with frontend_api (which then communicates with profile service and openmatch).

Once JWT token is expired, game launcher will prompt to auth with google account again.

I'll take on generating the oAuth client IDs with Terraform (which we can then chuck in a ConfigMap for the env vars)
Unless anyone objects, I'll next focus on getting this built in Cloud Build and Deployed using Cloud Deploy.

Fix patch:
diff --git a/infrastructure/spanner.tf b/infrastructure/spanner.tf
index 07fff7f..b015a99 100644
--- a/infrastructure/spanner.tf
+++ b/infrastructure/spanner.tf
@@ -64,9 +64,9 @@ resource "local_file" "services-profile-config" {
   content = templatefile(
     "${path.module}/files/services/profile-service-config.yaml.tpl", {
       service_email = google_service_account.spanner-sa.email
-      project_id = var.project
-      instance_id = google_spanner_instance.global-game-spanner.name
-      database_id = google_spanner_database.spanner-database.name
+      project_id    = var.project
+      instance_id   = google_spanner_instance.global-game-spanner.name
+      database_id   = google_spanner_database.spanner-database.name
   })
   filename = "${path.module}/${var.services_directory}/profile/spanner_config.yaml"
 }
diff --git a/services/cloudbuild.yaml b/services/cloudbuild.yaml
index e4e86a3..a180d69 100644
--- a/services/cloudbuild.yaml
+++ b/services/cloudbuild.yaml
@@ -27,6 +27,10 @@ steps:
     id: profile
     args: ["build", ".", "-t", "${_PROFILE_IMAGE}"]
     dir: profile
+  - name: gcr.io/cloud-builders/docker
+    id: frontend
+    args: ["build", ".", "-t", "${_FRONTEND_IMAGE}"]
+    dir: frontend
 
 #
 # Deployment
@@ -41,7 +45,7 @@ steps:
         "--delivery-pipeline", "global-game-services",
         "--skaffold-file", "skaffold.yaml",
         "--skaffold-version", "1.39",
-        "--images", "ping-discovery=${_PING_IMAGE},profile=${_PROFILE_IMAGE}",
+        "--images", "ping-discovery=${_PING_IMAGE},profile=${_PROFILE_IMAGE},frontend=${_FRONTEND_IMAGE}",
         "--region", "us-central1"
       ]
 
@@ -49,9 +53,11 @@ artifacts:
   images:
     - ${_REGISTRY}/ping-discovery
     - ${_REGISTRY}/profile
+    - ${_REGISTRY}/frontend
 substitutions:
   _PING_IMAGE: ${_REGISTRY}/ping-discovery:${BUILD_ID}
   _PROFILE_IMAGE: ${_REGISTRY}/profile:${BUILD_ID}
+  _FRONTEND_IMAGE: ${_REGISTRY}/frontend:${BUILD_ID}
   _REGISTRY: us-docker.pkg.dev/${PROJECT_ID}/global-game-images
   _RELEASE_NAME: rel-01
 options:
diff --git a/services/frontend/Dockerfile b/services/frontend/Dockerfile
index 278955c..27a182e 100644
--- a/services/frontend/Dockerfile
+++ b/services/frontend/Dockerfile
@@ -28,5 +28,7 @@ RUN CGO_ENABLED=0 go build -o /go/bin/app
 
 # Copy bin into our base image.
 FROM gcr.io/distroless/static-debian11
+
+ENV GIN_MODE=release
 COPY --from=build /go/bin/app /
 CMD ["/app"]
diff --git a/services/frontend/deployment.yaml b/services/frontend/deployment.yaml
new file mode 100644
index 0000000..d63c9ff
--- /dev/null
+++ b/services/frontend/deployment.yaml
@@ -0,0 +1,48 @@
+# Copyright 2023 Google LLC All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: frontend
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: frontend
+  template:
+    metadata:
+      labels:
+        app: frontend
+    spec:
+      containers:
+        - name: frontend
+          image: frontend
+          ports:
+            - containerPort: 8080
+          envFrom:
+            - configMapRef:
+                name: frontend-service
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: frontend
+spec:
+  type: LoadBalancer
+  selector:
+    app: frontend
+  ports:
+    - port: 80
+      targetPort: 8080
diff --git a/services/skaffold.yaml b/services/skaffold.yaml
index 54b354e..0e47017 100644
--- a/services/skaffold.yaml
+++ b/services/skaffold.yaml
@@ -21,4 +21,5 @@ deploy:
       - ping-discovery/deployment.yaml
       - profile/spanner_config.yaml
       - profile/deployment.yaml
+      - frontend/deployment.yaml
       - frontend/configmap.yaml


Test patch: