agones.dev/agones@v1.53.0/examples/rust-simple/README.md (about)

     1  # Simple Rust Example
     2  
     3  This is a very simple "server" that doesn't do much other than show how the SDK works in Rust.
     4  
     5  It will
     6  - Setup the Agones SDK
     7  - Call `SDK::Ready()` to register that it is ready with Agones.
     8  - Every 10 seconds, write a log saying "Hi! I'm a Game Server"
     9  - After 60 seconds, call `SDK::Shutdown()` to shut the server down.
    10  
    11  To learn how to deploy this example service to GKE, please see the tutorial [Build and Run a Simple Gameserver (Rust)](https://agones.dev/site/docs/tutorials/simple-gameserver-rust/).
    12  
    13  ## Building
    14  
    15  If you have a local rust developer environment installed locally, you can run `make build-server` to compile the code and
    16  `make run` to execute the resulting binary.
    17  
    18  If you want to build an updated container image or want to build the source code without installing the rust developer
    19  tools locally, run `make build-image` to run the `docker build` command with the correct context.
    20  
    21  This example uses the [Docker builder pattern](https://docs.docker.com/develop/develop-images/multistage-build/) to
    22  build the SDK, example and host it inside a container.
    23  
    24  ## Testing locally with Docker
    25  
    26  If you want to run the example locally, you need to start an instance of the SDK-server. To run an SDK-server for
    27  120 seconds, run
    28  ```bash
    29  $ cd ../../build; make run-sdk-conformance-local TIMEOUT=120 TESTS=ready,watch,health,gameserver
    30  ```
    31  
    32  In a separate terminal, while the SDK-server is still running, build and start a container with the example gameserver:
    33  ```bash
    34  $ make build-image
    35  $ make run-image
    36  ```
    37  
    38  You will see the following output:
    39  ```
    40  docker run --network=host us-docker.pkg.dev/agones-images/examples/rust-simple-server:0.13
    41  Rust Game Server has started!
    42  Creating SDK instance
    43  Setting a label
    44  Starting to watch GameServer updates...
    45  Health ping sent
    46  Setting an annotation
    47  GameServer Update, name: local
    48  GameServer Update, state: Ready
    49  Marking server as ready...
    50  ...marked Ready
    51  Getting GameServer details...
    52  GameServer name: local
    53  Running for 0 seconds
    54  Health ping sent
    55  Health ping sent
    56  Health ping sent
    57  Health ping sent
    58  Running for 10 seconds
    59  ```
    60  
    61  When you are finished, clean up the `sdk` directory:
    62  ```
    63  make clean-docker
    64  ```
    65  
    66  ## Testing locally (without Docker)
    67  
    68  If you want to run the example locally, you need to start an instance of the SDK-server. To run an SDK-server for
    69  120 seconds, run
    70  ```bash
    71  $ cd ../../build; make run-sdk-conformance-local TIMEOUT=120 TESTS=ready,watch,health,gameserver
    72  ```
    73  
    74  In a separate terminal, while the SDK-server is still running, build and execute the example gameserver:
    75  ```bash
    76  $ make build
    77  $ make run
    78  ```
    79  
    80  You will see the following output:
    81  ```
    82  Rust Game Server has started!
    83  Creating SDK instance
    84  Setting a label
    85  Starting to watch GameServer updates...
    86  Health ping sent
    87  Setting an annotation
    88  ...
    89  ```
    90  
    91  When you are finished, clean up the `sdk` directory and `target` folder:
    92  ```
    93  make clean
    94  ```