Skip to content

Instantly share code, notes, and snippets.

View mmerickel's full-sized avatar

Michael Merickel mmerickel

View GitHub Profile
@mmerickel
mmerickel / ssm-proxy.sh
Last active November 11, 2023 20:23
Connect to AWS instance using SSM and ec2-instance-connect with public access, and no shared keys.
#!/bin/bash
# Install an SSH key on an instance automatically and then configure an
# SSM proxy to the instance which will be used by SSH.
#
# Copy this script to ~/.ssh/ssm-proxy and make it executable:
#
# chmod +x ~/.ssh/ssm-proxy
#
# This script should be set as the ProxyCommand. For example:
#
@mmerickel
mmerickel / Dockerfile
Last active February 11, 2022 19:25
istio-launcher for implementing graceful shutdown and one-off job termination
FROM ...
COPY istio-launcher.py /app/istio-launcher.py
ENTRYPOINT ["tini", "--", "/app/istio-launcher.py"]
import argparse
import boto3
from collections import defaultdict
import csv
from datetime import datetime, timedelta
import logging
from pprint import pprint
import queue
import signal
import sys
@mmerickel
mmerickel / pyproject.toml
Created December 13, 2020 23:12
poetry config for pyramid scaffold
[tool.poetry]
name = "pyramid_scaffold"
version = "0.1.0"
description = "Pyramid Scaffold"
authors = []
classifiers = [
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
@mmerickel
mmerickel / aws-profile.sh
Last active February 6, 2024 17:10
a bash / zsh compatible alias that can assist in switching between aws profiles and triggering sso login if necessary
aws-profile() {
read -r -d '' SCRIPT <<'EOF'
import argparse
from configparser import RawConfigParser
import os
import shutil
import subprocess
import sys
from textwrap import dedent
@mmerickel
mmerickel / .gitlab-ci.yml
Created November 25, 2020 20:11
pre-commit cached with terraform
pre-commit:
image: python:3.8-buster
variables:
XDG_CACHE_HOME: ${CI_PROJECT_DIR}/.ci-cache
PYTHONUSERBASE: ${CI_PROJECT_DIR}/.ci-cache
TF_VERSION: 0.13.5
PRE_COMMIT_VERSION: 2.9.0
cache:
# bust the cache if the python version changes
key: ${CI_JOB_IMAGE}
@mmerickel
mmerickel / pyramid_resources.py
Created June 28, 2020 15:53
Support annotating resource objects with a URL and using them for view lookup.
from pyramid.interfaces import IResourceURL
from pyramid.traversal import traversal_path
import venusian
from zope.interface import implementedBy, providedBy
from zope.interface.interfaces import IInterface
class resource_config(object):
"""
A class decorator for defining resources.
#!/usr/bin/env bash
set -eEo pipefail
SSH_TRACE=
[[ "$TRACE" = "1" ]] && set -x && SSH_TRACE="-vvv"
SSH_TARGET=merickel.org
CONTROL_PATH=$(pwd)/.ssh-${SSH_TARGET}
SOCKET_PATH=$(pwd)/docker.sock
@mmerickel
mmerickel / .env
Last active June 5, 2023 09:09
render an ini file based on env vars
##############################################################################
# Settings made available in site.ini.in.
#
# After making changes re-run render-config
#
# Override settings by making a .env.local file.
##############################################################################
DEBUG=yes
WEB_CONCURRENCY=10
@mmerickel
mmerickel / cli.py
Last active November 20, 2019 00:38
wrap a wired service layer into pyramid_services
from myapp.services import make_service_factory
from myapp.utils.tm import tm_context
class CLI:
@reify
def service_factory(self):
return make_service_factory(self.settings)