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 https://github.com/mattiashem/cars (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 https://github.com/schickling/docker-hook 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
web1: image: mattiashem/cars links: - db web2: image: mattiashem/cars links: - db web3: image: mattiashem/cars links: - db web4: image: mattiashem/cars links: - db lb: image: mattiashem/cars-lb ports: - "80:80" - "443:443" links: - web1 - web2 - web3 - web4 db: 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.
#!/bin/bash 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" firstname.lastname@example.org
So lets trigger it when a build is done
Start the python script for autodeploys
curl https://raw.githubusercontent.com/schickling/docker-hook/master/docker-hook > /usr/local/bin/docker-hook; chmod +x /usr/local/bin/docker-hook docker-hook -t asdasdhh11wweddds -c sh /opt/matte/run.sh
curl -X POST http://luckyluke.madeatfareoffice.com:8555/asdasdhh11wweddds
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/run.sh &
And go to your dockerhub and klick webhook. Give it a name and past in you url http://luckyluke.madeatfareoffice.com:8555/asdasdhh11wweddds
Now you have a working push to git = deploy system