Skip to content

Instantly share code, notes, and snippets.

View pranavcode's full-sized avatar

Pranav Kulkarni pranavcode

View GitHub Profile
@pranavcode
pranavcode / django-consul-kv-store.sh
Created April 1, 2019 14:47
Velotio - HashiCorp Consul Part 2 - Configuration of Django App with Consul KV using Consul's HTTP API
# Flag to run Django app in debug mode
curl -X PUT -d 'True' consul_server:8500/v1/kv/web/debug
# Dynamic entries into Django app configuration
# to denote allowed set of hosts
curl -X PUT -d 'localhost, 33.10.0.100' consul_server:8500/v1/kv/web/allowed_hosts
# Dynamic entries into Django app configuration
# to denote installed apps
curl -X PUT -d 'tweetapp' consul_server:8500/v1/kv/web/installed_apps
@pranavcode
pranavcode / install-python-consul.sh
Created April 1, 2019 14:39
Velotio - HashiCorp Consul Part 2 - Configuration of Django App with Consul KV using Python library python-consul
$ pipenv shell
Launching subshell in virtual environment…
. /home/pranav/.local/share/virtualenvs/tweeter-PYSn2zRU/bin/activate
$ . /home/pranav/.local/share/virtualenvs/tweeter-PYSn2zRU/bin/activate
(tweeter) $ pipenv install python-consul
Installing python-consul…
Adding python-consul to Pipfile's [packages]…
✔ Installation Succeeded
@pranavcode
pranavcode / mongo-service-discovery
Created April 1, 2019 11:52
Velotio - HashiCorp Consul Part 2 - Discovering MongoDB Primary node from Django container
root@82857c424b15:/web/tweeter# dig @127.0.0.1 mongo-primary.service.consul
; <<>> DiG 9.10.3-P4-Debian <<>> @127.0.0.1 mongo-primary.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8369
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 2
;; WARNING: recursion requested but not available
@pranavcode
pranavcode / docker-compose.yml
Created April 1, 2019 11:29
Velotio - HashiCorp Consul Part 2 - Docker Compose file that runs complete application setup
version: "3.6"
services:
consul_server:
build:
context: consul_server
dockerfile: Dockerfile
image: consul_server
ports:
@pranavcode
pranavcode / consul_server.Dockerfile
Created April 1, 2019 11:23
Velotio - HashiCorp Consul Part 2 - Dockerfile for Consul Server Docker Container
FROM ubuntu:18.04
RUN apt-get update && \
apt-get install -y \
bash curl nano net-tools zip unzip \
jq dnsutils iputils-ping
ADD https://releases.hashicorp.com/consul/1.4.4/consul_1.4.4_linux_amd64.zip /tmp/consul.zip
RUN cd /bin && unzip /tmp/consul.zip && chmod +x /bin/consul && rm /tmp/consul.zip
@pranavcode
pranavcode / django.Dockerfile
Created April 1, 2019 11:16
Velotio - HashiCorp Consul Part 2 - Dockerfile for Django Web App Docker Container
FROM python:3.7
RUN apt-get update && \
apt-get install -y \
bash curl nano net-tools zip unzip \
jq dnsutils iputils-ping
# Python Environment Setup
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
@pranavcode
pranavcode / django-procfile
Created April 1, 2019 11:14
Velotio - HashiCorp Consul Part 2 - Procfile for Django App Docker Container
# Django
django: /web/tweeter.sh
# Consul Client Agent
consul: /opt/consul.sh
@pranavcode
pranavcode / mongo.Dockerfile
Created April 1, 2019 10:55
Velotio - HashiCorp Consul Part 2 - Dockerfile for MongoDB Docker Container
FROM ubuntu:18.04
RUN apt-get update && \
apt-get install -y \
bash curl nano net-tools zip unzip \
jq dnsutils iputils-ping
# Install MongoDB
RUN apt-get install -y mongodb
@pranavcode
pranavcode / mongo-procfile
Created April 1, 2019 10:09
Velotio - HashiCorp Consul Part 2 - Procfile for MongoDB Docker Container
# Mongo
mongo: /opt/mongo.sh
# Consul Client Agent
consul: /opt/consul.sh
# Consul Client Health Checks
consul_check: while true; do /opt/checks_toggler.sh && sleep 10; done
@pranavcode
pranavcode / consul_server.sh
Created April 1, 2019 09:46
Velotio - HashiCorp Consul Part 2 - Consul Server - Run Consul agent in server mode
consul agent -server \
-bind 33.10.0.2 \
-advertise 33.10.0.2 \
-node consul_server \
-client 0.0.0.0 \
-dns-port 53 \
-data-dir /data \
-ui -bootstrap