Skip to content

Instantly share code, notes, and snippets.

@gmoon
gmoon / Makefile
Last active February 13, 2024 13:32
Use make, mock, and expect to automate rpmbuild and rpmsign
# For the rpm-sign recipe, GoCD is injecting a secret GPG_PASSPHRASE
# into the environment. It should be fully compatible with Jenkins, Hudson, etc.
#
# For most CI systems, build artifacts need to be located within the working directory,
# so here the rpmbuild area is specified by _topdir and the default location (~/rpmbuild)
# is not used.
#
# The rpm and rpm-mock recipes require the source tar.gz archive for mypackage.spec to be
# available in target/rpmbuild/SOURCES. You can add your own recipe to achieve this and make
# it a dependency in the Makefile so this happens automatically.
@gmoon
gmoon / inject_instance_data.sh
Last active February 13, 2024 13:32
Inject AWS instance metadata into environment variables on your EC2 instance
# Inject environment variables into current shell
# Note: using jq's from_entries on the Key/Value pairs (capital K and V) format of Tags requires version 1.5 or higher
export INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
export STACK_NAME=`aws ec2 describe-instances --instance-ids $INSTANCE_ID --region us-east-1 \
| jq --raw-output '.Reservations[0].Instances[0].Tags | from_entries | .["aws:cloudformation:stack-name"]'`
# Make it permanent
echo export INSTANCE_ID=$INSTANCE_ID > /etc/profile.d/awsinstance.sh
@gmoon
gmoon / rsyslog-elasticsearch.conf
Last active February 5, 2017 22:23
Rsyslog configuration to forward logs to elasticsearch in batch and in a Kibana-compatable format
# /etc/rsyslog.d/31-elasticsearch.conf
# send syslog messages to logstash/kibana
module(load="omelasticsearch") # for outputting to Elasticsearch
# this is for index names to be like: logstash-YYYY.MM.DD
template(name="logstash-index"
type="list") {
constant(value="logstash-")
property(name="timereported" dateFormat="rfc3339" position.from="1" position.to="4")
constant(value=".")
@gmoon
gmoon / updaterepo.sh
Last active February 13, 2024 13:32
Update an s3-based Yum repo with a new package with minimal data transfer
#!/bin/bash -x
# Using s3 to host a yum repo has many advantages, but there is often
# a need to push new artifacts and update the metadata. To achieve
# this, we will mirror the s3 repo locally in a crafty way. We will
# grab the full repo metadata (in the repodata directory), but the packages
# will not be downloaded. Instead, the files will be created but will be
# EMPTY. This avoids large data sync's.
OPTIND=1
@gmoon
gmoon / Dockerfile
Last active February 13, 2024 13:32
Dockerfile for aws-cli, aws-sam-cli, and python3 on alpine linux
FROM alpine:3.10
RUN apk -v --no-cache --update add \
musl-dev \
gcc \
python3 \
python3-dev
RUN python3 -m ensurepip --upgrade \
&& pip3 install --upgrade pip
RUN pip3 install --upgrade awscli aws-sam-cli
RUN pip3 uninstall --yes pip \