Last active
August 29, 2015 14:16
-
-
Save philcryer/1fb46d3d5e883d91f920 to your computer and use it in GitHub Desktop.
A logstash-forwarder script that does a docker build, creates new certs, names the container from the working dir, finds the correct image name and does a docker run on it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ ! $1 ]; then | |
| echo "! fail - no logdestination at $1 - need hostname:port of log server"; exit 1 | |
| fi | |
| if [ ! -f Dockerfile ]; then | |
| echo "! fail - no Dockerfile file found"; exit 1 | |
| fi | |
| docker_name=`printf '%s\n' "${PWD##*/}"` | |
| example_conf="$docker_name.conf.example" | |
| if [ ! -f $docker_name.conf.example ]; then | |
| echo "! fail - no $example_conf file found "; exit 1 | |
| fi | |
| new_conf="$docker_name.conf" | |
| cat $example_conf | sed -e "s/@DOCKER_NAME@/$docker_name/" | sed -e "s/@REMOTE_NAME@/$1/" > $new_conf | |
| echo " -> creating certs..." | |
| openssl req -x509 -batch -nodes -newkey rsa:2048 -keyout $docker_name.key -out $docker_name.crt | |
| echo " -> uploading certs to consul..." | |
| key_value_url="http://localhost/consul-8500" | |
| echo " -> crt..." | |
| curl -L $key_value_url/v1/kv/services/logging/logstash/ssl_certificate -XPUT --data-urlencode $docker_name.crt | |
| echo " -> key..." | |
| curl -L $key_value_url/v1/kv/services/logging/logstash/ssl_private_key -XPUT --data-urlencode $docker_name.key | |
| echo " -> building docker image from Dockerfile..." | |
| docker build . | |
| image_id=`docker images |head -n2 | tail -n1 | awk '{print $3}'` | |
| echo " -> running docker container..." | |
| pit=`date +'%Y%m%d-%H%M%S-%N'` | |
| docker run -d --name $docker_name-$pit -v /var/lib/docker:/var/lib/docker:ro -v /var/run/docker.sock:/var/run/docker.sock $image_id -logstash="$1" | |
| echo " -> cleanup..." | |
| rm $new_conf; rm $docker_name.crt; rm $docker_name.key | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment