First you have to create the required Azure resources for your team.
To make things easy we created a deploy-team.sh script for you - it is using Terraform underneath.
Attention: You only need to do the following once as a team - not every team member need to do it!
Find below instructions how to...
- provision all needed Azure services
- deploy the GameBot
- deploy and configure the GameEngine
- Test it manually
- Register your game endpoint
Sincerely, your World Game Federation!
Hint: The resources created may be edited by the hackteams according to requirements throughout the day.
If you like, you can import this repository into your own GitHub repository and work with it.
Hint: Please import it and not clone/fork it - otherwise others teams can peek at you.
But this requires advanced knowledge at all team members regarding GitHub, Azure CLI and kubectl and have already installed these tools locally.
Attention: If you are not working already day-to-day with GitHub, Azure CLI and kubectl - please use Azure CloudShell!
Azure CloudShell (http://shell.azure.com) enables you to clone this repository directly inside the shell and it gives you benefit that already all tools are preinstalled.
Attention: To leverage this way, every team member needs to use the same Azure account!
-
Open CloudShell on http://shell.azure.com, if required create a storage account (only for cloud shell sessions) in your subscription and open Bash.
-
Clone this repo in CloudShell. This command downloads the git repository to your machine.
git clone https://github.com/azure-adventure-day/aad-team.git
- Infrastructure as Code with Terraform is used for deploying all Azure resources, which is defined in the ./terraform folder.
Deploy them using the following command.
Make the file executable first. Make sure you run this in the right directory.
chmod +x ./deploy-team.sh
Pick a name for your team. The name will be reflected in your Azure resources, no other team sees it.
Avoid special characters and keep it short (6 chars max).
./deploy-team.sh <team_name> northeurope <subscription_id>
Hint: This will take some minutes - take the time to look into the Terraform scripts, Kubernetes YAML files and provided source code from World Game Federation.
After the script has been executed you will see three resource groups:
- one holding the Terraform state,
- one holding all Azure resources
- and the last one is used by the AKS cluster for all the infrastructure components behind
Attention: Please see the Terraform output, it includes the SQL Server password and the SQL connection string
Deploy it using the following command.
Make sure you run this in the right directory.
kubectl apply -f gamebot_deployment.yaml
-
An instance of Azure SQL and a SQL DB should have been deployed to your RG
-
Adjust the firewall in the Azure Portal for Azure SQL Server so you can work with the DB
-
Also allow other Azure Services to access SQL Server so your cluster can talk to the DB
-
In the Azure Portal open your SQL Database, go to the Query editor and execute all the scripts in the ./DatabaseScripts folder
-
Take a note of the SQL database connection string
-
Switch to the GameEngine folder and modify the
blackbox_gameengine_deployment.yaml
file to reference your connection strings. Make sure you set the password correctly in the DB connection string. You can do this directly in the CloudShell using VIM in the right folder. (vim blackbox_gameengine_deployment.yaml) Or you can choose the fancy way and run code . to get a more graphical user experience of an editor within CloudShell. (this will open a Visual Studio Code like experience in the browser.) -
You can deploy directly from Cloud Shell. Run the following command to be able to use kubectl with your aks cluster.
az aks get-credentials -n <aks_cluster_name> -g <resource_group_name>
- Deploy the game engine using kubectl.
kubectl apply -f blackbox_gameengine_deployment.yaml
- Figure out the public endpoint which can be used to call your game engine. Use the command below and get the public IP of the gameengine service.
kubectl get services --field-selector metadata.name=blackboxgameengine --output=jsonpath={.items..status.loadBalancer.ingress..ip}
- If you found your endpoint, you can call it on
http://<YOUR_ENDPOINT_IP>/Match
in the browser.
You have to provide this URL in the team portal, so gambling can start.
Attention: Test it first (next paragraph) to ensure everything is fine - otherwise the Smorghs will be very angry!
- Test your GameBot
You can get the IP of your bot by running
kubectl get services --field-selector metadata.name=gamebot --output=jsonpath={.items..status.loadBalancer.ingress..ip}
You can test your bot by posting a request to your bot's public IP http://A.B.C.D/pick. The result should look like this: {"Move":"snap","Bet":null}. Here's a sample request for the commandline.
GAME_BOT_IP=$(kubectl get services --field-selector metadata.name=gamebot --output=jsonpath={.items..status.loadBalancer.ingress..ip})
curl --location --request POST "http://$GAME_BOT_IP/pick" --header 'Content-Type: application/json' --data-raw '{"Player1Name":"daniel","MatchId":"42"}'
- Test your GameEngine
You can test your engine by posting a request to your engine's public IP.
The result contains all the info for the current match. Here's a sample request.
GAME_ENGINE_IP=$(kubectl get services --field-selector metadata.name=blackboxgameengine --output=jsonpath={.items..status.loadBalancer.ingress..ip})
curl --location --request POST "http://$GAME_ENGINE_IP/Match" --header 'Content-Type: application/json' --data-raw '{"ChallengerId":"daniel","Move": "Rock"}'
For subsequent requests, make sure you put the gameid from the response into the request.
Register your game endpoint in your team portal.
Attention: As soon as you have registered it customers will start gambling and your performance is being measured. So make sure everything works as expected up front!
Azure Application Insights (AppInsights) was already provisioned with the Terraform scripts above.
To enable it, you need to
- get the AppInsights Instrumentation key from the Azure portal
- provide it via the environment variable
APPINSIGHTS_INSTRUMENTATIONKEY
for the GameBot and GameEngine
You can deploy directly from ghcr.io/azure-adventure-day/azure-adventure-day-coach/gamebot:latest without an additional build.
But if you change the source code, you can build and push the container manually or use a prepared github action (check the ./.github/workflows folder).
To modify, build and push the bot before deploying it, follow these steps:
- Build the image you want to use, eg like this.
// or use Azure Container Registry (was already deployed above)
az acr build --image gamebot:latest --registry myveryownregistry --file Dockerfile .
- Ensure your AKS has access to the Container Registry. If using your own Azure Container Registry a pull-secret needs to be configured
kubectl create secret docker-registry teamregistry --docker-server 'myveryownregistry.azurecr.io' --docker-username 'username' --docker-password 'password' --docker-email '[email protected]'
-
Ensure that gamebot_deployment.yaml uses this pull-secret
-
Change the file gamebot_deployment.yaml to reference your bot image