In this repo I'm tryin to implement feature branch deployment, along with odoo/react integration.
- Odoo
- ReactJS
- React Redux Store
- Jenkins
- Postgres
- Nginx Proxy
- Docker
- Amazon EC2
- Install Jenkins
- Install these plugins for jenkins [SSH2 Easy Plugin, SSH Agent, Github plugin]
- Add you Amazon EC2 credentials by going to jenkins -> credentials -> Stores scoped -> Add Credentials
- Kind of credentials should be SSH Username with private key
- Create SSH remote hosts by going to jenkins configuration -> SSH remote hosts section
- Create free style Jenkins Project
- Configure the project and connect it to your project repo and set Branches to build to /feature/
- Add build step "Execute shell script on remote host using ssh"
- Paste the following bash script
branch=$(echo "$GIT_BRANCH" | sed 's/origin\///g')
tag=$(echo "$GIT_BRANCH" | sed 's/[^0-9]*//g')
echo "branch=$branch, tag=$tag"
git clone https://[YOUR GITHUB AUTH]@github.com/[YOUR GITHUB REPO PATH URL] $tag
if [ $? -eq 0 ]; then
cd $tag
sudo touch .env
sudo echo "tag=$tag" > .env
cd frontend
sudo touch .env
sudo echo -e "DANGEROUSLY_DISABLE_HOST_CHECK=true\nREACT_APP_TAG=$tag" > .env
cd ..
sudo docker container inspect proxy > /dev/null 2>&1 && sudo docker rm -f proxy
[[ $(sudo docker ps -f "name=proxy" --format '{{.Names}}') == "proxy" ]] || sudo docker run --network='nginx-proxy' --name proxy -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
[[ $(sudo docker ps -f "name=db" --format '{{.Names}}') == "db" ]] || sudo docker run --network='nginx-proxy' --name db -d -e POSTGRES_PASSWORD=odoo -e POSTGRES_USER=odoo -e POSTGRES_DB=postgres postgres:10
sudo docker-compose build
sudo docker-compose up -d
else
cd $tag
git pull
sudo docker-compose down
sudo docker-compose build
sudo docker container inspect proxy > /dev/null 2>&1 && sudo docker rm -f proxy
[[ $(sudo docker ps -f "name=proxy" --format '{{.Names}}') == "proxy" ]] || sudo docker run --network='nginx-proxy' --name proxy -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
[[ $(sudo docker ps -f "name=db" --format '{{.Names}}') == "db" ]] || sudo docker run --network='nginx-proxy' --name db -d -e POSTGRES_PASSWORD=odoo -e POSTGRES_USER=odoo -e POSTGRES_DB=postgres postgres:10
sudo docker-compose up -d
fi
- Save
- Login to your github repo settings -> webhooks-> add new webhook-> set hook Payload URL to http[s]://[JenkinsURL]/github-webhook/ and with preference Just the push event.
- Login to your AWS EC2 instance
- install docker by running the following
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install docker-compose
- create default network for our apps to allow container to communicate
sudo docker network create nginx-proxy
-
Create branch and push anything to it, please not that branch name should be in this pattern feature|hotfix|bugfix/[JIRA-TICKET-NUMBER] for example feature/LGR-675 or hotfix/LGR-754
-
In you domain DNS management, create A record to forward all subdomains to AWS EC2 ip instance
- Navigate to, [JIRE-TICKET-NUMBER].react.[YOUR DOMAIN] to see react interface, for example 432.react.mydomain.com
- Navigate to, [JIRE-TICKET-NUMBER].odoo.[YOUR DOMAIN] to see odoo interface, for example 432.odoo.mydomain.com
- create new database in odoo with name [TICKET-NUMBER], for example 432