Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
wehappyfew / Dockerfile-k8s-admin
Created February 8, 2018 20:24
Alpine image to control Kubernetes on Azure using Helm and Draft
#
# Custom Dockerfile
# - based on Alpine linux
# - install AzureCLI v2.0
# - install Helm [Kubernetes (more than) package manager]
# - install kubectl
# Usage:
# Build it and push it to the private registry.
# Gitlab will use it to interact with Azure Kubernetes and Registry [AKS, ACR]
#
@wehappyfew
wehappyfew / scrape_gitlab_token.py
Created January 18, 2018 09:10
Script to grab from the Gitlab UI, the registration token needed to register the runners
# check http://kazuar.github.io/scraping-tutorial/
from bs4 import BeautifulSoup
import requests
from lxml import html
def grab_gitlab_runner_token(gl_user, gl_pass):
protocol = "http"
domain = "gitlab.example.com"
login_url = protocol+"://"+domain+"/users/sign_in"
@wehappyfew
wehappyfew / ssh-clone-dockerfile
Created January 18, 2018 09:05
Add a .pem file via on-build ARGS and clone a project from a private repo.
#Notice: add your .pem private key in the same path as the Dockerfile
# get the private key as on-build argument
ARG SSH_KEY_FILE = some-file.pem
ARG REPO_USER = some-user
ARG PROJECT = some-project
ENV REPO_URL = gitlab.example.com
#add the private key & set its permissions
RUN mkdir /root/.ssh/
COPY ./${SSH_KEY_FILE} /root/.ssh/${SSH_KEY_FILE}
running build_clib
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-oDYnTF/pynacl/setup.py", line 251, in <module>
"Programming Language :: Python :: 3.6",
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
@wehappyfew
wehappyfew / check_terraform_version.py
Created January 11, 2017 11:22
A lambda function that checks for the latest Terraform release
import boto3,requests,json,os,pprint
from bs4 import BeautifulSoup
tf_github_url = os.environ["target_url"] #"https://github.com/hashicorp/terraform/releases"
sns_topic_arn = os.environ["sns_topic_arn"] # eg arn:aws:sns:us-west-2:account-id:Report_terra_version
def post_to_SNS(SNS_topic_ARN, msg):
client = boto3.client('sns')
response = client.publish(
@wehappyfew
wehappyfew / ssh-config-github-multiple-deploy-keys
Created September 29, 2016 13:10
Using multiple github deploy keys from a Jenkins instance
# When using a CI server, like Jenkins, in conjunction with github, you may wish to use
# multiple deploy keys (github-speak for an rsa key pair that has been assigned to a single
# repo, rather than a user) to allow Jenkins to pull code from the github repositories
# In the example here, where three repos are used, the idea is to take advantage of ssh's config mechanism
# For use with Jenkins, do the following:
# login to your CI Server
sudo su jenkins
cd ~/.ssh/
@wehappyfew
wehappyfew / Restore_RDS_from_Snapshot.py
Created September 22, 2016 08:36
A script that finds the most recent snapshot of an existing rds instance and creates a new db instance based on that
from time import time, localtime, strftime, sleep, gmtime
from AWSsetup import AWS_user_secret_access_key,AWS_user_access_key_id
import boto.rds
def get_rds_instance_status(RDSconn, rds_instance_name):
# Grab the RDS instance status
instances = RDSconn.get_all_dbinstances(
instance_id = rds_instance_name,
)
# print instances #debug
@wehappyfew
wehappyfew / sample_locust_multiple_user_login.py
Last active August 2, 2016 19:49
example of simulating multiple users to use in a locust load testing script
import time,randint,config
users = 1000
users_rate = 10
class UserBehavior(TaskSet):
wait_secs = config.wait_for_locusts_to_hatch(locusts_num=users, hatch_rate=users_rate)
def on_start(self):
@wehappyfew
wehappyfew / locust_starter_scenario.py
Created August 2, 2016 18:59
Simple locust scenario to build upon.
__author__ = 'wehappyfew'
import time
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
def on_start(self):
# The scenario always starts by executing this function
# The way I load-test is creating a scenario function and running it from inside the on_start function.
# Notice: Inside the scenario function will reside ALL the steps of the load test.
@wehappyfew
wehappyfew / Cloud-Formation template
Created April 25, 2016 13:02
AWS CloudFormation template with 3 different instance 'types' (Server, Agent, Relay) I'm using AutoScaling to dynamically launch X number of instances of a type.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "uDeploy Agent-Relay-Server",
"Parameters" : {
"keyName" : {
"Description" : "SSH key to enable access on the servers",
"Type" : "String",
"Default" : "nick-portal"