-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·140 lines (121 loc) · 4.12 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·140 lines (121 loc) · 4.12 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
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
139
140
#!/bin/sh
# Exit immediately if a command returns a non-zero status.
set -e
# Usage of this script
program_name=$0
usage () {
echo "usage: $program_name [--target android|flutter-test] [--android-api 36] [--build-tools "36.0.0"] [--cmdtools 13114758] [--dart] [--dart-arch x64] [--dart-version 3.8.1] [--arch amd64] [--build] [--deploy]"
echo " --target <stage> Dockerfile stage to build: android (default) or flutter-test"
echo " --android-api <androidVersion> Use specific Android version from \`sdkmanager --list\` (android target only)"
echo " --build-tools <version> Use specific build tools version (android target only)"
echo " --cmdtools <version> Use specific command-line tools version (android target only)"
echo " --dart Install Dart SDK"
echo " --dart-arch <arch> Use specific dart architecture (x64, arm64)"
echo " --dart-version <version> Use specific dart version"
echo " --arch <arch> Use specific architecture (amd64, arm64)"
echo " --build Build image"
echo " --deploy Deploy image"
exit 1
}
# Parameters parsing
dart=false
target=android
while true; do
case "$1" in
--target ) target="$2"; shift 2 ;;
--android-api ) android_api="$2"; shift 2 ;;
--build-tools ) android_build_tools="$2"; shift 2 ;;
--cmdtools ) android_cmdtools="$2"; shift 2 ;;
--dart ) dart=true; shift ;;
--dart-arch ) dart_arch="$2"; shift 2 ;;
--dart-version ) dart_version="$2"; shift 2 ;;
--arch ) arch="$2"; shift 2 ;;
--build ) build=true; shift ;;
--deploy ) deploy=true; shift ;;
* ) break ;;
esac
done
if [ "$target" != "android" ] && [ "$target" != "flutter-test" ]; then
echo "Invalid --target: $target (expected android or flutter-test)"
usage
fi
if [ "$target" = "android" ]; then
if [ -z "$android_api" ]; then
echo "Missing --android-api parameter"
usage
fi
if [ -z "$android_build_tools" ]; then
echo "Missing --build-tools parameter"
usage
fi
if [ -z "$android_cmdtools" ]; then
echo "Missing --cmdtools parameter"
usage
fi
fi
if [ -z "$arch" ]; then
echo "Missing --arch parameter"
usage
fi
# Compute image tag
org_name="mylittlesuite"
if [ "$target" = "flutter-test" ]; then
simple_image_name="flutter-test"
else
simple_image_name="android-$android_api"
fi
if [ "$dart" = true ]; then
simple_image_name="$simple_image_name-dart-$dart_version"
fi
branch="${GIT_REF##refs/heads/}"
if [ "$branch" = "develop" ]; then
simple_image_name="$simple_image_name-snapshot"
fi
if [ -n "$RELEASE_NAME" ]; then
simple_image_name="$simple_image_name-$RELEASE_NAME"
fi
full_image_name="$org_name/mobile_ci:$simple_image_name-$arch"
# CI business
tasks=0
if [ "$build" = true ]; then
tasks=$((tasks+1))
if [ -n "$dart_version" ]; then
dart_arch_and_version_build_arg="--build-arg dart_arch=$dart_arch --build-arg dart_version=$dart_version"
fi
echo $dart_arch_and_version_build_arg
if [ "$target" = "android" ]; then
android_build_args="--build-arg android_api=android-$android_api --build-arg android_build_tools=$android_build_tools --build-arg android_cmdtools=commandlinetools-linux-${android_cmdtools}_latest.zip"
fi
cache_scope="$simple_image_name-$arch"
set -x
docker buildx build \
--load \
--network=host \
--target $target \
$android_build_args \
--build-arg dart="$dart" \
$dart_arch_and_version_build_arg \
--build-arg arch=$arch \
--cache-from "type=gha,scope=$cache_scope" \
--cache-to "type=gha,mode=max,scope=$cache_scope" \
--tag $full_image_name .
set +x
fi
ci=${CI:-false}
if [ "$ci" = true ]; then
echo "Running in CI"
volume_options="--volumes-from runner --workdir $GITHUB_WORKSPACE"
else
echo "Not running in CI"
volume_options="-v $PWD:/wd --workdir /wd"
fi
if [ "$deploy" = true ]; then
tasks=$((tasks+1))
echo "Deploy image $full_image_name"
echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USERNAME --password-stdin
docker push $full_image_name
fi
if [ "$tasks" = 0 ]; then
echo "No task was executed"
usage
fi