-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·105 lines (95 loc) · 2.9 KB
/
build.sh
File metadata and controls
executable file
·105 lines (95 loc) · 2.9 KB
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
#!/usr/bin/env bash
read -r -d '' USAGE <<- EOM
\n
Usage: ./build.sh [OPTIONS]\n
\n
Options:\n
--build-tools-version=VERSION \t Android build tools version. Default: 34.0.0\n
--channel=CHANNEL \t Redex branch master or stable default stable. Default: stable
-u, --update \t Update git submodules before build\n
-lp --local-push \t Push to a local repository\n
-l, --latest \t Tag image as latest
-p, --push \t Push image to docker hub\n
-t, --testing \t Run tests during docker build\n
-h, --help \t Print usage description\n
EOM
set -eo pipefail
IMAGE_NAME=redex
IMAGE=warnyul/$IMAGE_NAME
LOCAL_IMAGE=localhost:5000/$IMAGE_NAME
LOCAL_PUSH=false
LATEST=false
PUSH=false
UPDATE_REDEX=false
REDEX_BRANCH=stable
BUILD_TOOLS_VERSION=34.0.0
RUN_TESTS=false
while [[ $# -gt 0 ]]; do
case "$1" in
--build-tools-version=*)
BUILD_TOOLS_VERSION="${1#*=}"
if [ -z $BUILD_TOOLS_VERSION ]; then
echo -e "\n --build-tools-version is required.\n See './build.sh --help'.\n"
echo -e "$USAGE"
exit 1
fi
;;
--channel=*)
REDEX_BRANCH="${1#*=}"
if [ -z $REDEX_BRANCH ]; then
echo -e "\n --channel is required.\n See './build.sh --help'.\n"
echo -e "$USAGE"
exit 1
fi
;;
-u|--update)
UPDATE_REDEX=true
;;
-lp|--local-push)
LOCAL_PUSH=true
;;
-l|--latest)
LATEST=true
;;
-p|--push)
PUSH=true
;;
-t|--testing)
RUN_TESTS=true
;;
-h|--help|*)
echo -e "\n Unknown argument: '$1'.\n See './build.sh --help'.\n"
echo -e "$USAGE"
exit 1
;;
esac
shift
done
if [[ "$UPDATE_REDEX" == "true" ]]; then
git submodule update --init
git submodule update --remote
fi
# Build
COMMIT_HASH=$(git submodule status | grep "redex_${REDEX_BRANCH}" | cut -d' ' -f2)
BASE_IMAGE="warnyul/android-build-tools:${BUILD_TOOLS_VERSION}-jammy-openjdk17"
docker pull "$BASE_IMAGE"
docker tag "$BASE_IMAGE" base-image
VERSION="${REDEX_BRANCH}-${COMMIT_HASH}-androidbuildtools${BUILD_TOOLS_VERSION}-jammy-openjdk17"
docker build \
--build-arg="REDEX_BRANCH=${REDEX_BRANCH}" \
--build-arg="RUN_TESTS=${RUN_TESTS}" \
-t "${IMAGE}:${VERSION}" .
# Publish to a local repo
if [[ "${LOCAL_PUSH}" == "true" ]]; then
docker run -d -p 5000:5000 --restart=always --name registry registry 2> /dev/null
docker tag "${IMAGE}:${VERSION}" "${LOCAL_IMAGE}:${VERSION}"
docker tag "${IMAGE}:${VERSION}" ${LOCAL_IMAGE}
docker push ${LOCAL_IMAGE}
fi
if [[ "$LATEST" == "true" ]]; then
docker tag "${IMAGE}:${VERSION}" "${IMAGE}:latest"
fi
# Publish to Docker Hub
if [[ "$PUSH" == "true" ]]; then
docker image push --all-tags "$IMAGE"
fi