sudo 

###
###setup docker
###
#https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#set-up-the-repository
apt-get update
apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

apt-get update
apt-get install docker-ce

###
###setup docker-compose
###
#https://docs.docker.com/compose/install/
#this command may need updating to the latest docker version
#check https://github.com/docker/compose/releases for the current version
curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

###
###setup nginx
###
#https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#prebuilt
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key

echo "deb http://nginx.org/packages/mainline/ubuntu/ $(lsb_release -cs) nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ $(lsb_release -cs) nginx" >> /etc/apt/sources.list

apt-get remove nginx-common
apt-get update
apt-get install nginx

###
###setup elasticsearch
###
sysctl -w vm.max_map_count=262144                    #increase virtual memory
echo "" >> /etc/sysctl.conf                          #https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
mkdir -p /home/ubuntu/elastic/
mv ./elastic-docker-compose.yml /home/ubuntu/elastic/docker-compose.yml
docker-compose -f /home/ubuntu/elastic/docker-compose.yml up -d 
(crontab -l 2>/dev/null; echo "@reboot docker-compose -f /home/ubuntu/elastic/docker-compose.yml up -d") | crontab -

###
###setup nginx config
###
mkdir -p /home/ubuntu/nginx/
mv ./nginx.conf /home/ubuntu/nginx/nginx.conf
nginx -c /home/ubuntu/nginx/nginx.conf
(crontab -l 2>/dev/null; echo "@reboot nginx -c /home/ubuntu/nginx/nginx.conf") | crontab -

###
###setup small applications
###
apt-get install htop

###
###setup my applications
###
docker login -u AWS -p myPassword https://userid.dkr.ecr.region.amazonaws.com

##setup cryptocurrency exchange tracker
docker pull userid.dkr.ecr.region.amazonaws.com/cryptoexchangecurrencytracker:latest
mkdir -p /home/ubuntu/cryptoexchangecurrencytracker/data
(crontab -l 2>/dev/null; echo "@hourly docker run -d -v /home/ubuntu/cryptoexchangecurrencytracker/data:/app/Data userid.dkr.ecr.region.amazonaws.com/cryptoexchangecurrencytracker") | crontab -

##setup ismydependencysafe
docker pull userid.dkr.ecr.region.amazonaws.com/ismydependencysafe:latest
docker run -d -p 127.0.0.1:5000:80 userid.dkr.ecr.region.amazonaws.com/ismydependencysafe
(crontab -l 2>/dev/null; echo "@reboot docker run -d -p 127.0.0.1:5000:80 userid.dkr.ecr.region.amazonaws.com/ismydependencysafe") | crontab -