Skip to content

Instantly share code, notes, and snippets.

@jinnabaalu
Last active March 30, 2017 09:34
Show Gist options
  • Save jinnabaalu/bad9d60458c7cb69c0d42e1c9204b00d to your computer and use it in GitHub Desktop.
Save jinnabaalu/bad9d60458c7cb69c0d42e1c9204b00d to your computer and use it in GitHub Desktop.

#CD#

Checkout the code

RUn Unit Test

Build

Run Functional Tests

Push To the Registry

Deploy to the Production like Cluster

Run Production Like Test

Deploy to the production cluster

Run Production Tests

#Docker Machine with AWS#

set -e
COMMON_OPTS=" --amazonec2-zone a --amazonec2-vpc-id vpc-cbe6c1ad \
--amazonec2-security-group docker-machine "

docker-machine rm -f tokenserver
docker-machine rm -f manager0
docker-machine rm -f worker0
docker-machine rm -f worker1

echo "---- creating swarm token server"
docker-machine create -d amazonec2 $COMMON_OPTS tokenserver
eval $(docker-machine env tokenserver)
swarm_token=$(docker run swarm create)
echo "-- swarm token is $swarm_token"
SWARM_OPTS=" --swarm --swarm-discovery token://${swarm_token} "
echo "---- creating swarm manager"
docker-machine create -d amazonec2 --amazonec2-access-key $AWS_ACCESS_KEY_ID --amazonec2-secret-key $AWS_SECRET_ACCESS_KEY --amazonec2-vpc-id $AWS_VPC_ID \
                $SWARM_OPTS \
                --swarm-master \
                manager0

echo "---- creating swarm workers"

docker-machine create -d amazonec2 --amazonec2-access-key $AWS_ACCESS_KEY_ID --amazonec2-secret-key $AWS_SECRET_ACCESS_KEY --amazonec2-vpc-id $AWS_VPC_ID \
               $SWARM_OPTS \
               worker0

docker-machine create -d amazonec2 --amazonec2-access-key $AWS_ACCESS_KEY_ID --amazonec2-secret-key $AWS_SECRET_ACCESS_KEY --amazonec2-vpc-id $AWS_VPC_ID \
               $SWARM_OPTS \
               worker1

docker-machine ls

echo "---- to connect to the swarm manager, we will run the following: \
eval $(docker-machine env --swarm manager0)"
eval $(docker-machine env --swarm manager0)

echo "---- now we run a sample Nginx application on manager0"
docker run -d -p 8080:80 nginx:latest

echo "---- the container has been started. details of the worker where its running are printed below:"
docker ps -a

MANAGER0_IP=$(docker-machine inspect manager0 -f "{{ .Driver.IPAddress }}")
echo "---- manager0 IP address is at $MANAGER0_IP. "



echo "run virtualizer"
docker run -it -d -p 7002:7002 -v /var/run/docker.sock:/var/run/docker.sock --name visualizer manomarks/visualizer




docker-machine ls

docker-machine env manager0 

docker node ls

docker swarm init

docker swarm join \
    --token SWMTKN-1-10sjjedipx2tp25jrxcwuosq12hak16rj481se5k2gdbhhlz8g-49p7rif4w7eokc9au1kg48wt3 \
    --advertise-addr $(docker-machine ip worker0) \
    172.30.0.101:2377

docker swarm join \
    --token SWMTKN-1-10sjjedipx2tp25jrxcwuosq12hak16rj481se5k2gdbhhlz8g-49p7rif4w7eokc9au1kg48wt3 \
    --advertise-addr $(docker-machine ip worker1) \
    172.30.0.101:2377



echo "registry : manager0 : registry path : /home/ubuntu/ws-img-registry/ and port to see the registry : 500"

echo "creating the ws registry folder and assigning to the environment variable REGISTRY_PATH"

mkdir ws-img-registry

docker service create --name wsregistry -p 5000:5000 --mount "type=bind,source=/home/ubuntu/ws-img-registry,target=/var/lib/registry" registry

echo "successfully created the registry with the name wsregistry"


echo "create the network"

docker network create --driver overlay proxy

docker network create --driver overlay 

docker service ls


Step 1: Install docker

https://docs.docker.com/engine/installation/linux/ubuntu/#install-using-the-repository

Step 2: Install Docker Visualizer

https://github.com/ManoMarks/docker-swarm-visualizer

Based on the requirement we can set the port to work

Find the dirtibuttion of the ubuntu

cat /etc/*-release

#Continuous Deployment with Jenkins and Docker Swarm Create Virtal box before creating the Docker machine

sudo apt-get install virtualbox

Docker Swarm

Nodes Setup

create the machines using

for i in 1 2 3 ; do docker-machine create -d virtualbox swarm-$i done

Create Visualizer

docker service create
--name=viz
--publish=8080:8080/tcp
--constraint=node.role==manager
--mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock
manomarks/visualizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment