Skip to content

Instantly share code, notes, and snippets.

#----------------------
# instance sizes: https://docs.microsoft.com/en-us/azure/virtual-machines/dv3-dsv3-series
# Azure VM
#----------------------
clouddevvmazure-up:
az vm create \
--name sm_dev2 \
--resource-group kdocs \
--size Standard_D4s_v3 \
--image "Canonical:0001-com-ubuntu-confidential-vm-focal:20_04-lts-gen2:20.04.202110290" \
#!/bin/bash
#set -e; [ "$TRACE" ] && set -x
set -e
set -x
# figure out the latest release
# This script must be run as root.
[ `id -u` != "0" ] && echo "Must run as root" && exit 1
source /etc/os-release
# yum relies on python2 hence breaks when updating to python3
# fix yum to explicitly use python2 because when we replace with python 3, yum breaks
$ sudo sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2/' /usr/bin/yum

IMPORTANT - create WITH tags:

$ aws ec2 run-instances --image-id ami-0022f774911c1d690 --security-group-ids sg-0b8cf89d293b7adfc --instance-type t3.medium --key-name sm-key --count 1 --no-paginate --tag-specifications 'ResourceType=instance,Tags=[{Key=usage,Value=guide-examples}]' 'ResourceType=volume,Tags=[{Key=usage,Value=guide-examples}]'

IMPORTANT - query with tags in CLI

$ aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' --filters "Name=tag:usage,Values=guide-examples" --output text
@smijar
smijar / cloud-init-vagrant-ubuntu-kvm-dev.txt
Last active May 8, 2022 00:46
a cloud-init for a VM with golang, node, java and Python using sdkman and pyenv
#!/bin/sh
set -xe
echo "this has been written via cloud-init" + $(date) >> /tmp/myScript.txt
echo "write install script for java sdkman and python pyenv"
# check kvm
sudo chmod +x /dev/kvm
sudo lscpu | grep Virtualization
#!/usr/bin/python3
#
# 1. $ docker save -o foo.tar image
#
# 2. Call me like this:
# docker-image-extract tarfile.tar extracted
# to install $ sudo curl -Lo /usr/local/bin/docker-image-extract https://gist.githubusercontent.com/smijar/0f4a5a8a8ce69ed54baa6e82063ff074/raw/e4f50bc636a27d88aa1a3fbf3073ceff271bbf4b/docker-image-extract.py
import tarfile
import json
# enables unmount and remount of sshfs folders to vagrant vm
# on mac when suspending or sleep the sshfs folders get unmounted, so instead of reloading VM we can do this
$ vagrant sshfs --unmount
$ vagrant sshfs --mount
#Vagrant.configure("2") do |config|
# config.vm.box = "hashicorp/bionic64"
# config.vmx_custom_settings = [['vhv.enable', 'True']]
#end
vm_script = <<-SCRIPT
#!/bin/bash
set -euxo pipefail
echo hello, world!
# made it performant on OS X based on this article:
# https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck
# nfs on mac: https://knowledge.autodesk.com/search-result/caas/sfdcarticles/sfdcarticles/Enabling-network-NFS-shares-in-Mac-OS-X.html
#
# on Mac OS X:
# NOTE: if access denied error
# might have to restart nfsd
# $ sudo nfsd restart or use before vagrant up: $ sudo mount -o vers=3,udp 192.168.56.1:/Users/me/path/to/code /vagrant
# also $ showmount -e
#
# made it performant on OS X based on this article:
# https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck
# nfs on mac: https://knowledge.autodesk.com/search-result/caas/sfdcarticles/sfdcarticles/Enabling-network-NFS-shares-in-Mac-OS-X.html
#
# on Mac OS X:
# NOTE: if access denied error
# might have to restart nfsd
# $ sudo nfsd restart or use before vagrant up: $ sudo mount -o vers=3,udp 192.168.56.1:/Users/me/path/to/code /vagrant
# also $ showmount -e