forked from nextcloud/neon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-app.sh
executable file
·74 lines (61 loc) · 1.94 KB
/
build-app.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
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
source tool/common.sh
function get_mount_paths_dir() {
dir="$1"
mapfile -t packages < <(melos list --parsable --relative --dir-exists="$dir")
echo "${packages[@]/%//$dir}"
}
function get_mount_paths_file() {
file="$1"
mapfile -t packages < <(melos list --parsable --relative --file-exists="$file")
echo "${packages[@]/%//$file}"
}
targets=("linux/arm64" "linux/amd64")
target="$1"
# shellcheck disable=SC2076
if ! [[ ${targets[*]} =~ "$target" ]]; then
echo "Unknown target $target, must be one of ${targets[*]}"
exit 1
fi
if [[ "$target" == "linux/arm64" ]] || [[ "$target" == "linux/amd64" ]]; then
os="$(echo "$target" | cut -d "/" -f 1)"
arch="$(echo "$target" | cut -d "/" -f 2)"
tag="$(image_tag "build:$os-$arch")"
# shellcheck disable=SC2046
docker buildx build \
--platform "$target" \
--progress plain \
--tag "$tag" \
--build-arg="FLUTTER_VERSION=$(jq ".flutterSdkVersion" -r < .fvm/fvm_config.json | cut -d "@" -f 1)" \
$(cache_build_args "$tag") \
-f "tool/build/Dockerfile.$os" \
./tool/build
paths=(packages/app/{pubspec.lock,linux,build})
mapfile -O "${#paths[@]}" -t paths < <(get_mount_paths_dir "lib")
mapfile -O "${#paths[@]}" -t paths < <(get_mount_paths_dir "assets")
mapfile -O "${#paths[@]}" -t paths < <(get_mount_paths_file "pubspec.yaml")
mapfile -O "${#paths[@]}" -t paths < <(get_mount_paths_file "pubspec_overrides.yaml")
run_args=()
for path in ${paths[*]}; do
run_args+=(-v "$(pwd)/$path:/src/$path")
done
mkdir -p "packages/app/build"
container_id="$(
# shellcheck disable=SC2086
docker run \
--platform "$target" \
--rm -d \
-e "ORIGINAL_USER=$(id -u)" \
-e "ORIGINAL_GROUP=$(id -g)" \
-e "BUILD_ARGS=${*:2}" \
${run_args[*]} \
"$tag"
)"
function cleanup() {
docker kill "$container_id" > /dev/null 2>&1 || true
}
trap cleanup EXIT
docker logs -f "$container_id"
fi