Autodeploy you docker images to AWS (git push = deploy)

So I have a lot of small project and some large. To buil in quality into my code i need to run test in my code. And my code in a prod like env.
I always uses docker so my dev env are verly like my prod.
One key thing that i do is that when i push code to my master branch i do a release do server. This is so that i can verify that everything is working and i can run test on it.


So what do you need to autodeploy you code to an AWS server.


The code and docker

I have build a small app for an hackaton i did and it here (look in the autobuild branch ) so it this code that i want to run on my server.
Login into your docker hub account go “settings > linked account and settings” and link you docker account with you dockerhub account.
Now we can make a autobuild for our code. This will when i push code to github build my docker image (I have i dockerfile in my git repo base )


Test that when you push some new stuff to git the autobuild starts (You can also trigger an build manuall from the dockerhub page)


Deploying into AWS

Now i have a aws server running and port 8555 open to that server.
download the python code from that will be my hock. When I trigger my hock it will run i script for me.

So first I need to create the  script i run i docker-compose so i create i docker-compose file


 image: mattiashem/cars
 - db
 image: mattiashem/cars
 - db
 image: mattiashem/cars
 - db
 image: mattiashem/cars
 - db
 image: mattiashem/cars-lb
 - "80:80"
 - "443:443"
 - web1
 - web2
 - web3
 - web4
 image: mongo


This docker-compose it NOT like the one i use for dev this ONLY has image and do not build aything.


This is a test this script it stops my app and pulls down the latest images, and then start my app again.

docker-compose stop
docker pull mattiashem/cars
docker pull mattiashem/bars-lb
docker-compose start
echo "Cars is now deployd" | mail -s "I have autodeployd cars"

So lets trigger it when a build is done


Start the python script for autodeploys

curl > /usr/local/bin/docker-hook; chmod +x /usr/local/bin/docker-hook

docker-hook -t asdasdhh11wweddds  -c sh /opt/matte/

Test it

curl -X POST


You should see your command bean triggerd.
It it woks stop the docker-hook and start it in background

docker-hook -t asdasdhh11wweddds  -c sh /opt/matte/ &

And go to your dockerhub and klick webhook. Give it a name and past in you url

Now you have a working push to git = deploy system