Skip to content

Instantly share code, notes, and snippets.

View ipmb's full-sized avatar

Peter Baumgartner ipmb

View GitHub Profile
@ipmb
ipmb / push_static_to_s3.py
Created April 15, 2020 21:44
Django management command to push whitenoise static files to S3, respecting headers
import logging
from concurrent import futures
from typing import List, Tuple
import boto3
from django.conf import settings
from django.core.management import BaseCommand
from whitenoise.middleware import WhiteNoiseMiddleware
log = logging.getLogger(__name__)
@ipmb
ipmb / Dockerfile
Last active June 13, 2023 14:19
amazon-ssm-agent Dockerfile
FROM golang:1.12-alpine as builder
ARG VERSION=2.3.930.0
RUN set -ex && apk add --no-cache make git gcc libc-dev curl bash && \
curl -sLO https://github.com/aws/amazon-ssm-agent/archive/${VERSION}.tar.gz && \
mkdir -p /go/src/github.com && \
tar xzf ${VERSION}.tar.gz && \
mv amazon-ssm-agent-${VERSION} /go/src/github.com/amazon-ssm-agent && \
cd /go/src/github.com/amazon-ssm-agent && \
echo ${VERSION} > VERSION && \
gofmt -w agent && make checkstyle || ./Tools/bin/goimports -w agent && \
@ipmb
ipmb / cloudfront_signed_storage.py
Created March 25, 2020 17:09
Django S3 Storage backend to generate signed Cloudfront URLs
"""
S3 Storage served via private Cloudfront URL
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html
https://github.com/boto/boto3/blob/develop/boto3/examples/cloudfront.rst
"""
import datetime
from botocore.signers import CloudFrontSigner
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
@ipmb
ipmb / docker-exec-ecs.sh
Last active June 2, 2022 17:30
docker exec on AWS ECS with SSM
#!/bin/bash
# USAGE: CLUSTER=mycluster SERVICE=myservice ./docker-exec-ecs.sh
set -euf -o pipefail
TASK_ARN=$(aws ecs list-tasks --cluster=$CLUSTER --service=$SERVICE \
| jq -r .taskArns[0])
if [ "$TASK_ARN" = "null" ]; then
echo "Could not find any running tasks for $SERVICE on cluster:$CLUSTER."
exit 1
fi
import logging.config
from django.utils.log import DEFAULT_LOGGING
# =======
# LOGGING
# =======
LOGGING_CONFIG = None
LOGLEVEL = os.getenv("LOGLEVEL", "info").upper()
@ipmb
ipmb / uwsgi_cors_router.ini
Last active August 6, 2019 17:05
Add CORS headers for domains matching a regex in uWSGI
# Add CORS header for Origin's which match a regexp
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin#Examples
route-if = regexp:${HTTP_ORIGIN};^.*\.example\.com$ addheader:Access-Control-Allow-Origin: ${HTTP_ORIGIN}
[tool.poetry]
name = "tmp"
version = "0.1.0"
description = ""
authors = ["User <user@example.com>"]
[tool.poetry.dependencies]
python = "^3.7"
requests = "^2.21"
sentry-sdk = "^0.7.11"
@ipmb
ipmb / Dockerfile
Created April 4, 2019 21:56
Build vmods on Ubuntu from Varnish repo
FROM ubuntu:18.04
ARG REPO=varnish60lts
RUN set -ex && \
apt-get update -qq && \
apt-get -yq install curl apt-transport-https build-essential libtool autotools-dev automake gnupg && \
echo "deb https://packagecloud.io/varnishcache/${REPO}/ubuntu/ bionic main" > /etc/apt/sources.list.d/varnish.list && \
curl -L https://packagecloud.io/varnishcache/${REPO}/gpgkey | apt-key add && \
apt-get update -qq && \
apt-get -yq install varnish varnish-dev
@ipmb
ipmb / keybase.md
Created November 3, 2018 14:23
keybase.md

Keybase proof

I hereby claim:

  • I am ipmb on github.
  • I am ipmb (https://keybase.io/ipmb) on keybase.
  • I have a public key ASAhIL1zFberH0RNfVsAfqZOpwcXxLWpcQgGfaSywHmS0wo

To claim this, I am signing this object:

shiv -o test.pyz -e pytest:main .
./test.pyz --pyargs my_tests
echo $?