podman-bake.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env bash
  2. # Determine the basedir of this script.
  3. # It should be located in the same directory as the docker-bake.hcl
  4. # This ensures you can run this script from both inside and outside of the docker directory
  5. BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")" || exit; pwd)/$(basename "${SP}")")
  6. # Load build env's
  7. source "${BASEDIR}/bake_env.sh"
  8. # Check if a target is given as first argument
  9. # If not we assume the defaults and pass the given arguments to the podman command
  10. case "${1}" in
  11. alpine*|debian*)
  12. TARGET="${1}"
  13. # Now shift the $@ array so we only have the rest of the arguments
  14. # This allows us too append these as extra arguments too the podman buildx build command
  15. shift
  16. ;;
  17. esac
  18. LABEL_ARGS=(
  19. --label org.opencontainers.image.description="Unofficial Bitwarden compatible server written in Rust"
  20. --label org.opencontainers.image.licenses="AGPL-3.0-only"
  21. --label org.opencontainers.image.documentation="https://github.com/dani-garcia/vaultwarden/wiki"
  22. --label org.opencontainers.image.url="https://github.com/dani-garcia/vaultwarden"
  23. --label org.opencontainers.image.created="$(date --utc --iso-8601=seconds)"
  24. )
  25. if [[ -n "${SOURCE_REPOSITORY_URL}" ]]; then
  26. LABEL_ARGS+=(--label org.opencontainers.image.source="${SOURCE_REPOSITORY_URL}")
  27. fi
  28. if [[ -n "${SOURCE_COMMIT}" ]]; then
  29. LABEL_ARGS+=(--label org.opencontainers.image.revision="${SOURCE_COMMIT}")
  30. fi
  31. if [[ -n "${SOURCE_VERSION}" ]]; then
  32. LABEL_ARGS+=(--label org.opencontainers.image.version="${SOURCE_VERSION}")
  33. fi
  34. # Check if and which --build-arg arguments we need to configure
  35. BUILD_ARGS=()
  36. if [[ -n "${DB}" ]]; then
  37. BUILD_ARGS+=(--build-arg DB="${DB}")
  38. fi
  39. if [[ -n "${CARGO_PROFILE}" ]]; then
  40. BUILD_ARGS+=(--build-arg CARGO_PROFILE="${CARGO_PROFILE}")
  41. fi
  42. if [[ -n "${VW_VERSION}" ]]; then
  43. BUILD_ARGS+=(--build-arg VW_VERSION="${VW_VERSION}")
  44. fi
  45. # Set the default BASE_TAGS if non are provided
  46. if [[ -z "${BASE_TAGS}" ]]; then
  47. BASE_TAGS="testing"
  48. fi
  49. # Set the default CONTAINER_REGISTRIES if non are provided
  50. if [[ -z "${CONTAINER_REGISTRIES}" ]]; then
  51. CONTAINER_REGISTRIES="vaultwarden/server"
  52. fi
  53. # Check which Dockerfile we need to use, default is debian
  54. case "${TARGET}" in
  55. alpine*)
  56. BASE_TAGS="${BASE_TAGS}-alpine"
  57. DOCKERFILE="Dockerfile.alpine"
  58. ;;
  59. *)
  60. DOCKERFILE="Dockerfile.debian"
  61. ;;
  62. esac
  63. # Check which platform we need to build and append the BASE_TAGS with the architecture
  64. case "${TARGET}" in
  65. *-arm64)
  66. BASE_TAGS="${BASE_TAGS}-arm64"
  67. PLATFORM="linux/arm64"
  68. ;;
  69. *-armv7)
  70. BASE_TAGS="${BASE_TAGS}-armv7"
  71. PLATFORM="linux/arm/v7"
  72. ;;
  73. *-armv6)
  74. BASE_TAGS="${BASE_TAGS}-armv6"
  75. PLATFORM="linux/arm/v6"
  76. ;;
  77. *)
  78. BASE_TAGS="${BASE_TAGS}-amd64"
  79. PLATFORM="linux/amd64"
  80. ;;
  81. esac
  82. # Be verbose on what is being executed
  83. set -x
  84. # Build the image with podman
  85. # We use the docker format here since we are using `SHELL`, which is not supported by OCI
  86. # shellcheck disable=SC2086
  87. podman buildx build \
  88. --platform="${PLATFORM}" \
  89. --tag="${CONTAINER_REGISTRIES}:${BASE_TAGS}" \
  90. --format=docker \
  91. "${LABEL_ARGS[@]}" \
  92. "${BUILD_ARGS[@]}" \
  93. --file="${BASEDIR}/${DOCKERFILE}" "$@" \
  94. "${BASEDIR}/.."