Skip to content

Commit

Permalink
treehouses services with check_space (fixes #621) (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjong authored Feb 6, 2020
1 parent c392425 commit a0e9dd5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions modules/services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function services {
up)
case "$service_name" in
planet)
check_space "treehouses/planet"
if [ -f /srv/planet/pwd/credentials.yml ]; then
docker-compose -f /srv/planet/planet.yml -f /srv/planet/volumes.yml -f /srv/planet/pwd/credentials.yml -p planet up -d
else
Expand All @@ -89,50 +90,50 @@ function services {
check_tor "80"
;;
kolibri)
check_space "treehouses/kolibri"
bash $TEMPLATES/services/kolibri/kolibri_yml.sh
echo "yml file created"

docker-compose -f /srv/kolibri/kolibri.yml -p kolibri up -d
echo "kolibri built and started"
check_tor "8080"
;;
nextcloud)
check_space "library/nextcloud"
bash $TEMPLATES/services/nextcloud/nextcloud_yml.sh
echo "yml file created"

docker-compose -f /srv/nextcloud/nextcloud.yml -p nextcloud up -d
echo "nextcloud built and started"
check_tor "8081"
;;
pihole)
check_space "pihole/pihole"
bash $TEMPLATES/services/pihole/pihole_yml.sh
echo "yml file created"

service dnsmasq stop
docker-compose -f /srv/pihole/pihole.yml -p pihole up -d
echo "pihole built and started"
check_tor "8053"
;;
moodle)
check_space "treehouses/moodle"
bash $TEMPLATES/services/moodle/moodle_yml.sh
echo "yml file created"

docker-compose -f /srv/moodle/moodle.yml -p moodle up -d
echo "moodle built and started"
check_tor "8082"
;;
privatebin)
check_space "treehouses/privatebin"
bash $TEMPLATES/services/privatebin/privatebin_yml.sh
echo "yml file created"

docker-compose -f /srv/privatebin/privatebin.yml -p privatebin up -d
echo "privatebin built and started"
check_tor "8083"
;;
portainer)
check_space "portainer/portainer"
bash $TEMPLATES/services/portainer/portainer_yml.sh
echo "yml file created"

docker-compose -f /srv/portainer/portainer.yml -p portainer up -d
echo "portainer built and started"
check_tor "9000"
Expand Down Expand Up @@ -369,6 +370,18 @@ function find_available_services {
echo "$service [$available_formats]"
}

function check_space {
image_size=$(curl -s -H "Authorization: JWT " "https://hub.docker.com/v2/repositories/${1}/tags/?page_size=100" | jq -r '.results[] | select(.name == "latest") | .images[0].size')
free_space=$(df -Ph /var/lib/docker | awk 'END {print $4}' | numfmt --from=iec)

if (( image_size > free_space )); then
echo "image size:" $image_size
echo "free space:" $free_space
echo "not enough free space"
exit 1
fi
}

# tor status and port check
function check_tor {
port="$1"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.13.9",
"version": "1.13.10",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
"bin": {
Expand Down

0 comments on commit a0e9dd5

Please sign in to comment.