build 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. echo ">>> Building images..."
  3. # shellcheck source=arches.sh
  4. source ./hooks/arches.sh
  5. if [[ -z "${SOURCE_COMMIT}" ]]; then
  6. # This var is typically predefined by Docker Hub, but it won't be
  7. # when testing locally.
  8. SOURCE_COMMIT="$(git rev-parse HEAD)"
  9. fi
  10. # Construct a version string in the style of `build.rs`.
  11. GIT_EXACT_TAG="$(git describe --tags --abbrev=0 --exact-match 2>/dev/null)"
  12. if [[ -n "${GIT_EXACT_TAG}" ]]; then
  13. SOURCE_VERSION="${GIT_EXACT_TAG}"
  14. else
  15. GIT_LAST_TAG="$(git describe --tags --abbrev=0)"
  16. SOURCE_VERSION="${GIT_LAST_TAG}-${SOURCE_COMMIT:0:8}"
  17. fi
  18. LABELS=(
  19. # https://github.com/opencontainers/image-spec/blob/master/annotations.md
  20. org.opencontainers.image.created="$(date --utc --iso-8601=seconds)"
  21. org.opencontainers.image.documentation="https://github.com/dani-garcia/vaultwarden/wiki"
  22. org.opencontainers.image.licenses="AGPL-3.0-only"
  23. org.opencontainers.image.revision="${SOURCE_COMMIT}"
  24. org.opencontainers.image.source="${SOURCE_REPOSITORY_URL}"
  25. org.opencontainers.image.url="https://github.com/dani-garcia/vaultwarden"
  26. org.opencontainers.image.version="${SOURCE_VERSION}"
  27. )
  28. LABEL_ARGS=()
  29. for label in "${LABELS[@]}"; do
  30. LABEL_ARGS+=(--label "${label}")
  31. done
  32. # Check if DOCKER_BUILDKIT is set, if so, use the Dockerfile.buildkit as template
  33. if [[ -n "${DOCKER_BUILDKIT}" ]]; then
  34. buildkit_suffix=.buildkit
  35. fi
  36. set -ex
  37. for arch in "${arches[@]}"; do
  38. docker build \
  39. "${LABEL_ARGS[@]}" \
  40. -t "${DOCKER_REPO}:${DOCKER_TAG}-${arch}" \
  41. -f "docker/${arch}/Dockerfile${buildkit_suffix}${distro_suffix}" \
  42. .
  43. done