This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
/
build.sh
executable file
·111 lines (103 loc) · 3 KB
/
build.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
#
# Copyright (c) 2019-2022 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
set -e
REGISTRY="quay.io"
ORGANIZATION="eclipse"
TAG="next"
TARGET="registry" # or offline-registry
DOCKERFILE="./build/dockerfiles/Dockerfile"
USAGE="
Usage: ./build.sh [OPTIONS]
Options:
--help
Print this message.
--tag, -t [TAG]
Docker image tag to be used for image; default: 'next'
--registry, -r [REGISTRY]
Docker registry to be used for image; default 'quay.io'
--organization, -o [ORGANIZATION]
Docker image organization to be used for image; default: 'eclipse'
--offline
Build offline version of registry, with all artifacts included
cached in the registry; disabled by default.
--rhel
Build using the rhel.Dockerfile (UBI images) instead of default
"
function print_usage() {
echo -e "$USAGE"
}
function parse_arguments() {
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-t|--tag)
TAG="$2"
shift; shift;
;;
-r|--registry)
REGISTRY="$2"
shift; shift;
;;
-o|--organization)
ORGANIZATION="$2"
shift; shift;
;;
--offline)
TARGET="offline-registry"
shift
;;
--rhel)
DOCKERFILE="./build/dockerfiles/rhel.Dockerfile"
shift
;;
*)
print_usage
exit 0
esac
done
}
parse_arguments "$@"
BUILD_COMMAND="build"
if [[ -z $BUILDER ]]; then
echo "BUILDER not specified, trying with podman"
BUILDER=$(command -v podman || true)
if [[ ! -x $BUILDER ]]; then
echo "[WARNING] podman is not installed, trying with buildah"
BUILDER=$(command -v buildah || true)
if [[ ! -x $BUILDER ]]; then
echo "[WARNING] buildah is not installed, trying with docker"
BUILDER=$(command -v docker || true)
if [[ ! -x $BUILDER ]]; then
echo "[ERROR] neither docker, buildah, nor podman are installed. Aborting"; exit 1
fi
else
BUILD_COMMAND="bud"
fi
fi
else
if [[ ! -x $(command -v "$BUILDER" || true) ]]; then
echo "Builder $BUILDER is missing. Aborting."; exit 1
fi
if [[ $BUILDER =~ "docker" || $BUILDER =~ "podman" ]]; then
if [[ ! $($BUILDER ps) ]]; then
echo "Builder $BUILDER is not functioning. Aborting."; exit 1
fi
fi
if [[ $BUILDER =~ "buildah" ]]; then
BUILD_COMMAND="bud"
fi
fi
IMAGE="${REGISTRY}/${ORGANIZATION}/che-devfile-registry:${TAG}"
VERSION=$(head -n 1 VERSION)
${BUILDER} ${BUILD_COMMAND} \
--build-arg VERSION="${VERSION}" \
-t "${IMAGE}" \
-f "${DOCKERFILE}" \
--target "${TARGET}" .