deploy.functions 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- mode:sh -*-
  2. function fetch_updates() {
  3. cd ${masterdir}/
  4. local beforefetch=$(git rev-parse HEAD)
  5. git fetch origin
  6. local afterfetch=$(git rev-parse origin/deploy)
  7. if [[ ${beforefetch} == ${afterfetch} ]]; then
  8. exit 0
  9. fi
  10. }
  11. function find_commitids() {
  12. cd ${masterdir}
  13. OLDHEAD=$(git rev-parse HEAD)
  14. NEWHEAD=$(git rev-parse origin/deploy)
  15. }
  16. function check_commit_signature() {
  17. cd ${masterdir}
  18. git config --local gpg.program "${scriptsdir}/gpgverify"
  19. if ! SIGNKEY=$(git verify-commit --raw ${NEWHEAD} 2>&1 | awk '/VALIDSIG/ {print $NF}'); then
  20. log_error "{NEWHEAD} is not signed correctly"
  21. exit 3
  22. fi
  23. if [[ -z ${DEPLOY_KEYS[${SIGNKEY}]} ]]; then
  24. log_error "{NEWHEAD} signed by ${SIGNKEY} which is not allowed to deploy code"
  25. exit 4
  26. fi
  27. }
  28. function check_for_db_update() {
  29. # Check: Do we have a DB Upgrade?
  30. if [[ -n ${NEEDDB} ]]; then
  31. NEWDBVER=$(GIT_DIR=${masterdir}/.git git ls-tree origin/deploy dak/dakdb/|grep -v '__init__.py'|sort -V -k 4|tail -n 1)
  32. NEWDBVER=${NEWDBVER##*update}
  33. declare -r NEWDBVER=${NEWDBVER%%.py}
  34. fi
  35. if [[ ${OLDDBVER} -ne ${NEWDBVER} ]] && [[ -z ${FORCETHISDAMNUPGRADEIKNOWWHATIDOIHOPE:-""} ]]; then
  36. # Differing versions and no FORCETHISDAMNUPGRADEIKNOWWHATIDOIHOPE variable, break
  37. log_error "Database update from ${OLDDBVER} to ${NEWDBVER} required, will not update dak code on ${HOSTNAME} unless told with FORCETHISDAMNUPGRADEIKNOWWHATIDOIHOPE=1 in the environment"
  38. exit 21
  39. fi
  40. }
  41. function check_ancestor() {
  42. cd ${masterdir}
  43. if ! git merge-base --is-ancestor ${OLDHEAD} ${NEWHEAD}; then
  44. log_error "Running code HEAD ${OLDHEAD} is not an ancestor of newly-to-deploy HEAD ${NEWHEAD}, refusing to update"
  45. exit 2
  46. fi
  47. }
  48. function update_masterdir() {
  49. cd ${masterdir}
  50. # We do not want local changes
  51. git stash save --include-untracked --all "Update for commitid ${NEWHEAD}"
  52. # And switch to the commit we just verified
  53. git checkout ${NEWHEAD}
  54. }
  55. function cleanlogs() {
  56. find ${logdir} -mtime +60 -delete
  57. }