created new image to improve waiting times

Reviewers: kuba-orlik

Subscribers: kuba-orlik

Differential Revision: https://hub.sealcode.org/D1364
This commit is contained in:
migueldar 2024-03-06 08:43:31 +01:00 committed by Kuba Orlik
parent 7a25b95420
commit a4c63e5ad4
9 changed files with 88 additions and 25 deletions

View File

@ -1,11 +1,4 @@
FROM runmymind/docker-android-sdk:ubuntu-standalone-20230511
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/android-sdk-linux/cmdline-tools/latest/bin:/opt/android-sdk-linux/cmdline-tools/tools/bin:/opt/android-sdk-linux/tools/bin:/opt/android-sdk-linux/build-tools/32.0.0:/opt/android-sdk-linux/platform-tools:/opt/android-sdk-linux/emulator:/opt/android-sdk-linux/bin
RUN sdkmanager "system-images;android-33;google_apis;x86_64"
RUN echo no | avdmanager create avd -n virtual_dev -b google_apis/x86_64 -k "system-images;android-33;google_apis;x86_64"
RUN apt-get update && apt-get install -y iproute2 iputils-ping iptables redsocks npm git
FROM pre_android/ready
EXPOSE 3000

View File

@ -1,14 +1,8 @@
hashed_name=`openssl x509 -inform PEM -subject_hash_old -in /ca-cert.cer | head -1`
emulator -avd virtual_dev -writable-system -no-window -no-audio &
bash /conf/start_culebra.sh
npm i -C /code
cp /ca-cert.cer /$hashed_name.0
bash /conf/install_cert.sh $hashed_name.0
bash /conf/install_culebra.sh
bash /conf/iptables_conf.sh
redsocks -c /conf/redsocks.conf &
bash /conf/wait_for_sd.sh
#wait for cert to be installed before launching socket server
node /code/index.js
#tail -f /dev/null

View File

@ -0,0 +1,15 @@
rm -f /opt/android-sdk-linux/.android/avd/virtual_dev.avd/*.lock
adb start-server
emulator -avd virtual_dev -writable-system -no-window -no-audio &
adb wait-for-device
adb emu avd snapshot load configured
adb wait-for-device
export PATH=$PATH:/root/culebraDependencies
cd /root/culebra
./culebratester2 start-server &
#wait for the server to start
while ! curl http://localhost:9987/v2/uiDevice/screenshot > /dev/null 2> /dev/null; do
sleep 0.1
done

View File

@ -20,7 +20,6 @@ services:
- rent_gen_android
volumes:
- $PWD/android/conf:/conf
- $PWD/certificates/mitmproxy-ca-cert.cer:/ca-cert.cer
- $PWD/android/code:/code
http_server:
build: ./http_server/

10
pre_android/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM runmymind/docker-android-sdk:ubuntu-standalone-20230511
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/android-sdk-linux/cmdline-tools/latest/bin:/opt/android-sdk-linux/cmdline-tools/tools/bin:/opt/android-sdk-linux/tools/bin:/opt/android-sdk-linux/build-tools/32.0.0:/opt/android-sdk-linux/platform-tools:/opt/android-sdk-linux/emulator:/opt/android-sdk-linux/bin
RUN sdkmanager "system-images;android-33;google_apis;x86_64"
RUN echo no | avdmanager create avd -n virtual_dev -b google_apis/x86_64 -k "system-images;android-33;google_apis;x86_64"
RUN apt-get update && apt-get install -y iproute2 iputils-ping iptables redsocks npm git
CMD bash /preconf/docker-entrypoint.sh

View File

@ -0,0 +1,15 @@
hashed_name=`openssl x509 -inform PEM -subject_hash_old -in /ca-cert.cer | head -1`
adb start-server
emulator -avd virtual_dev -writable-system -no-window -no-audio &
cp /ca-cert.cer /$hashed_name.0
bash /preconf/install_cert.sh $hashed_name.0
bash /preconf/install_culebra.sh
adb emu avd snapshot save configured
adb emu kill
#to let the host know it finished installing
install -m 777 /dev/null /preconf/finished
tail -f /dev/null

View File

@ -1,3 +1,4 @@
adb wait-for-device
cd /root
git clone https://github.com/dtmilano/CulebraTester2-public culebra
git clone https://gist.github.com/dtmilano/4537110 culebraDependencies
@ -6,10 +7,4 @@ export PATH=$PATH:/root/culebraDependencies
cd culebra
git checkout 4ce1987e7ec6ae627d8f33a1a3b59f684aff90c0
echo "/opt/android-sdk-linux" >> local.properties
./gradlew installDebug installDebugAndroidTest
./culebratester2 start-server &
#wait for the server to start
while ! curl http://localhost:9987/v2/uiDevice/screenshot > /dev/null 2> /dev/null; do
sleep 0.1
done
./culebratester2 install

View File

@ -1,5 +1,9 @@
import { promises as fs } from "fs";
async function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
async function checkCertExistance() {
return await Promise.all([
fs.access("./certificates/mitmproxy-ca-cert.cer", fs.constants.R_OK),
@ -34,7 +38,33 @@ async function generateCert() {
}
//kill docker container
await $`docker stop certGenerator`;
$`docker stop certGenerator`;
}
async function generatePreAndroid() {
await $`docker build -t pre_android pre_android`;
$`docker run --rm -v $PWD/certificates/mitmproxy-ca-cert.cer:/ca-cert.cer -v $PWD/pre_android/preconf:/preconf --device=/dev/kvm --name pre_android_cont pre_android &`;
console.log(
"installing tls certificate and culebra into the android pre-image"
);
//the way of knowing when the culebra install is creating a file in the shared volume
let finished = false;
while (!finished) {
try {
await fs.access(
"./pre_android/preconf/finished",
fs.constants.R_OK
),
$`rm -f ./pre_android/preconf/finished`;
finished = true;
} catch {
await sleep(100);
}
}
await $`docker commit pre_android_cont pre_android/ready`;
$`docker stop pre_android_cont`;
}
if (process.argv.length !== 4) throw new Error("expected an argument");
@ -44,9 +74,21 @@ else if (process.argv[3] === "up") {
} catch {
await generateCert();
}
try {
await $`docker image inspect pre_android/ready > /dev/null 2> /dev/null`;
} catch {
await generatePreAndroid();
}
await $`docker compose build`;
await $`docker compose up`;
} else if (process.argv[3] === "down") await $`docker compose down`;
else if (process.argv[3] === "generateCert") {
generateCert();
} else throw new Error("expected [up | down | generateCert ] as argument");
} else if (process.argv[3] === "generatePreAndroid") {
generatePreAndroid();
} else
throw new Error(
"expected [up | down | generateCert | generatePreAndroid ] as argument"
);