Git Product home page Git Product logo

microsoft / rockpaperscissorslizardspock Goto Github PK

View Code? Open in Web Editor NEW
587.0 37.0 287.0 46.08 MB

Rock, Paper, Scissors, Lizard, Spock - Sample Application

License: MIT License

PowerShell 11.03% Python 2.31% C# 30.80% Dockerfile 0.92% Java 1.95% HTML 16.91% Shell 0.08% CSS 20.65% JavaScript 9.66% PHP 3.45% Mustache 2.24%
dotnet-core nodejs python java php tensorflow javascript blazor aspnetcore azure

rockpaperscissorslizardspock's Introduction

page_type name urlFragment description languages products
sample
Rock, Paper, Scissors, Lizard, Spock
azure-rock-paper-scissors
Rock, Paper, Scissors, Lizard, Spock is the geek version of the classic Rock, Paper, Scissors game.
csharp
powershell
html
php
python
javascript
java
azure-cosmos-db
azure-kubernetes-service
dotnet-core
azure-cognitive-services
vs
vs-code

Rock, Paper, Scissors, Lizard, Spock - Sample Application

We are happy to announce the release of Rock, Paper, Scissors, Lizard, Spock sample application running in Azure presented at Microsoft Ignite 2019 by Scott Hanselman and friends.

Rock, Paper, Scissors, Lizard, Spock is the geek version of the classic Rock, Paper, Scissors game. Rock, Paper, Scissors, Lizard, Spock is created by Sam Kass and Karen Bryla.

The Rock, Paper, Scissors, Lizard, Spock - Sample Application shows a multilanguage application built with Visual Studio and Visual Studio Code, deployed with GitHub Actions and running on Azure Kubernetes Service (AKS). The sample application also uses Machine Learning and Azure Cognitive Services (Custom Vision API). Languages used in this application include .NET, Node.js, Python, Java, and PHP.

Application development for everyone

  • Get everything that you need to deploy the code and run in your subscription.

Table of contents

Application Screens

Application Diagram

This a multilanguage application running on AKS with AI embedded. There are 5 bots (.NET, NodeJS, Python, Java and PHP) the user can select a language as the opponent and both, the user and the bot will have to select an object to play. The Game Manager which is a .NET API decides who wins based on the logic of the game. If the user is authenticated using Twitter the bots will call a predictor AI Model (Python Azure Function), this model learns from the selections of the objects that the user have done based on the history (stored in a Cosmos DB) to try to predict their next move. If the user is not authenticated the bots will select a random object. There is also a TensorFlow model created with Custom Vision to allow the user to play with their hands by using the webcam.

Getting Started

Pre-Requisites

  1. You will need Visual Studio 2019 on Windows 10.
  2. You will need Docker Desktop.

If you want to deploy this solution in Azure:

  1. You will need and Azure Subscription in order to deploy this.
  2. Azure CLI.
  3. Download and install helm.

New to Microsoft Azure?

You will need an Azure subscription to work with this demo code. You can:

  • Open an account for free Azure subscription. You get credits that can be used to try out paid Azure services. Even after the credits are used up, you can keep the account and use free Azure services and features, such as the Web Apps feature in Azure App Service.
  • Activate Visual Studio subscriber benefits. Your Visual Studio subscription gives you credits every month that you can use for paid Azure services.
  • Create an Azure Student Account and get free credit when you create your account.

Learn more about it with Microsoft Learn - Introduction to Azure.

Deploy to Azure

You can either go through all steps and customizing its configuration or run one single command.

Deploy RPSLS using one script

Execute the script located in Deploy folder with the following parameters:

.\Deploy-Unified.ps1 -resourceGroup <resource-group-name> -location <location> -clientId <service-principal-id> -password <service-principal-password> -subscription <subscription-id>
  • resourceGroup: The name of your resource group where all infrastructure will be created Required
  • location: Select where you want to create your resource group, for example: eastus Required
  • clientId: Id of the service principal used to create the AKS Optional
  • password: Password of the service principal Optional
  • subscription: Id of your subscription where you are going to deploy your resource group Required

If service principal credentials are not passed a new one will be created.

Deploy RPSLS step by step

To run RPSLS you need to create the Azure infrastructure. There are two ways to do it. Using Azure portal or using a Powershell script.

Step 1 - Option 1: Creating infrastructure using Azure Portal

An ARM template is provided so you can create the whole infrastructure required for RPSLS

Deploy to Azure

  • servicePrincipalId: Id of the service principal used to create the AKS Required
  • servicePrincipalSecret: Password of the service principal Required
  • aksVersion: AKS version to use. Required

The deployment could take more than 10 minutes, and once finished all needed resources will be created.

Step 1 - Option 2: Create the resources using the CLI

You can use the CLI to deploy the ARM script. Open a Powershell window from the /Deploy folder and run the Deploy-Arm-Azure.ps1 with following parameters:

  • -resourceGroup: Name of the resource group Required
  • -location: Location of the resource group Required if resourceGroup does not exist
  • -clientId: Id of the service principal used to create the AKS Optional
  • -password: Password of the service principal Optional

If service principal credentials are not passed a new one will be created.

Once script finishes, everything is installed. If a service principal has been created, the script will output the service principal details - please, take note of the appId and password properties for use them in the AKS deployment

Step 2: Deploy RPSLS on AKS

Pre-requisites for this deployment are to have:

  • The AKS and all related resources deployed in Azure
  • A terminal with Powershell environment
  • Azure CLI 2.0 installed.
  • Azure Functions Core Tools installed (required only to deploy Predictor).
  • Kubectl installed with the last version (v1.16.0 at this moment).
  • Helm 3 installed with 3.0 or superior version (v3.0.0 at this moment).
  • Docker installed

Service Principal

A Service Principal is needed for creating the AKS. If you use the CLI for create the resources. You need the client id and password of a Service Principal to install RPSLS.

In case you use Azure Portal for the resources' creation, you can also reuse a SP or create manually a new one for passing the credentials to the template.

Connecting kubectl to AKS

From the terminal type:

  • az login and follow instructions to log into your Azure.
  • If you have more than one subscription type az account list -o table to list all your Azure subscriptions. Then type az account set --subscription <subscription-id> to select your subscription
  • az aks get-credentials -n <your-aks-name> -g <resource-group-name> to download the configuration files that kubectl needs to connect to your AKS.

At this point if you type kubectl config current-context the name of your AKS cluster should be displayed. That means that kubectl is ready to use your AKS

Installing FlexVolume

The KeyVault support is implemented through FlexVol. To install Flex Volume in the AKS, type the following:

.\Create-Kv-FlexVolume.ps1

Publish Python Azure Function

To publish the Azure Function you can execute the next command of the Azure Functions Core Tools from the folder /Source/Functions/RPSLS.Python.Api:

func azure functionapp publish <funcapp-name> --no-build

The value for funcapp-name must be the name of the Function App created in your Azure Resource Group.

Configuring services

Before deploying services using Helm, you need to setup the configuration. We refer to the configuration file with the name of gvalues file. This file contains all secrets so beware to not commit in your repo accidentally.

A template of this file is in powershell/gvalues.template. The deployment scripts use this file by default, but do not rely on editing this file. Instead create a copy of it a folder outside the repository and use the -valuesFile parameter of the deployment script.

Note: The folder /Deploy/helm/__values/ is added to .gitignore, so you can keep all your configuration files in it, to avoid accidental pushes.

Please refer to the comments of the file for its usage.

Auto generating the configuration file

Generating a valid gvalues file can be a bit harder, so there is a Powershell script that can do all work by you. This script assumes that all resources are deployed in the same resource group, and this resource group contains only the RPSLS resources. Also assumes the Azure resources have been created using the tools provided in this repo.

Note The Generate-Config.ps1 uses the application-insights CLI extension to find the application insights id. Install it with az extension add --name application-insights

Note The configuration script requires the Azure function key so internal aks services can call it. So before executing the Generate-Config.ps1 make sure that the function is already published and the function key exists.

To auto-generate your gvalues file just go to /Deploy/powershell folder and from a Powershell window, type the following:

.\Generate-Config.ps1 -resourceGroup <your-resource-group> -outputFile ..\helm\__values\<name-of-your-file>

The Generate-Config.ps1 script accepts so many parameters. Here you can find a list of them all.

The script checks that all needed resources exists in the resource group. If some resource is missing or there is an unexpected resource, the script exits.

Build & deploy images to ACR

You can manually use docker-compose to build and push the images to the ACR. If using compose you can set following environment variables:

  • TAG: Will contain the generated docker images tag
  • REGISTRY: Registry to use. This variable should be set to the login server of the ACR

Once set, you can use docker-compose build and docker-compose push to build and push the images.

Additionally there is a Powershell script in the Deploy folder, named Build-Push.ps1. You can use this script for building and pushing ALL images to ACR. Parameters of this script are:

  • resourceGroup: Resource group where ACR is. Required.
  • acrName: ACR name (not login server). Required.
  • dockerTag: Tag to use for generated images (defaults to latest)
  • dockerBuild: If $true (default value) docker images will be built using docker-compose build.
  • dockerPush: If $true (default value) docker images will be push to ACR using docker-compose push.

This script uses az CLI to get ACR information, and then uses docker-compose to build and push the images to ACR.

To build and push images tagged with v1 to a ACR named my-acr in resource group named my-rg, execute the following command inside /Deploy/powershell

.\Build-Push.ps1 -resourceGroup my-rg -dockerTag v1 -acrName my-acr

To just push the images (without building them before):

.\Build-Push.ps1 -resourceGroup my-rg -dockerTag v1 -acrName my-acr -dockerBuild $false

Deploying services

You need to use Powershell and run ./Deploy-Images-Aks.ps1. A typical call is:

.\Deploy-Images-Aks.ps1 -resourceGroup $resourceGroup -aksName $myAks -acrName $myAcr -valuesFile $myValuesFilePath -tag v1

Note: Read the documentation of this script for a list of all parameters.

This script will install all services using Helm and your custom configuration from the configuration file set by -valuesFile parameter.

The parameter charts allow for a selective installation of charts. Is a list of comma-separated values that mandates the services to deploy in the AKS. Values are:

  • cs C# Player.
  • nj NodeJS Player.
  • py Python Player.
  • php PHP Player.
  • jv Java Player.
  • web Website
  • gm Game Manager

Swag

We distributed some swag after the keynote session at Ignite (t-shirts, stickers and pins) but we had a limited amount so it made sense to open up the logo for swag.


Feedback

Help us improve this sample application with your valuable feedback by filling up this survey.

If you prefer you can also send us an email with your feedback.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

rockpaperscissorslizardspock's People

Contributors

aleks-ivanov avatar angelavl avatar cdemiguel avatar dependabot[bot] avatar dijitald avatar dsrodenas avatar eiximenis avatar isaacrlevin avatar jennjin avatar kai-richardson avatar microsoft-github-operations[bot] avatar microsoftopensource avatar n-usha avatar olgamarti avatar oriolbonjoch avatar rgbrota avatar snpdev avatar supernova-eng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rockpaperscissorslizardspock's Issues

Document Kubernetes Architecture

The app is really cool and provides some good guidelines but any particular reason the app is using Kubernetes instead of the app service? Haven't gone through any particular metrics but usually App service deployments are more affordable than Kubernetes and will benefit from auto-scaling...

Need help with Azure Dev Spaces for RPSLS

Hi Friends ๐Ÿ˜ƒ,

At minute 43 of Scott Hanselman's Application Dev Keynote, Jessica Deen comes on stage for an Azure Dev Spaces demo using the Rock Paper Scissors Lizard Spock sample application.

I plan to replicate her demo wherein she redirects traffic from a connected AKS cluster to a development machine. But before I do that, I want to try Team development on Kubernetes using Azure Dev Spaces for RPSLS. This Quickstart is my reference.

My objective is to use Azure Dev Spaces with RPSLS for an AKS workshops that I run.

For testing, I had no problem using Azure Dev Spaces to run and debug RPSLS.Web in its own space. However, when I use azds up for the APIs, the application still uses the pod in the default K8s namespace, not in my azds space. I am interested in hearing if anyone has had success debugging the APIs with Azure Dev Spaces. I am probably missing a step. I'll be happy to share my steps in this issue. Thanks in advance

Error retrieving function keys on generation of gvalues file

On running .\Generate-Config.ps1 to auto-generate my gvalues file, I receive the following error:

Not Found({"error":{"code":"NotFound","message":"Error retrieving function keys."}})

The command that invokes the error is:

az rest --method post --uri "https://management.azure.com$($funcapp.id)/functions/$funcname/listKeys?api-version=2018-02-01" -o json --subscription $subscription

At

$funckeys=$(az rest --method post --uri "https://management.azure.com$($funcapp.id)/functions/$funcname/listKeys?api-version=2018-02-01" -o json --subscription $subscription | ConvertFrom-Json)

I suspect an incorrect uri format is the reason, as in this related thread on Stack Overflow. I tried again after updating the api-version to 2018-11-01, but this did not help.

Any thoughts?

Running app locally with docker desktop

Good day

I have problems running the app locally with docker desktop.

I cloned the repository, opened in VS 2019, built the app, everything good. I have RPSLS.Web as startup project and press F5.
I have docker desktop running, but get the following message in the browser:
Could not reconnect to the server.
Have fun defeating our bot with your language of choice!

In the output window I get the message:
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit '9bTXHbA9Q5vH-LPXg4wBw0SEuZMcT71Huwvutl0nqBc'.
System.InvalidOperationException: Cannot consume scoped service 'RPSLS.Web.Clients.IConfigurationManagerClient' from singleton 'Microsoft.Extensions.Options.IOptions`1[RPSLS.Web.Config.MultiplayerSettings]'.

What am I missing?
Regards

Deploy to Azure button error

Loved the "App Development for Everyone" Ignite keynote and demos. Kudos to all involved!

I'm giving rpsls a go today and have this issue to report.

In Step 1 - Option 1: Creating infrastructure using Azure Portal, I click on the Deploy to Azure button. This opens Azure Portal with the following error:

There was an error loading the template from URI 'https://raw.githubusercontent.com/OriolBonjoch/RPSLS/master/Deploy/arm/deployment.json'. Ensure that the template is publicly accessible and does not have any comments.

I was able to copy and paste deployment.json into a custom template in my Azure subscription and deploy from there.

Apart from the Service Principal Id and Secret, the Kv_object Id is also required. A minor point perhaps, but the Kv_object Id requirement is not mentioned in the README.md.

The deployment succeeded showing the following 10 resources:

image

Deploying services fails

I have complete and utter failure on the Deploying services step ๐Ÿ˜ง. As time permits today, I'll review logs and add information to this issue. If there are particular logs that the maintainers would like to see, please comment. Thanks

$ kubectl get po
NAME                                                 READY   STATUS              RESTARTS   AGE
rpsls-dotnet-dotnet-player-random-5cdfffbff6-pnvxn   0/1     ImagePullBackOff    0          6m3s
rpsls-game-game-api-d96656ffb-wdnvb                  0/1     ContainerCreating   0          5m52s
rpsls-java-java-player-random-69977b48d4-hjt45       0/1     ErrImagePull        0          5m57s
rpsls-node-node-player-paper-696fc4f975-lrl82        0/1     ImagePullBackOff    0          6m2s
rpsls-php-php-player-random-85d89489b6-mngvh         0/1     ErrImagePull        0          5m54s
rpsls-python-python-player-random-76bbdb94f9-x2rd6   0/1     ErrImagePull        0          5m56s
rpsls-web-865fb687c4-t5qcl                           0/2     ImagePullBackOff    0          5m50s

Tiller install error: configmaps is forbidden

On running .\Add-Tiller.ps1 from my local Powershell, I have the following error:

------------------------------------------------------------
Installing Helm
------------------------------------------------------------
Error: configmaps is forbidden: User "system:serviceaccount:kube-system:default" cannot list resource "configmaps" in API group "" in the namespace "kube-system"

Error occurs on the command helm list -q

I'm investigating this now, but if anyone wants to chime in with a solution, please do.

CRLF to LF for entrypoint.sh and mvnw

Just as an FYI: I had trouble with the JavaPlayer Dockerfile build and the ModelUploader.Web Dockerfile build.

JavaPlayer Dockerfile:

line 10: RUN ./mvnw package

./mvnw couldn't be found at docker build

ModelUploader.Web Dockerfile:

line 28: CMD /app/entrypoint.sh

Made the container crash at run time.

Both issues were related to the same problem. Both ./mvnw and entrypoint.sh were using Windows line endings (CRLF) as opposed to Unix ones (LF). Opening each file with Notepad++ - Edit - EOL - change to LF, fixed this error for me.

And I though I'd just leave this FYI out here for anyone else bumping into this issue. Maybe mention in install doc for awareness.

MountVolume.SetUp failed for volume "azure-kv"

Almost done with my RPSLS deployment. One more open issue (hopefully).

The rpsls-game-game-api deployment pods fail with the following message (masked with X's):

Warning  FailedMount  40s (x7 over 74s)  kubelet, aks-agentpool-96345064-0  MountVolume.SetUp failed for volume "azure-kv" : mount command failed, status: Failure, reason: /etc/kubernetes/volumeplugins/azure~kv/azurekeyvault-flexvolume failed, Access denied. Caller was not found on any access policy. r nCaller: appid=6e2584bf-XXXXXXXXXXXXXXXX;oid=087127d7-XXXXXXXXXXXXXX;numgroups=0;iss=https://sts.windows.net/XXXXXXXXXXXXXXX/ r nVault: rpslskvXXXXXXXXXXX;location=eastus InnerError={code:AccessDenied}

The secret game-api-kv is in place and in Azure Portal I see my cosmos-constr secret and an Access policy for my service principal. The appid is correct. I'll poke around some more over the weekend, but if anyone has a troubleshooting suggestion, please reply. Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.