aboutsummaryrefslogtreecommitdiff
path: root/hooks/build
blob: f18c58bf904659ac1ca23570bb93b13b5d50e363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

echo ">>> Building images..."

source ./hooks/arches.sh

if [[ -z "${SOURCE_COMMIT}" ]]; then
    # This var is typically predefined by Docker Hub, but it won't be
    # when testing locally.
    SOURCE_COMMIT="$(git rev-parse HEAD)"
fi

# Construct a version string in the style of `build.rs`.
GIT_EXACT_TAG="$(git describe --tags --abbrev=0 --exact-match 2>/dev/null)"
if [[ -n "${GIT_EXACT_TAG}" ]]; then
    SOURCE_VERSION="${GIT_EXACT_TAG}"
else
    GIT_LAST_TAG="$(git describe --tags --abbrev=0)"
    SOURCE_VERSION="${GIT_LAST_TAG}-${SOURCE_COMMIT:0:8}"
fi

LABELS=(
    # https://github.com/opencontainers/image-spec/blob/master/annotations.md
    org.opencontainers.image.created="$(date --utc --iso-8601=seconds)"
    org.opencontainers.image.documentation="https://github.com/dani-garcia/vaultwarden/wiki"
    org.opencontainers.image.licenses="GPL-3.0-only"
    org.opencontainers.image.revision="${SOURCE_COMMIT}"
    org.opencontainers.image.source="${SOURCE_REPOSITORY_URL}"
    org.opencontainers.image.url="https://hub.docker.com/r/${DOCKER_REPO#*/}"
    org.opencontainers.image.version="${SOURCE_VERSION}"
)
LABEL_ARGS=()
for label in "${LABELS[@]}"; do
    LABEL_ARGS+=(--label "${label}")
done

set -ex

for arch in "${arches[@]}"; do
    docker build \
           "${LABEL_ARGS[@]}" \
           -t "${DOCKER_REPO}:${DOCKER_TAG}-${arch}" \
           -f docker/${arch}/Dockerfile${distro_suffix} \
           .
done