Skip to content

Commit b90c955

Browse files
committed
Docker: refactor the exe function
1 parent c5a4a91 commit b90c955

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

docker/build-linux.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dock run -d --rm --name $container_name $image_name \
5959
sh -c 'sleep 60; while [ -n "$(find /tmp/alive -cmin -10)" ]; do sleep 10; done'
6060

6161
# Prevent the container from stopping
62-
while true; do exe / touch /tmp/alive || true; sleep 14; done &
62+
while true; do exe touch /tmp/alive || true; sleep 14; done &
6363
keep_alive_pid=$!
6464

6565
# Enter the container on exit
@@ -75,7 +75,7 @@ function on_exit() {
7575
# Set up secrets inside the container
7676
if [ "$flavor" != unofficial ]; then
7777
function exe_i() { dock exec -i $container_name "$@"; }
78-
exe / mkdir -p /opt/secrets
78+
exe mkdir -p /opt/secrets
7979
echo "$secretKeystoreHex" | xxd -p -r | exe_i dd of=/opt/secrets/keystore.jks
8080
echo "storePassword=$secretStorePassword" | exe_i dd of=/opt/secrets/key.properties
8181
echo "keyPassword=$secretKeyPassword" | exe_i dd of=/opt/secrets/key.properties oflag=append conv=notrunc
@@ -94,12 +94,12 @@ else
9494
fi
9595

9696
# Generate bindings (TODO: This should be done automatically)
97-
exe /opt/ouisync-app/ouisync/bindings/dart dart pub get
98-
exe /opt/ouisync-app/ouisync/bindings/dart dart tool/bindgen.dart
97+
exe -d /opt/ouisync-app/ouisync/bindings/dart dart pub get
98+
exe -d /opt/ouisync-app/ouisync/bindings/dart dart tool/bindgen.dart
9999

100100
# Build Ouisync app
101-
exe /opt/ouisync-app dart pub get
102-
exe /opt/ouisync-app dart run util/release.dart \
101+
exe -d /opt/ouisync-app dart pub get
102+
exe -d /opt/ouisync-app dart run util/release.dart \
103103
--flavor=$flavor \
104104
$arg_android_key_properties \
105105
$arg_sentry \
@@ -108,6 +108,6 @@ exe /opt/ouisync-app dart run util/release.dart \
108108
# Collect artifacts
109109
mkdir -p $dst_dir
110110
src_dir=/opt/ouisync-app/releases/latest
111-
for artifact in $(exe $src_dir ls); do
111+
for artifact in $(exe -d $src_dir ls); do
112112
dock cp $container_name:$src_dir/$artifact $dst_dir/
113113
done

docker/build-utils.sh

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,25 @@ function dock() {
1414
docker --host ssh://$host "$@"
1515
}
1616

17-
function exe() {
18-
local dir=$1; shift
19-
dock exec -w $dir $container_name "$@"
20-
}
17+
function exe() (
18+
while [[ "$#" -gt 0 ]]; do
19+
case $1 in
20+
-d) local dir_opt="-w $2"; shift ;;
21+
-i) local interactive_opt="-i" ;;
22+
-l) local history_log=1 ;;
23+
*) break ;;
24+
esac
25+
shift
26+
done
27+
28+
local cmd="dock exec $dir_opt $interactive_opt $container_name $@"
29+
30+
if [ "$history_log" == 1 ]; then
31+
echo $cmd | dock exec -i $container_name dd of=/root/.bash_history oflag=append conv=notrunc
32+
fi
33+
34+
$cmd
35+
)
2136

2237
function get_sources_from_git {
2338
local commit=$1
@@ -26,9 +41,9 @@ function get_sources_from_git {
2641
# Remove slash suffix if present
2742
dstdir=${dstdir%/}
2843

29-
exe $dstdir/ git clone --filter=tree:0 https://github.com/equalitie/ouisync-app
30-
exe $dstdir/ouisync-app git reset --hard $commit
31-
exe $dstdir/ouisync-app git submodule update --init --recursive
44+
exe -d $dstdir/ git clone --filter=tree:0 https://github.com/equalitie/ouisync-app
45+
exe -d $dstdir/ouisync-app git reset --hard $commit
46+
exe -d $dstdir/ouisync-app git submodule update --init --recursive
3247
}
3348

3449
function get_sources_from_local_dir {
@@ -54,5 +69,5 @@ function get_sources_from_local_dir {
5469
${exclude_dirs[@]/#/--exclude=} \
5570
${srcdir%/}/ $container_name:$dstdir/ouisync-app
5671

57-
exe / git config --global --add safe.directory /opt/ouisync-app
72+
exe git config --global --add safe.directory /opt/ouisync-app
5873
}

docker/build-windows.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dock run -d --rm --name $container_name --cpus $host_core_count -p 22 $image_nam
6262
sh -c 'sleep 60; while [ -n "$(find /tmp/alive -cmin -10)" ]; do sleep 10; done'
6363

6464
# Prevent the container from stopping
65-
while true; do exe / touch /tmp/alive || true; sleep 14; done &
65+
while true; do exe touch /tmp/alive || true; sleep 14; done &
6666
keep_alive_pid=$!
6767

6868
# Enter the container on exit
@@ -77,8 +77,8 @@ function on_exit() {
7777

7878
# Prepare secrets
7979
if [ "$flavor" = "production" ]; then
80-
exe / mkdir c:\\secrets
81-
exe / powershell -Command "Add-Content -Force -Path c:/secrets/sentry_dsn -Value \"$secretSentryDSN\""
80+
exe mkdir c:\\secrets
81+
exe powershell -Command "Add-Content -Force -Path c:/secrets/sentry_dsn -Value \"$secretSentryDSN\""
8282
sentry_arg='--sentry=C:/secrets/sentry_dsn'
8383
fi
8484

@@ -90,18 +90,18 @@ else
9090
fi
9191

9292
# Generate bindings
93-
exe c:/ouisync-app/ouisync/bindings/dart dart pub get
94-
exe c:/ouisync-app/ouisync/bindings/dart dart tool/bindgen.dart
93+
exe -d c:/ouisync-app/ouisync/bindings/dart dart pub get
94+
exe -d c:/ouisync-app/ouisync/bindings/dart dart tool/bindgen.dart
9595

9696
# Build Ouisync
97-
exe c:/ouisync-app dart pub get
98-
exe c:/ouisync-app dart run util/release.dart --flavor=$flavor $sentry_arg $build_exe $build_msix
97+
exe -d c:/ouisync-app dart pub get
98+
exe -d c:/ouisync-app dart run util/release.dart --flavor=$flavor $sentry_arg $build_exe $build_msix
9999

100100
function dock_rsync() {
101101
rsync -e "docker -H ssh://$host exec -i" "$@"
102102
}
103103

104104
mkdir -p $out_dir
105-
for asset in $(exe c:/ouisync-app/releases/latest ls); do
105+
for asset in $(exe -d c:/ouisync-app/releases/latest ls); do
106106
dock_rsync -av $container_name:/c/ouisync-app/releases/latest/$asset $out_dir
107107
done

0 commit comments

Comments
 (0)