Skip to content

Instantly share code, notes, and snippets.

@charlesmarshall
charlesmarshall / etcd-to-docker-env
Created September 3, 2014 10:22
Bash script to parse elements of etcd into -e docker params
#!/bin/bash
# create global ENVS associated array
declare -A ENVS
# string for the -e vars
environmentVariables=""
##
# set a a bunch of test data
generateTestEnvData(){
echo "Setting test data"
@charlesmarshall
charlesmarshall / coreos-auto-token-replace
Created September 3, 2014 09:03
automated vagrant up with token replacement
vagrant destroy -f
vagrant box update
ssh-keygen -f ~/.ssh/known_hosts -R 172.17.8.101
oldIFS="$IFS"
IFS="¬"
content="$(cat ./user-data)"
discovery="$(curl -s https://discovery.etcd.io/new)"
echo "new token: ${discovery}"
echo ${content} | sed -E "s#discovery: (.*)#discovery: ${discovery}#g" > ./user-data
IFS="$oldIFS"
@charlesmarshall
charlesmarshall / heartbeat-with-domain-registration.service
Created July 28, 2014 13:12
heartbeat service with added domain registration
[Unit]
Description=heartbeat for website
BindTo=website.service
[X-Fleet]
X-ConditionMachineOf=website.service
[Service]
EnvironmentFile=$pathToBashUtilitiesFile
Environment="envFile=$pathToBashUtilitiesFile"
Environment="containerName=website$counter"
Environment="sleepTime=20"
@charlesmarshall
charlesmarshall / heartbeat-for-website-blocking.service
Created July 25, 2014 15:39
A heartbeat that will be blocked and wait before it starts setting values in etcd
[Unit]
Description=heartbeat for website
BindTo=website.service
[X-Fleet]
X-ConditionMachineOf=website.service
[Service]
EnvironmentFile=$pathToBashUtilitiesFile
Environment="envFile=$pathToBashUtilitiesFile"
Environment="containerName=website$counter"
Environment="sleepTime=20"
@charlesmarshall
charlesmarshall / heartbeat-for-website.service
Created July 25, 2014 15:04
heartbeat for the simple website service
[Unit]
Description=heartbeat for website
BindTo=website.service
[X-Fleet]
X-ConditionMachineOf=website.service
[Service]
EnvironmentFile=$pathToBashUtilitiesFile
Environment="envFile=$pathToBashUtilitiesFile"
Environment="containerName=website$counter"
Environment="sleepTime=20"
@charlesmarshall
charlesmarshall / get-service-ip-and-port.sh
Last active August 29, 2015 14:04
Use a service name to find the ip & port that its running on
# $1 = service name
# $2 = service internal port
getServiceIPAndPort(){
local id=$(docker ps -a | grep "\( ${1}\)" | awk '{ print $1 }')
local port=$(docker port $id $2 | sed -r 's#0.0.0.0:##gi')
if [[ -z $port ]]; then
sleep 5
getServiceIPAndPort "${1}" "${2}"
fi
echo "${COREOS_PRIVATE_IPV4}:${port}"
@charlesmarshall
charlesmarshall / website-service-dynamic-port.service
Created July 25, 2014 14:10
basic website without hard coded port mapping
[Unit]
Description=Example website
After=etcd.service
After=docker.service
[Service]
ExecStop=/usr/bin/bash -l -c "docker stop $image_name ;"
ExecStart=/usr/bin/bash -l -c "docker pull $registry_ip:5000/$image_name ; docker run --rm --name $container_name -p 80 -i $image_name /bin/bash -l -c "service nginx start";"
@charlesmarshall
charlesmarshall / website-service-file.service
Last active August 29, 2015 14:04
basic website service file
[Unit]
Description=Example website
After=etcd.service
After=docker.service
[Service]
ExecStop=/usr/bin/bash -l -c "docker stop $image_name ;"
ExecStart=/usr/bin/bash -l -c "docker pull $registry_ip:5000/$image_name ; docker run --rm --name $container_name -p 80:80 -i $image_name /bin/bash -l -c "service nginx start";"
@charlesmarshall
charlesmarshall / coreos-simple-service-docker-service
Created July 22, 2014 12:24
CoreOS Docker registry as a service
[Unit]
Description=Docker registry
After=etcd.service
After=docker.service
[Service]
ExecStop=/usr/bin/bash -l -c "docker stop registry ;"
ExecStart=/usr/bin/bash -l -c "docker pull registry:latest ; docker run --rm --name registry -p 5000:5000 registry ;"
@charlesmarshall
charlesmarshall / coreos-simple-service-registry
Last active August 29, 2015 14:04
CoreOS setting up Docker registry
docker pull registry:latest && docker run --rm --name registry -p 5000:5000 registry