Last active
November 20, 2022 11:19
-
-
Save hasan4temp/8ca75c578299da2d9ddb6e17a66c4f99 to your computer and use it in GitHub Desktop.
docker automation script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function sed_rt() { | |
echo "$1" | sed -e 's/^ *//g' -e 's/ *$//g' | sed -n '1 p' | |
} | |
function to_num() { | |
case $1 in | |
'' | *[!0-9\.]*) echo 0 ;; | |
*) echo $1 ;; | |
esac | |
} | |
#os info | |
if [ -z "$os_name" ]; then | |
if [ -e /etc/redhat-release ]; then | |
os_name=$(sed_rt "$(cat /etc/redhat-release)") | |
elif [ -e /etc/debian_version ]; then | |
os_name=$(sed_rt "Debian $(cat /etc/debian_version)") | |
fi | |
if [ -z "$os_name" ]; then | |
os_name=$(sed_rt "$(uname -s)") | |
fi | |
fi | |
echo "os_name = $os_name" | |
if [ -z "$cpu_freq" ]; then | |
cpu_freq=$(sed_rt $(to_num "$(lscpu | grep 'CPU MHz' | awk -F\: '{ print $2 }' | sed -e 's/^ *//g' -e 's/ *$//g')")) | |
fi | |
echo "cpu_freq = $cpu_freq" | |
ram_free=$(sed_rt $(to_num "$(cat /proc/meminfo | grep ^MemFree: | awk '{ print $2 }')")) | |
echo "ram_free = $ram_free" | |
#check if docker installed if not then install | |
if [ ! -n "$(command -v docker)" ]; then | |
dnf -y update && sudo dnf install -y yum-utils && yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin && sudo systemctl enable --now docker && usermod -aG docker $USER | |
fi | |
if [ ! -n "$(command -v curl)" ]; then | |
yum install -y curl | |
fi | |
if [ ! -n "$(command -v jq)" ]; then | |
yum install -y jq | |
fi | |
if [ ! -n "$(command -v docker)" ]; then | |
fail "|\n| Error: Cannot install docker, please install the docker and run the script again\n|" | |
fi | |
curl $1 -o compose.yaml | |
mkdir -p /home/mariadb_storage && chmod 777 /home/mariadb_storage | |
echo "!!!!!!!!!!!!!!!!!!!!!Docker process listed below" | |
docker compose up -d | |
docker ps | |
echo "!!!!!!!!!!!!!!!!!!!!!!Docker installed images listed below" | |
docker images | |
#docker log | |
dockerfullid=$(docker container ls --all --quiet --no-trunc --filter "name=mariadb") | |
#docker_log=$(curl -F file=@/var/lib/docker/containers/$log_path/$log_path-json.log https://store1.gofile.io/uploadFile) | |
dockercreated=$(docker inspect $dockerfullid | grep -i created) | |
dockerstatus=$(docker ps --filter name=mariadb | awk '{print $7,$8,$9}' | tail -1) | |
echo $dockerfullid | |
echo $dockercreated | |
echo $dockerstatus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment