038 - June 14, 2019

A fun case of Rust to Rust FFI

Hey!

This past week I worked on our continuous deployment.

I made some good progress and planning to finish things up this week.

Continuous Deployment of the Game's Web Client

The game's web client deployment consists of three files.

A .html file, a .wasm file, and a .js file.

The wasm file and JS file are generated by wasm-bindgen during our build process.

The HTML file looks like this:

<!-- HTML for Akigi Web Game Client -->

<html>
    <head>
        <title>Akigi</title>
    </head>
    <body style='margin: 0; padding: 0; width: 100%; height: 100%;'>
        <div id='akigi-web-client' style='width: 100%; height: 100%;'>
            <canvas id='akigi-game-canvas' width='900' height='560'></canvas>
        </div>
        <script src='/web_client.js'></script>
        <script>
            window.wasm_bindgen('web_client_bg.wasm').then(start)

            function start () {
                const { WebClient } = window.wasm_bindgen
                const rust = new WebClient()
                rust.start()
            }

            function downloadBytes(path, callback) {
              window.fetch(path)
                  .then(response => response.arrayBuffer())
                    .then(bytes => {
                        bytes = new Uint8Array(bytes)
                        callback(bytes)
                    })
            }
        </script>
    </body>
</html>

We have a CI job for deploying the game's web client which ends up running the following:

set -e

ak dist download-game-server --name="current-prod" -o /tmp
ak test game-server-integration --server-staticlib /tmp/libgs_static.a
ak deploy web-client --name="latest-green-master"

We first download a static library binary of the game server that is currently running in production.

We then run our integration tests against it. If they pass we know that the latest client code is compatible with the live server.

Then, if those tests passed, we deploy the web client by copying the HTML, Wasm and JS into our public-acl s3 bucket.

Deploy process image Web client automatically deployed if latest integration tests pass against a staticlib of the server that is currently in production.

Next Week

We can't automatically deploy the game server because at any point there can be players connected to it via websocket.

So we need to explicitly decide to deploy it.

I've started working on a process that will allow me to deploy the game server.

The final CLI command should end up looking something like ak deploy-game-client --shutdown-timer 30, which would mean that the gave will get updated in 30 minutes and connected players will see a countdown indicating this.

More on that next week!


Cya next time!

- CFN