rebuild.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. #
  3. # Rebuild and publish all docker images.
  4. # Use the --dry-run argument to prevent the actual build process from running.
  5. #
  6. # Note: This script should not be triggered manually. Only run it in CI.
  7. #
  8. # Required env variables:
  9. #
  10. # - `DOCKER_USER`
  11. # - `DOCKER_API_KEY`
  12. set -euo pipefail
  13. SUPPORTED_BRANCH_NAMES=("master")
  14. SUPPORTED_TAG_PATTERNS=("^v2.2.[0-9][0-9]*$")
  15. IMAGE_NAME=threema/threema-web
  16. if [ "${1:-}" = "--dry-run" ]; then
  17. echo -e "Dry run\n"
  18. DOCKER='echo > docker'
  19. else
  20. DOCKER="docker"
  21. fi
  22. echo "Logging in..."
  23. $DOCKER login -u $DOCKER_USER -p $DOCKER_API_KEY
  24. echo "Create temporary directory..."
  25. mkdir -p builds
  26. echo -e "\nBuilding branches:"
  27. for branch in $SUPPORTED_BRANCH_NAMES; do
  28. echo -e "\n- $branch"
  29. git clone -b $branch . "builds/$branch"
  30. cd "builds/$branch"
  31. $DOCKER build . --no-cache -t $IMAGE_NAME:$branch
  32. $DOCKER push $IMAGE_NAME:$branch
  33. cd ../..
  34. rm -rf "builds/$branch"
  35. done
  36. echo -e "\nBuilding tags:"
  37. for pattern in $SUPPORTED_TAG_PATTERNS; do
  38. for tag in $(git tag | grep $pattern); do
  39. echo -e "\n- $tag"
  40. git clone -b $tag . "builds/$tag"
  41. cd "builds/$tag"
  42. maintag=$tag
  43. minortag=$(echo $tag | sed 's/^\(v[0-9]*\.[0-9]*\)\..*$/\1/')
  44. majortag=$(echo $tag | sed 's/^\(v[0-9]*\)\..*$/\1/')
  45. $DOCKER build . --no-cache -t $IMAGE_NAME:$tag -t $IMAGE_NAME:$minortag -t $IMAGE_NAME:$majortag
  46. $DOCKER push $IMAGE_NAME:$tag
  47. $DOCKER push $IMAGE_NAME:$minortag
  48. $DOCKER push $IMAGE_NAME:$majortag
  49. cd ../..
  50. rm -rf "builds/$tag"
  51. done
  52. done