forked from eclipse-che/che-plugin-registry
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·138 lines (128 loc) · 4.05 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# Copyright (c) 2018-2021 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
base_dir=$(cd "$(dirname "$0")"; pwd)
REGISTRY="quay.io"
ORGANIZATION="eclipse"
TAG="next"
DOCKERFILE="./build/dockerfiles/Dockerfile"
SKIP_OCI_IMAGE="false"
NODE_BUILD_OPTIONS="${NODE_BUILD_OPTIONS:-}"
BUILD_FLAGS_ARRAY=()
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
--skip-oci-image
Build artifacts but do not create the image
--skip-digest-generation
Write image entries as is instead of re-writing with digests
"
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)
BUILD_FLAGS_ARRAY+=("--embed-vsix:true")
shift;
;;
--skip-oci-image)
SKIP_OCI_IMAGE="true"
shift;
;;
--skip-digest-generation)
BUILD_FLAGS_ARRAY+=("--skip-digest-generation:true")
shift;
;;
--rhel)
DOCKERFILE="./build/dockerfiles/rhel.Dockerfile"
shift
;;
*)
print_usage
exit 0
esac
done
}
parse_arguments "$@"
echo "Update yarn dependencies..."
yarn
echo "Build tooling..."
pushd "${base_dir}"/tools/build > /dev/null
yarn build
echo "Generate artifacts..."
eval yarn node "${NODE_BUILD_OPTIONS}" lib/entrypoint.js --output-folder:"${base_dir}/output" "${BUILD_FLAGS_ARRAY[@]}"
popd > /dev/null
echo -e "\nTest entrypoint.sh"
"${base_dir}"/build/dockerfiles/test_entrypoint.sh
if [ "${SKIP_OCI_IMAGE}" != "true" ]; then
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
echo "Building with $BUILDER $BUILD_COMMAND"
IMAGE="${REGISTRY}/${ORGANIZATION}/che-plugin-registry:${TAG}"
VERSION=$(head -n 1 VERSION)
echo "Building che plugin registry ${VERSION}."
${BUILDER} ${BUILD_COMMAND} -t "${IMAGE}" -f "${DOCKERFILE}" .
fi