forked from KhronosGroup/DockerContainers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-one.sh
executable file
·53 lines (46 loc) · 1.74 KB
/
build-one.sh
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
46
47
48
49
50
51
52
53
#!/bin/bash
# Copyright 2019-2024, The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0
# Pass a Dockerfile name and version (typically the year and month).
# Optionally pass the literal text "push" as third argument to publish
# the result to dockerhub.
# Any extra arguments (including the third argument if it's not "push")
# are passed to `docker build` literally.
#
# The tag portion of the name is used as the tag within the repo.
set -e
REPO="khronosgroup/docker-images"
(
cd "$(dirname "$0")"
DOCKERFILE=${1%%.Dockerfile}
VERSION=$2
shift 2
if [ "$1" == "push" ]; then
OP=$1
shift
fi
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
[ -n "$CI" ] && echo "::group::$DOCKERFILE @ $VERSION"
docker build "$@" . -f "$DOCKERFILE.Dockerfile" \
--build-arg "VERSION=$VERSION" \
--label "org.opencontainers.image.created=$BUILD_DATE" \
-t "$REPO:$DOCKERFILE" \
-t "$REPO:$DOCKERFILE.$VERSION" \
$EXTRA_DOCKER_ARGS
if [ "$OP" == "push" ]; then
docker push "$REPO:$DOCKERFILE"
docker push "$REPO:$DOCKERFILE.$VERSION"
# Show how to refer to it.
# This digest is only created by pushing to a v2 registry,
# so we can't do this reliably except in the "push" base
HASH=$(docker inspect --format='{{index .RepoDigests 0}}' "$REPO:$DOCKERFILE.$VERSION" | sed -E -n "s/.*(sha256:.*)/\1/p")
echo
echo "** To refer to this image precisely, use:"
echo " $REPO:$DOCKERFILE.$VERSION@$HASH"
else
echo
echo "** Not pushing, so no SHA256 manifest available. Until you push this image, refer to it as:"
echo " $REPO:$DOCKERFILE.$VERSION"
fi
[ -n "$CI" ] && echo "::endgroup::"
)