1
0

Kind of working

Signed-off-by: James P. Ketrenos <james.p.ketrenos@intel.com>
This commit is contained in:
James P. Ketrenos 2024-06-25 16:34:50 -07:00
parent bf4956f5e0
commit 78f44e2aed
13 changed files with 236 additions and 69 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ AndroidSDK
*/build */build
repos repos
flutter flutter
cache

View File

@ -115,13 +115,36 @@ ENV PATH "/usr/bin/flutter/bin:$PATH"
RUN git config --global --add safe.directory /usr/bin/flutter RUN git config --global --add safe.directory /usr/bin/flutter
#RUN apt-get update \ RUN apt-get update \
# && DEBIAN_FRONTEND=noninteractive apt-get install -y \ && DEBIAN_FRONTEND=noninteractive apt-get install -y \
# clang++ \ clang \
# cmake \ cmake \
# ninja-build \ ninja-build \
# pkg-config \ pkg-config \
# && apt-get clean \ libgtk-3-dev \
# && rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} && apt-get clean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log}
# Install Chrome (flutter)
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt install -y ./google-chrome-stable_current_amd64.deb
RUN mkdir -p /opt/android-studio ; wget -O - https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2024.1.1.11/android-studio-2024.1.1.11-linux.tar.gz | tar -xvz -C /opt
# Install VNC (remote gui editing)
#
ENV DISPLAY :20
# Port is 5900+${DISPLAY}
#
EXPOSE 5920
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
tightvncserver fluxbox
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
qemu-system-x86 \
libpulse-dev
COPY /scripts /scripts COPY /scripts /scripts

View File

@ -7,44 +7,54 @@ infrastructure configured as well.
## Build the Android SDK base container ## Build the Android SDK base container
This will seed the base container with an initial version of the Android SDK. This will seed the base container with an initial version of the Android SDK.
After it is created, the SDK is copied to a volume bind mount on the host to
allow multiple containers to use the same base SDK, as well as to perform
SDK updates, upgrades, and additional package installations.
```bash ```bash
docker compose build docker compose build
``` ```
This will build the base 'android-sdk-manager' container as well as the unseeded
'android-dev-container'.
Inside the 'anrdoid-sdk-manager' container the directory '/sdk' will contain the original SDK.
After it is created, the SDK is copied to a volume bind mount on the host to
allow multiple containers to use the same base SDK, as well as to perform
SDK updates, upgrades, and additional package installations. The initial
seeding of the AndroidSDK on the host is performed via:
```bash
docker compose run -it --rm \
android-sdk-manager \
init
```
## Install packages into SDK
The following will install Android platform 34:
https://docs.flutter.dev/get-started/install/linux/android?tab=physical#configure-android-development
```bash
docker compose run -it --rm \
android-sdk-manager -- \
sdkmanager \
"emulator" \
"cmdline-tools;latest" \
"build-tools;34.0.0" \
"platforms;android-34" \
"platform-tools" \
"system-images;android-34;google_apis_playstore;x86_64"
```
At this point, ./AndroidSDK contains the latest SDK. The docker-compose.yml
for the android-dev-container will mount ./AndroidSDK to /opt/android-sdk.
## Seed the flutter repository ## Seed the flutter repository
``` ```
git clone https://github.com/flutter/flutter.git git clone https://github.com/flutter/flutter.git
``` ```
## Copy the base SDK to the mounted 'sdk' directory
```bash
docker compose run -it --rm \
android-dev-container -- \
bash -c 'cp -a $ANDROID_HOME/. /sdk/'
```
## Install packages into SDK
The following will install Android platform 35:
```bash
ANDROID_PLATFORM=35
docker compose run -it --rm \
android-dev-container -- \
sdkmanager \
"build-tools;${ANDROID_PLATFORM}.0.0" \
"platforms;android-${ANDROID_PLATFORM}"
```
At this point, ./AndroidSDK contains the latest SDK. The docker-compose.yml
for the android-dev-container will mount ./AndroidSDK to /opt/android-sdk.
## To seed a new project (once per project) ## To seed a new project (once per project)
```bash ```bash

0
cache/pub-cache/.keep vendored Normal file
View File

View File

@ -4,28 +4,22 @@ fail() {
exit 1 exit 1
} }
declare project_type=$1 declare project=$1
declare project=$2
if [[ "${project}" == "" ]] || [[ "${project_type}" == "" ]]; then if [[ "${project}" == "" ]]; then
echo "usage: ./launch expo|flutter PROJECT" >&2 echo "usage: $0 PROJECT" >&2
exit 1 exit 1
fi fi
if [[ ! -d "projects/${project}" ]]; then
if ! mkdir -p "projects/${project}"; then
fail "mkdir -p projects/${project}"
fi
fi
declare full_path=$(realpath "projects/${project}") declare full_path=$(realpath "projects/${project}")
if ! docker compose run -it --rm \ if ! docker compose run -it --rm \
--name "${project}-seed" \ --name "${project}-seed" \
-v $(pwd)/scripts:/scripts \
-v "${full_path}:/projects/${project}" \ -v "${full_path}:/projects/${project}" \
-p 5920:5920 \
-e CONTAINER="${project}" \
android-dev-container -- \ android-dev-container -- \
develop \ develop \
"${project_type}" \
"${project}"; then "${project}"; then
fail "Unable to launch ${project_type} develop container for ${project}" fail "Unable to launch development container for ${project}"
fi fi

View File

@ -1,9 +1,23 @@
services: services:
android-sdk-manager:
build:
context: .
environment:
- CONTAINER_MODE=android-sdk-manager
tty: true
ports:
- '5037:5037'
volumes:
- ./AndroidSDK:/sdk:rw
# - ./AndroidSDK:/opt/android-sdk:rw
- ./scripts:/scripts:rw
- ./devices:/opt/devices:rw
healthcheck:
disable: true
android-dev-container: android-dev-container:
build: build:
context: . context: .
args:
- NODE_ENV=development
environment: environment:
- NODE_ENV=development - NODE_ENV=development
tty: true tty: true
@ -11,6 +25,9 @@ services:
- '19006:19006' - '19006:19006'
- '19001:19001' - '19001:19001'
- '19002:19002' - '19002:19002'
- '5920:5920'
devices:
- /dev/kvm
volumes: volumes:
- ./react_native_app:/opt/react_native_app/app:delegated - ./react_native_app:/opt/react_native_app/app:delegated
- ./react_native_app/package.json:/opt/react_native_app/package.json - ./react_native_app/package.json:/opt/react_native_app/package.json
@ -18,8 +35,12 @@ services:
- ./flutter:/usr/bin/flutter - ./flutter:/usr/bin/flutter
- notused:/opt/react_native_app/app/node_modules - notused:/opt/react_native_app/app/node_modules
- ./repos:/opt/repos - ./repos:/opt/repos
# - ./AndroidSDK:/opt/android-sdk:ro
- ./AndroidSDK:/opt/android-sdk:ro - ./AndroidSDK:/opt/android-sdk:ro
- ./scripts:/scripts:rw - ./scripts:/scripts:rw
- ./devices:/opt/devices:rw
- ./cache/pub-cache:/root/.pub-cache:rw
- ./cache/android:/root/.android:rw
healthcheck: healthcheck:
disable: true disable: true

25
launch.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
fail() {
echo "$*" >&2
exit 1
}
declare project=$1
if [[ "${project}" == "" ]]; then
echo "usage: $0 PROJECT" >&2
exit 1
fi
declare full_path=$(realpath "projects/${project}")
if ! docker compose run --rm \
--name "${project}-seed" \
-v "${full_path}:/projects/${project}" \
-p 5920:5920 \
-e CONTAINER="${project}" \
android-dev-container -- \
run \
"${project}"; then
fail "Unable to start container for ${project}"
fi

View File

@ -29,6 +29,8 @@ accept_all_android_licenses() {
accept_license_of android-sdk-preview-license 504667f4c0de7af1a06de9f4b1727b84351f2910 accept_license_of android-sdk-preview-license 504667f4c0de7af1a06de9f4b1727b84351f2910
accept_license_of google-gdk-license 33b6a2b64607f11b759f320ef9dff4ae5c47d97a accept_license_of google-gdk-license 33b6a2b64607f11b759f320ef9dff4ae5c47d97a
accept_license_of intel-android-extra-license d975f751698a77b662f1254ddbeed3901e976f5a accept_license_of intel-android-extra-license d975f751698a77b662f1254ddbeed3901e976f5a
accept_license_of android-sdk-arm-dbt-license 859f317696f67ef3d7f30a50a5560e7834b43903
accept_license_of mips-android-sysimage-license e9acab5b5fbb560a72cfaecce8946896ff6aab9d
} }
accept_license_of() { accept_license_of() {

View File

@ -9,6 +9,8 @@ arguments=(
declare -i parse_error=0 declare -i parse_error=0
declare command="" declare command=""
declare XVNC_ARGS="-depth 24 -geometry 1280x1024 -ac"
# #
# Parse command line arguments # Parse command line arguments
# #
@ -61,29 +63,113 @@ if (( parse_error )); then
fi fi
case "${command}" in case "${command}" in
*bash|shell) init)
/bin/bash "${options[@]}" if [[ "${CONTAINER_MODE}" != "android-sdk-manager" ]]; then
fail "'${command}' must be run on android-sdk-manager not android-dev-container"
fi
if [[ ! -e "${ANDROID_HOME}"/license/android-sdk-license ]]; then
if ! cp -a "${ANDROID_HOME}"/. /sdk; then
fail "Unable to copy ${ANDROID_HOME} to /sdk"
fi
fi
echo "AndroidSDK transfered to host bind mount."
;;
seed-project)
if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]]; then
fail "'${command}' must be run on android-dev-container not android-sdk-manager"
fi
seed-project "${options[@]}"
exit $? exit $?
;; ;;
develop) develop)
project_type="${1}" if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]]; then
project="${2}" fail "'${command}' must be run on android-dev-container not android-sdk-manager"
fi
project="${1}"
project_type=$(cat "/projects/${project}/project_type")
cd "/projects/${project}" cd "/projects/${project}"
if [[ -d ".git" ]]; then
git config --global --add safe.directory "$(pwd)"
fi
case "${project_type}" in case "${project_type}" in
"expo") "expo")
echo "Launching web app in ${project}" echo "Launching web app in ${project}"
npm run web npm run web
;; ;;
"flutter") "flutter")
cat << EOF > ~/.flutter
{
"firstRun": false,
"clientId": "b88ac7f3-4d6f-41e0-bef6-f377e4eaceb7",
"enabled": false
}
EOF
Xvnc ${DISPLAY} ${XVNC_ARGS} >/dev/null 2>&1 &
fluxbox >/dev/null 2>&1 &
echo "X11 VNC running on ${DISPLAY} with password '${CONTAINER}'"
if [[ ! -d "/opt/devices/pixel-6a" ]]; then
echo "Creating Pixel 6A with Android 35 and Google APIs"
avdmanager create avd --force --path /opt/devices/pixel-6a --name Pixel-6a -k "system-images;android-34;google_apis_playstore;x86_64" --device pixel_6a
fi
echo "Launching emulator. Connect via vnc to view."
emulator -avd Pixel-6a &
echo "Launching terminal in ${project}" echo "Launching terminal in ${project}"
/bin/bash /bin/bash
;; ;;
esac esac
;; ;;
seed-project) run)
seed-project "${options[@]}" if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]]; then
fail "'${command}' must be run on android-dev-container not android-sdk-manager"
fi
project="${1}"
cd "/projects/${project}"
if [[ -d ".git" ]]; then
git config --global --add safe.directory "$(pwd)"
fi
project_type=$(cat "/projects/${project}/project_type")
case "${project_type}" in
"expo")
echo "Starting web app in ${project}"
while true; do npm run web; sleep 5; done
;;
"flutter")
cat << EOF > ~/.flutter
{
"firstRun": false,
"clientId": "b88ac7f3-4d6f-41e0-bef6-f377e4eaceb7",
"enabled": false
}
EOF
Xvnc ${DISPLAY} ${XVNC_ARGS} >/dev/null 2>&1 &
fluxbox >/dev/null 2>&1 &
echo "X11 VNC running on ${DISPLAY} with password '${CONTAINER}'"
if [[ ! -d "/opt/devices/pixel-6a" ]]; then
echo "Creating Pixel 6A with Android 35 and Google APIs"
avdmanager create avd --force --path /opt/devices/pixel-6a --name Pixel-6a -k "system-images;android-34;google_apis_playstore;x86_64" --device pixel_6a
fi
echo "Launching emulator. Connect via vnc to view."
emulator -avd Pixel-6a &
echo "Launching terminal in ${project}"
/bin/bash
;;
esac
;;
*bash|shell)
/bin/bash "${options[@]}"
exit $? exit $?
;; ;;
*) *)
fail "Invalid command '${command}'" if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]] && [[ "${command}" =~ .*sdkmanager$ ]]; then
echo "'${command}' detected. Updating container copy of Android SDK from the host."
cp -a /sdk/. $ANDROID_HOME/
fi
${command} "${@}"
if [[ "${CONTAINER_MODE}" == "android-sdk-manager" ]] && [[ "${command}" =~ .*sdkmanager$ ]]; then
echo "'${command}' detected. Updating host copy of Android SDK"
cp -a $ANDROID_HOME/. /sdk/
fi
;;
esac esac

View File

@ -106,6 +106,8 @@ case "${project_type}" in
if ! chown -R ${user}:${group} .; then if ! chown -R ${user}:${group} .; then
fail "chown -R ${user}:${group} ." fail "chown -R ${user}:${group} ."
fi fi
echo "${project_type}" > project_type
;; ;;
"flutter") "flutter")
ls -altr /usr/bin/flutter ls -altr /usr/bin/flutter
@ -121,5 +123,14 @@ case "${project_type}" in
fi fi
fi fi
git config --global --add safe.directory /usr/bin/flutter git config --global --add safe.directory /usr/bin/flutter
flutter config --no-analytics
flutter config --disable-analytics
flutter doctor --android-licenses
cd "${project}"
if ! chown -R ${user}:${group} .; then
fail "chown -R ${user}:${group} ."
fi
echo "${project_type}" > project_type
;; ;;
esac esac

View File

@ -8,7 +8,7 @@ declare project_type=$1
declare project=$2 declare project=$2
if [[ "${project}" == "" ]] || [[ "${project_type}" == "" ]]; then if [[ "${project}" == "" ]] || [[ "${project_type}" == "" ]]; then
echo "usage: ./launch expo|flutter PROJECT" >&2 echo "usage: $0 expo|flutter PROJECT" >&2
exit 1 exit 1
fi fi

View File

@ -4,24 +4,18 @@ fail() {
exit 1 exit 1
} }
declare project_type=$1 declare project=$1
declare project=$2
if [[ "${project}" == "" ]] || [[ "${project_type}" == "" ]]; then if [[ "${project}" == "" ]]; then
echo "usage: ./launch expo|flutter PROJECT" >&2 echo "usage: ${0} PROJECT" >&2
exit 1 exit 1
fi fi
if [[ ! -d "projects/${project}" ]]; then
if ! mkdir -p "projects/${project}"; then
fail "mkdir -p projects/${project}"
fi
fi
declare full_path=$(realpath "projects/${project}") declare full_path=$(realpath "projects/${project}")
if ! docker compose exec -it \ if ! docker compose exec -it \
"${project}" \ "${project}" \
shell; then shell; then
fail "Unable to launch shell in ${project}" fail "Unable to launch shell in '${project}'. Make sure it is running via './launch.sh ${project}'."
fi fi