Skip to content

Commit

Permalink
Linux Game Build -> Remote Client VM (#237)
Browse files Browse the repository at this point in the history
* Linux Game Build -> Remote Client VM

This PR connects the new Remote Client VM to the automated linux build
of the game client.

This also includes a variety of improvements and fixes to the Remote
Client VM setup and implementation, including:

* Tweaks to Terraform config
* Update to documentation.
* Cleaning up installation script to remove options.
* Removing cinnamon (single WM).
* Installing Nvidia vst drivers.
* Script for downloading the latest client
* Stop rebuild of vm on terraform apply

* Added escapes to clone-unreal-engine cloudbuild

---------

Co-authored-by: Andrew Marcum <[email protected]>
  • Loading branch information
markmandel and abmarcum authored Mar 3, 2024
1 parent aba5cd6 commit b5465e8
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 127 deletions.
94 changes: 68 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dedicated game servers, utilising both Google Cloud's products and open source g
If you’re using this demo, please **★Star** this repository to show your interest!

**Note to Googlers**: Please fill out the form at [go/global-scale-game-form](http://go/global-scale-game-form).
Details of the program can be found at [go/global-scale-game](http://go/global-scale-game).
Details of the program can be found at [go/global-scale-game].

Projects and products utilised include:

Expand Down Expand Up @@ -287,6 +287,69 @@ the file and `unzip` it locally.
Run `launcher` to run the Game Launcher, and see [Playing The Game](#playing-the-game) for details on how to play the
game once the launcher is up and running.

### Enable Remote Cloud Game Client VM

Since not everyone has a Linux machine with a graphics card - we've supplied one for you in the Cloud, which can run
our automated Linux build of the game launcher and client!

To enable the VM for the Game Client, make sure to set `enable_game_client_vm = true` in the `terraform.tfvars`,
and `terraform apply` those changes.

Once Terraform has run and the VM has successfully rebooted after all the software has installed, SSH into the VM
using gcloud (or the [Cloud Console](https://console.cloud.google.com/compute/instances)) for first time setup with
[Chrome Remote Desktop](https://remotedesktop.google.com/).

```shell
gcloud compute ssh game-client-vm
```

To determine if the setup scripts are complete, running
[`nvidia-smi`](https://developer.nvidia.com/nvidia-system-management-interface) will complete successfully.

The first time you use the service, you will need to configure the Game Client VM
by [Setting up via SSH](https://remotedesktop.google.com/headless).

**Note to Googlers**: Check [go/global-scale-game] for special instructions on setting up Chrome Remote Desktop for
the Game Client VM.

Click through the buttons Begin -> Next -> Authorize (skip installing the deb, we already did that) to get to
the screen where you can then copy the commands for `Debian Linux`.

Paste these commands into the SSH terminal you have open to the Game Client VM. After the commands have been
successfully run, you can return to [Chrome Remote Desktop](https://remotedesktop.google.com/access) and click on the
Game Client VM that should now be displayed.

If Chrome Remote Desktop is an issue for you, we have also installed several other (but less tested) remoting solutions
into the VM, including:

* [TightVNC](https://www.tightvnc.com/)
* [Xpra](https://xpra.org/)
* [Sunshine](https://app.lizardbyte.dev/Sunshine/)
* [xrdp](https://www.xrdp.org/)

#### Downloading the latest client

On first connection to the remote machine, you will need to download the latest client. To do so, open a terminal and
run:

```shell
/opt/game-client/update-client.sh
```

Which will download the latest DroidShooter Client to the Desktop of this machine.

If you ever want to update the client to the latest build, run the same command again.

#### Running the Launcher

After remoting into the Game Cloud Game Client VM, open the `Client` folder on the Desktop, and double-click the
`launcher` to run the game launcher.

**Note:** When using Chrome Remote Desktop, you may want to enable "Relative Mouse Mode" via the sidebar, when playing
the game for better mouse interaction with the game client (hit `Esc` to exit Relative Mouse Mode).

See [Playing The Game](#playing-the-game) for details on how to play the game once the launcher is up and running.

### Editing or Building the Game Locally

To build the Game Client for your host machine, you will need to
Expand All @@ -297,7 +360,7 @@ This project currently uses **Unreal Engine 5.2.0**.

> Installing Unreal Engine from source can take several hours, and use all your CPU. You have been warned!
Open [`game/Droidshooter.uproject`](./game) in the Unreal Engine Editor.
Open [`game/Droidshooter.uproject`](./game) in the Unreal Engine Editor.

To package the project:

Expand All @@ -317,30 +380,7 @@ gcloud compute addresses list --filter=name=frontend-service --format="value(add

JWT token can be obtained by accessing frontend api's ip address with '/login' path, such as "http://[IP_ADDRESS].sslip.io/login" and extracting it from the URL.

### Enable Cloud Linux VM for Game Client

You have the option to enable a GCP Linux VM for the Game Client. To have Terraform setup the VM, edit `terraform.tfvars` and set:

`enable_game_client_vm = true`

Then you will need to run Terraform to apply the changes to your environment:

```shell
terraform apply
```

Once Terraform has run and a few minutes have passed for all of the software packages to install, you can then connect to the VM using gcloud:

```shell
gcloud compute ssh game-client-vm
```

You can also connect to an X display using [Chrome Remote Desktop](https://remotedesktop.google.com/).
The first time you use the service, you will need to configure the Game Client VM by [Setting up via SSH](https://remotedesktop.google.com/headless)

You can click through the buttons Begin -> Next -> Authorize to get to the screen where you can then copy the commands for `Debian Linux`. Then you can paste these commands into the SSH terminal you have open to the Game Client VM. After the commands have been succesfully run, you can return to [Chrome Remote Desktop](https://remotedesktop.google.com/access) and click on the Game Client VM that should now be displayed.

### Run the Game Launcher
#### Run the Game Launcher from source

To run the game launcher, you will need to have [Go](https://go.dev/dl/) installed to run it, as well as the
[prerequisites for the Fyne Go Cross Platform UI library](https://developer.fyne.io/started/).
Expand Down Expand Up @@ -389,3 +429,5 @@ The project should open as normal now.
Apache 2.0

This is not an officially supported Google product

[go/global-scale-game]: http://go/global-scale-game
6 changes: 3 additions & 3 deletions game/unreal-engine/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ steps:
- name: gcr.io/cloud-builders/git
id: clone-unreal-engine
script: |
df -h
git clone --depth=1 --single-branch --branch "$_UNREAL_VERSION-release" https://[email protected]/EpicGames/UnrealEngine.git
cd UnrealEngine
df -h && \
git clone --depth=1 --single-branch --branch "$_UNREAL_VERSION-release" https://[email protected]/EpicGames/UnrealEngine.git && \
cd UnrealEngine && \
ls -l
secretEnv:
- GITHUB_AUTH
Expand Down
6 changes: 6 additions & 0 deletions infrastructure/client.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ resource "google_storage_bucket" "release-artifacts" {
location = "US"
name = "${var.project}-release-artifacts"
}

resource "google_storage_bucket_object" "update-client" {
name = "update-client.sh"
bucket = google_storage_bucket.release-artifacts.name
source = "./files/update-client.sh"
}
101 changes: 101 additions & 0 deletions infrastructure/files/game-client-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

#
# Copyright 2024 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.
#

# Script to install applications for the Game Client VM

# Credits
# https://cloud.google.com/architecture/chrome-desktop-remote-on-compute-engine
# https://cloud.google.com/compute/docs/gpus/install-grid-drivers#debianubuntu

set -euxo pipefail

export DEBIAN_FRONTEND=noninteractive

# if we've already run this script, exit successfully
if [ -f /opt/game-client/init.lock ]; then
echo "Remote Game Client VM startup script already ran - exiting"
exit 0
fi

# Latest version of Xpra
sudo wget -O "/usr/share/keyrings/xpra.asc" https://xpra.org/xpra.asc
cd /etc/apt/sources.list.d
sudo wget https://raw.githubusercontent.com/Xpra-org/xpra/master/packaging/repos/bookworm/xpra.sources
sudo apt-get update --assume-yes
cd -

# Installs:
# * xfce4 desktop environment
# * remoting libraries
# * graphics support and utilities
# * general handy utilities
sudo apt-get install --assume-yes \
xfce4 desktop-base dbus-x11 xscreensaver \
tightvncserver xrdp xpra \
build-essential "linux-headers-$(uname -r)" mesa-utils \
less bzip2 zip unzip tasksel wget

# Chrome Remote Desktop session
sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" > /etc/chrome-remote-desktop-session'

# Install Nvidia Virtual Workstation Drivers
curl -O https://storage.googleapis.com/nvidia-drivers-us-public/GRID/vGPU16.4/NVIDIA-Linux-x86_64-535.161.07-grid.run
sudo bash NVIDIA-Linux-x86_64-535.161.07-grid.run --silent

# Disable GSP Firmware
echo "options nvidia NVreg_EnableGpuFirmware=0" | sudo tee /etc/modprobe.d/nvidia.conf

function download_and_install { # args URL FILENAME
curl -L -o "$2" "$1"
sudo apt-get install --assume-yes --fix-broken "$2"
}

function is_installed { # args PACKAGE_NAME
dpkg-query --list "$1" | grep -q "^ii" 2>/dev/null
return $?
}

! is_installed sunshine && \
download_and_install \
https://github.com/LizardByte/Sunshine/releases/download/v0.21.0/sunshine-debian-bookworm-amd64.deb \
/tmp/sunshine-debian-bookworm-amd64.deb

! is_installed chrome-remote-desktop && \
download_and_install \
https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb \
/tmp/chrome-remote-desktop_current_amd64.deb

! is_installed google-chrome-stable && \
download_and_install \
https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
/tmp/google-chrome-stable_current_amd64.deb

# Write lock file, to stop this file rerunning, and Terraform recreating the VM if the script gets deleted.
sudo mkdir /opt/game-client
sudo touch /opt/game-client/init.lock

# Grab the script that will pull down the latest Client.
project=$(curl http://metadata.google.internal/computeMetadata/v1/project/project-id -H Metadata-Flavor:Google)
storage_bucket="gs://$project-release-artifacts"

sudo gsutil cp "$storage_bucket/update-client.sh" /opt/game-client/update-client.sh
sudo chmod o+x /opt/game-client/update-client.sh

# Rebooting to disable GSP Firmware because Nvidia says so.
echo "Remote Game Client VM startup script completed - rebooting"
sudo reboot
31 changes: 31 additions & 0 deletions infrastructure/files/update-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

#
# Copyright 2024 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.
#

# Script to download and update the Game Client for Google Cloud Storage

set -euxo pipefail

project=$(curl http://metadata.google.internal/computeMetadata/v1/project/project-id -H Metadata-Flavor:Google)
storage_bucket="gs://$project-release-artifacts"
latest_client=$(gsutil ls -l "$storage_bucket/*.zip" | sort -k 2 -r | head -n 2 | tail -n 1 | awk '{print $3}')

mkdir -p ~/Desktop/Client || true

gsutil cp "$latest_client" ~/Desktop/Client/Client.zip
cd ~/Desktop/Client/
unzip Client.zip
95 changes: 0 additions & 95 deletions infrastructure/game-client-startup.sh

This file was deleted.

Loading

0 comments on commit b5465e8

Please sign in to comment.