2018-06-14 19:19:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-05-06 22:34:25 +00:00
|
|
|
# Deployment Script for docker and all containers
|
|
|
|
|
2018-06-14 19:19:30 +00:00
|
|
|
NC='\033[0m'
|
|
|
|
|
|
|
|
RED='\033[00;31m'
|
|
|
|
GREEN='\033[00;32m'
|
|
|
|
YELLOW='\033[00;33m'
|
|
|
|
BLUE='\033[00;34m'
|
|
|
|
PURPLE='\033[00;35m'
|
|
|
|
CYAN='\033[00;36m'
|
|
|
|
LIGHTGRAY='\033[00;37m'
|
|
|
|
MAGENTA='\033[00;35m'
|
|
|
|
LRED='\033[01;31m'
|
|
|
|
LGREEN='\033[01;32m'
|
|
|
|
LYELLOW='\033[01;33m'
|
|
|
|
LBLUE='\033[01;34m'
|
|
|
|
LPURPLE='\033[01;35m'
|
|
|
|
LCYAN='\033[01;36m'
|
|
|
|
WHITE='\033[01;37m'
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-10 14:05:43 +00:00
|
|
|
## INSTALL docker-ce
|
|
|
|
read -r -p "Do you want to install docker? [y/N] " response
|
|
|
|
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
|
|
|
|
then
|
2018-06-14 19:19:30 +00:00
|
|
|
logout=1
|
2018-06-10 14:05:43 +00:00
|
|
|
curl -fsSL get.docker.com -o get-docker.sh
|
|
|
|
sudo sh get-docker.sh
|
2018-06-14 19:19:30 +00:00
|
|
|
sudo systemctl enable docker
|
2018-06-10 14:05:43 +00:00
|
|
|
else
|
|
|
|
echo -e "'no' chosen for docker installation - docker assummed to be already installed"
|
|
|
|
fi
|
|
|
|
|
2018-06-10 13:44:52 +00:00
|
|
|
## INSTALL docker-compose
|
2018-06-10 14:05:43 +00:00
|
|
|
read -r -p "Do you want to install docker-compose? [y/N] " response
|
|
|
|
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
|
|
|
|
then
|
2018-06-14 19:19:30 +00:00
|
|
|
logout=1
|
2018-06-10 14:05:43 +00:00
|
|
|
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
|
|
|
|
sudo chmod +x /usr/local/bin/docker-compose
|
|
|
|
else
|
|
|
|
echo -e "'no' chosen for docker-compose installation - docker-compose assummed to be already installed"
|
|
|
|
fi
|
2018-06-10 13:44:52 +00:00
|
|
|
|
2018-06-14 19:19:30 +00:00
|
|
|
## LOGOUT IF NEEDED
|
|
|
|
if [[ "$logout" -eq 1 ]]; then
|
|
|
|
if [[ $(whoami) != "root" ]]; then
|
|
|
|
if [[ ! $(groups $(whoami) | egrep -oh 'docker') == "docker" ]]; then
|
|
|
|
echo -e "${BLUE}your login ${YELLOW}$(whoami)${NC}${BLUE} will be added to "docker" group...${NC}"
|
|
|
|
if [[ ! $(cat /etc/group | egrep -oh 'docker:') == "docker:" ]]; then
|
|
|
|
sudo groupadd docker
|
|
|
|
echo -e "${BLUE}creating group: ${YELLOW}docker${NC}${BLUE}${NC}"
|
|
|
|
fi
|
|
|
|
sudo usermod -aG docker $(whoami)
|
|
|
|
echo -e "${BLUE}you need to logout and login again...${NC}"
|
|
|
|
echo -e "${BLUE}start the same script and skip docker related part (answer 'no' two times).${NC}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo -e "${YELLOW}docker was installed, you need to logout and login${NC}"
|
|
|
|
echo -e "${RED}login again and start deploy script without docker* installation part (answer no)${NC}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2018-06-10 13:44:52 +00:00
|
|
|
# START docker-compose
|
2018-06-17 11:05:55 +00:00
|
|
|
docker-compose up -d --remove-orphans
|
2018-06-10 13:44:52 +00:00
|
|
|
|
|
|
|
# ADD DATASOURCES AND DASHBOARDS
|
2018-06-14 19:19:30 +00:00
|
|
|
sudo systemctl restart docker
|
2018-06-10 13:44:52 +00:00
|
|
|
docker-compose up -d
|
|
|
|
|
|
|
|
# ADD DATASOURCES AND DASHBOARDS
|
2018-06-14 19:19:30 +00:00
|
|
|
sleep 5
|
2018-06-17 11:05:55 +00:00
|
|
|
echo "adding datasources..."
|
|
|
|
docker exec -it -u 0 grafana /var/lib/grafana/ds/add_datasources.sh
|
|
|
|
|
2018-06-10 13:44:52 +00:00
|
|
|
echo "adding dashboards..."
|
|
|
|
docker exec -it -u 0 grafana /var/lib/grafana/ds/add_dashboards.sh
|
|
|
|
|
2018-06-17 11:05:55 +00:00
|
|
|
|
2018-06-17 15:06:21 +00:00
|
|
|
### NOW LET'S SECURE GRAFANA
|
|
|
|
### STOPPING and REMOVING GRAFANA CONTAINER
|
|
|
|
#echo -e "stopping & removing grafana container"
|
|
|
|
#container_id=$(docker container ls | grep grafana| awk '{print $1}')
|
|
|
|
#docker stop $container_id
|
|
|
|
#docker rm $container_id
|
2018-06-19 15:12:39 +00:00
|
|
|
#find grafana -name '*.pem' -exec chmod 666 {} \;
|
2018-06-17 15:06:21 +00:00
|
|
|
#
|
|
|
|
## REPLACING HTTP with HTTPS
|
|
|
|
#echo -e "changing http to https"
|
|
|
|
#sed -i 's/GF_SERVER_PROTOCOL: "http"/GF_SERVER_PROTOCOL: "https"/g' docker-compose.yml
|
|
|
|
#docker-compose up -d grafana
|
|
|
|
#echo -e "reverting: changing https to http"
|
|
|
|
#sed -i 's/GF_SERVER_PROTOCOL: "https"/GF_SERVER_PROTOCOL: "http"/g' docker-compose.yml
|