build 1.4 KB

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