dottie 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. set -e -o errexit -o nounset -o pipefail
  3. declare project_root="${PWD}"
  4. declare user="${PF_USER:=www-data}"
  5. if command -v git &>/dev/null; then
  6. project_root=$(git rev-parse --show-toplevel)
  7. fi
  8. declare -r release="${DOTTIE_VERSION:-latest}"
  9. declare -r update_check_file="/tmp/.dottie-update-check" # file to check age of since last update
  10. declare -i update_check_max_age=$((8 * 60 * 60)) # 8 hours between checking for dottie version
  11. declare -i update_check_cur_age=$((update_check_max_age + 1)) # by default the "update" event should happen
  12. # default [docker run] flags
  13. declare -a flags=(
  14. --rm
  15. --interactive
  16. --tty
  17. --user "${user}"
  18. --env TERM
  19. --env COLORTERM
  20. --volume "${project_root}:/var/www"
  21. --workdir /var/www
  22. )
  23. # if update file exists, find its age since last modification
  24. if [[ -f "${update_check_file}" ]]; then
  25. now=$(date +%s)
  26. changed=$(date -r "${update_check_file}" +%s)
  27. update_check_cur_age=$((now - changed))
  28. fi
  29. # if update file is older than max allowed poll for new version of dottie
  30. if [[ $update_check_cur_age -gt $update_check_max_age ]]; then
  31. flags+=(--pull always)
  32. touch "${update_check_file}"
  33. fi
  34. # run dottie
  35. exec docker run "${flags[@]}" "ghcr.io/jippi/dottie:${release}" "$@"