agones.dev/agones@v1.54.0/examples/nodejs-simple/README.md (about) 1 # Simple node.js Example 2 3 This is a very simple "server" that doesn't do much other than show how the SDK works in node.js. 4 5 It will: 6 - Set up the Agones SDK and connect to the SDK-server 7 - Add a watch to display status updates from the SDK-server 8 - Set labels, annotations 9 - Manage a fake lifecycle from `Ready` through `Allocated` and `Reserved` 10 - Every 10 seconds, write a log showing how long it has been running for 11 - Every 20 seconds, mark as healthy 12 - After the shutdown duration (default 60 seconds), shut the server down 13 - Parse options to get help or set the shutdown timeout duration 14 15 If alpha features are enabled it will additionally: 16 - Set and get the player capacity (this is not enforced) 17 - Add, get and remove players, and test if they are present 18 19 To learn how to deploy this example service to GKE, please see the tutorial [Build and Run a Simple Gameserver (node.js)](https://agones.dev/site/docs/tutorials/simple-gameserver-nodejs/). 20 21 ## Building 22 23 If you want to modify the source code and/or build an updated container image, run `make build` from this directory. 24 This will run the `docker build` command with the correct context. 25 26 This example uses a Docker container to host the SDK and example it inside a container so that no special build 27 tools need to be installed on your system. 28 29 ## Testing locally with Docker 30 31 If you want to run the example locally, you need to start an instance of the SDK-server. To run an SDK-server for 32 120 seconds, run 33 ```bash 34 $ cd ../../build; make run-sdk-conformance-local TIMEOUT=120 TESTS=ready,watch,health,gameserver 35 ``` 36 37 In a separate terminal, while the SDK-server is still running, build and start a container with the example gameserver: 38 ```bash 39 $ make build 40 $ make run 41 ``` 42 43 The example can also be run via docker: 44 ``` 45 $ docker run --network=host us-docker.pkg.dev/agones-images/examples/nodejs-simple-server:0.10 46 ``` 47 Or directly via npm: 48 ``` 49 $ npm start 50 ``` 51 52 You will see the output like the following: 53 ``` 54 docker run --network=host us-docker.pkg.dev/agones-images/examples/nodejs-simple-server:0.10 55 56 > @ start /home/server/examples/nodejs-simple 57 > node src/index.js 58 59 Connecting to the SDK server... 60 ...connected to SDK server 61 ``` 62 63 To see help, pass `--help` as the argument (use the preferred command below, all are equivalent): 64 ``` 65 $ make args="--help" run 66 $ docker run --network=host us-docker.pkg.dev/agones-images/examples/nodejs-simple-server:0.10 --help 67 $ npm start -- --help 68 ``` 69 70 You can optionally specify how long the server will stay up once the basic tests are complete with the `--timeout` option. 71 To do this pass arguments through, e.g. to increase the shutdown duration to 120 seconds: 72 ``` 73 $ make args="--timeout=120" run 74 $ docker run --network=host us-docker.pkg.dev/agones-images/examples/nodejs-simple-server:0.10 --timeout=120 75 $ npm start -- --timeout=120 76 ``` 77 78 To make run indefinitely use the special timeout value of 0: 79 ``` 80 $ make args="--timeout=0" run 81 $ docker run --network=host us-docker.pkg.dev/agones-images/examples/nodejs-simple-server:0.10 --timeout=0 82 $ npm start -- --timeout=0 83 ``` 84 85 To enable alpha features ensure the feature gate is enabled: 86 ```bash 87 $ cd ../../build; make run-sdk-conformance-local TIMEOUT=120 FEATURE_GATES="PlayerTracking=true" TESTS=ready,watch,health,gameserver 88 ``` 89 90 Then enable the alpha suite: 91 ``` 92 $ make args="--alpha" run 93 $ docker run --network=host us-docker.pkg.dev/agones-images/examples/nodejs-simple-server:0.10 --alpha 94 $ npm start -- --alpha 95 ```