Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Curylo ninjarobot

  • Microsoft @Azure
  • Atlanta, GA
View GitHub Profile
@ninjarobot
ninjarobot / acr-workflow.fsx
Last active Jul 27, 2021
Deploys an Azure Container Registry, builds Docker image, pushes it there, hosts in ACI
View acr-workflow.fsx
#r "nuget: Farmer"
#r "nuget: FSharp.Text.Docker"
open System
open Farmer
open Farmer.Builders
open FSharp.Text.Docker.Dockerfile
// Create Container Registry
let myAcr =
@ninjarobot
ninjarobot / home-grown-farmer-resource.fsx
Created Jun 30, 2021
Create a minimal ARM resource to use with Farmer template generation.
View home-grown-farmer-resource.fsx
#r "nuget: Farmer"
open Farmer
// Give it a resource type. This is helpful the resource and handling dependencies.
let rightClickDeployments = ResourceType ("Microsoft.Hi/rightClickDeployments", "2021-06-29")
// Define the resource itself.
let minimalResource =
{ new IArmResource with
@ninjarobot
ninjarobot / farmer-global-app.fsx
Last active Jun 18, 2021
Farmer application with multiple resource groups and traffic manager
View farmer-global-app.fsx
#r "nuget: Farmer, 1.6.0"
open Farmer
open Farmer.Builders
open Farmer.Builders.ContainerGroups
open Farmer.Builders.TrafficManager
open Farmer.TrafficManager
let msi = userAssignedIdentity {
name "my-app"
@ninjarobot
ninjarobot / du-with-partial-active-pattern.fs
Last active Apr 8, 2021
Using partial active patterns to return calculated data in pattern matches
View du-with-partial-active-pattern.fs
/// Several types of consoles
type Console =
| Playstation_5
| Xbox_Series_X
| Switch
with
member this.Name =
match this with
| Playstation_5 -> "Playstation 5"
| Xbox_Series_X -> "XBox Series X"
@ninjarobot
ninjarobot / JsonConfigSource.fs
Created Jan 20, 2021
Load a configuration source from a JSON string in F#
View JsonConfigSource.fs
open Microsoft.Extensions.Configuration
/// Builds a configuration source from raw JSON.
let configSourceFromJson (json:string) : IConfigurationSource =
{ new IConfigurationSource with
member this.Build (builder:IConfigurationBuilder) =
{ new ConfigurationProvider() with
member this.Load() =
this.Data <- Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string,string>> json
} :> IConfigurationProvider
@ninjarobot
ninjarobot / minecraftServerDeployment.fsx
Created Jan 5, 2021
Generates an ARM deployment template for creating a Minecraft Server running on Azure container instances
View minecraftServerDeployment.fsx
#r "nuget: Farmer"
#r "nuget: MinecraftConfig"
#r "nuget: FSharp.Data"
open System
open Farmer
open Farmer.Builders
open FSharp.Data
open MinecraftConfig
@ninjarobot
ninjarobot / wcfclient.fs
Created Dec 5, 2020
Using WCF in dotnet without a trusted certificate
View wcfclient.fs
let binding = CustomBinding ()
let textMessageEncoding = TextMessageEncodingBindingElement ()
textMessageEncoding.MessageVersion <- MessageVersion.Soap11
let transport = HttpsTransportBindingElement (RequireClientCertificate=false, AllowCookies=true, MaxReceivedMessageSize=int64(Int32.MaxValue))
binding.Elements.Add textMessageEncoding
binding.Elements.Add transport
@ninjarobot
ninjarobot / etcdDeployment.fsx
Created Nov 22, 2020
Deploying etcd on Azure with Farmer
View etcdDeployment.fsx
open System
open Farmer
open Farmer.Builders
let deploymentLocation = Location.EastUS
let etcdDataStorage = storageAccount {
name "etcddata"
add_file_share_with_quota "data" 5<Gb>
}
@ninjarobot
ninjarobot / ACI_in_VNet_with_MSI.json
Last active Oct 13, 2020
Creating an Azure container instance in a vnet using managed identity
View ACI_in_VNet_with_MSI.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2018-11-30",
"dependsOn": [],
"location": "eastus",
@ninjarobot
ninjarobot / deployment_cleanup.sh
Created Feb 28, 2020
Cleanup ARM deployments
View deployment_cleanup.sh
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: deployment-cleanup.sh <subscription_id> <resource_group>"
exit 1
fi
az group deployment list --subscription $1 -g $2 --query '[].{name:name,ts:properties.timestamp}[*].name' -o tsv | tail -n +100 | xargs -n1 az group deployment delete --subscription $1 -g $2 -n