Skip to content

Instantly share code, notes, and snippets.

View ppanyukov's full-sized avatar

Philip Panyukov ppanyukov

  • UK
View GitHub Profile
# Shows how to get auth token for VSTS (Azure Devops) from Azure CLI.
#
# Extracted from various github projects: Azure CLI and Azure SDK for Go
# See: https://github.com/Azure/azure-sdk-for-go/blob/ca5ebc8601ba1af17b289bb42161b7afb496423f/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1#L17
# VSTS / Azure Devops resource identifier is: "499b84ac-1321-427f-aa17-267ca6975798"
organisation="your_org"
project="your_project"
@ppanyukov
ppanyukov / deployment.yaml
Created June 18, 2022 14:04
Using Docker in Kubernetes
---
# This creates a deployment where each pod has two containers:
# - Docker Server: the actual docker engine.
# - Docker Client: simple Ubuntu instance with docker cli so we can
# test the docker things. In practice this would be some CI agent
# like Azure Devops agent or Jenkins or anything at all.
#
# After this deployment is created, wait for a bit for docker CLI to be installed
# in the client container. Then shell into it and use docker commands like docker build etc
# to test that things actually work.
# This is a hack to obtain azurerm_user_assigned_identity data item from
# the cluster.identity object.
#
# The reason we need this is depending on the kind of identity (SystemAssigned,
# UserAssigned) we have different fields in that object. In particular if we
# have UserAssigned identity, the value of principal_id will be empty, and
# we need to assign roles to it like Network Contributor.
#
# To use:
# # Grab the cluster data item
@ppanyukov
ppanyukov / azure-graph-tag-list.kusto
Last active June 10, 2020 15:45
Azure Graph: List all tags as name value columns
// Problem: tags in Azure are an objects like this:
// {tag_name: tag_value, tag_name2: tag_value2}
//
// What we want is to list these as table with name,value columns.
// The way I found is to convert the tag objects into arrays by
// simple text replace and then we can tag and value by index and
// can project them as columns. :)
Resources
| project tags
| extend tags = tostring(tags)
@ppanyukov
ppanyukov / az.sh
Last active June 9, 2020 15:00
How to run Azure CLI in docker as if it's locally install and not notice a difference :)
# How to use dockerised version Azure CLI (or anything else)
# in a totally transparent way. This solves several challenges:
# - Persistent login. Don't want to login every time.
# - Container startup time. It can be noticable.
# - Access to host's disk.
# - Run without ever using "docker" command.
#
# WINDOWS NOTE:
# - You *will* run into volume mapping issues on Windows, sadly.
# - Either remove any args with '-v` and 'v` and then everything
@ppanyukov
ppanyukov / powershell-azure-cli-demo.ps1
Created April 21, 2020 17:53
powershell-azure-cli-demo
#!/usr/bin/env pwsh
# Very very small demo of Powerhell and how to use
# Azure CLI from within it.
# These should be required for all scripts.
# The first says to stop at any failure, almost same as bash 'set -e'
# except it does not apply to external commands unfortunately.
# The second one is to make sure informational messages are written.
# See: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7
@ppanyukov
ppanyukov / string_hacks.go
Created November 7, 2019 13:25
Go Hacks for Performance and Fun
package main
import (
"fmt"
"unsafe"
)
// A demo of things you can do with strings and []byte slices
// in a dangerous and exciting ways. I got here by having to verify
// if two given strings point to the same storage in memory.
@ppanyukov
ppanyukov / dirtyCast.go
Last active October 17, 2019 15:25
dirtyCast converts from []Foo to []Bar without copy.
package main
import (
"encoding/json"
"fmt"
"unsafe"
)
// dirtyCast converts from []Foo to []Bar without copy.
func dirtyCast(foos []Foo) []Bar {
@ppanyukov
ppanyukov / sample-gen-config.yml
Last active October 7, 2019 09:58
attempt at generating raw Prometheys TSDB blocks
---
# Sample configuration for metric generation.
# This is used to create random but repeatable
# set of metrics to populate Prometheus TSDB
# for further benchmarks etc.
#
# WORK IN PROGRESS
# TODO:
# - where do we configure the sample interval?
@ppanyukov
ppanyukov / encrypt.sh
Last active September 14, 2021 06:13
Noddy script to encrypt/decrypt files using openssl private (ssh) key.
#!/usr/bin/env bash
set -eu
# Noddy script to encrypt/decrypt files using openssl private (ssh) key.
# Works with files and stdin.
# Results are stdout.
#
# Requirements:
# - openssl
# - ssh private key: ~/.ssh/id_rsa