1
0

Updating to work with latest expo

Signed-off-by: James Ketrenos <james.p.ketrenos@intel.com>
This commit is contained in:
James Ketrenos 2024-12-15 19:59:41 -08:00
parent bf80f5e5ec
commit 1cba45c7b9
11 changed files with 257 additions and 101 deletions

View File

@ -124,4 +124,27 @@ RUN apt-get update \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} && rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log}
# Install build-essential, which includes g++ (required)
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log}
# Helper utilities...
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
nano \
openssh-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log}
# Needed for running android emulator
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
xterm \
libpulse-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log}
COPY /scripts /scripts COPY /scripts /scripts

View File

@ -1,40 +1,49 @@
# Android Development Container # Android Development Container
This sets up development containers for Expo and Flutter using This sets up development containers for Expo and Flutter using the
the Android SDK. The Dockerfile is derived from parts of [thyrlian/android-sdk](https://github.com/thyrlian/AndroidSDK), with expo and flutter development Android SDK. The Dockerfile is derived from parts of
infrastructure configured as well. [thyrlian/android-sdk](https://github.com/thyrlian/AndroidSDK), with
expo and flutter development infrastructure configured as well.
## Build the Android SDK base container ## Build the Android SDK development container environment
This will seed the base container with an initial version of the Android SDK. The following steps will set up an Android build environment:
1. Seed `android-sdk-manager` container with an initial version of the Android
SDK:
```bash ```bash
docker compose build docker compose build
``` ```
This will build the base 'android-sdk-manager' container as well as the unseeded This will build the base 'android-sdk-manager' container as well create an unseeded 'android-dev-container'.
'android-dev-container'.
Inside the 'anrdoid-sdk-manager' container the directory '/sdk' will contain the original SDK. 2. Transfer the AndroidSDK from `android-sdk-manager` to the host:
After it is created, the SDK is copied to a volume bind mount on the host to Copy the sdk from the android-sdk-manager to the host to allow multiple
allow multiple containers to use the same base SDK, as well as to perform containers to use the same base SDK, as well as to perform SDK updates,
SDK updates, upgrades, and additional package installations. The initial upgrades, and additional package installations.
seeding of the AndroidSDK on the host is performed via:
```bash ```bash
docker compose run -it --rm \ docker compose run -it --rm \
-v $(realpath AndroidSDK):/sdk:rw \
-v $(realpath scripts):/scripts:rw \
android-sdk-manager \ android-sdk-manager \
init init
``` ```
## Install packages into SDK 3. Install packages into SDK
The following will install Android platform 35. The `android-sdk-manager` container can then be used to update then
`./AndroidSDK` on the host to include additional packages.
The following will install Android platform 35:
```bash ```bash
ANDROID_PLATFORM=35 ANDROID_PLATFORM=35
docker compose run -it --rm \ docker compose run -it --rm \
-v $(realpath AndroidSDK):/opt/android-sdk:rw \
-v $(realpath scripts):/scripts:rw \
android-sdk-manager -- \ android-sdk-manager -- \
sdkmanager \ sdkmanager \
"build-tools;${ANDROID_PLATFORM}.0.0" \ "build-tools;${ANDROID_PLATFORM}.0.0" \
@ -42,25 +51,14 @@ docker compose run -it --rm \
"platform-tools" "platform-tools"
``` ```
At this point, ./AndroidSDK contains the latest SDK. The docker-compose.yml At this point, `./AndroidSDK` contains the latest SDK with the requested Android Platform version.
for the android-dev-container will mount ./AndroidSDK to /opt/android-sdk.
### Copy the base SDK to the mounted 'sdk' directory ## Seed a flutter repository
```bash
docker compose run -it --rm \
android-dev-container -- \
bash -c 'cp -a $ANDROID_HOME/. /sdk/'
```
## Seed the flutter repository
``` ```
git clone https://github.com/flutter/flutter.git git clone https://github.com/flutter/flutter.git
``` ```
## To seed a new project (once per project) ## To seed a new project (once per project)
```bash ```bash
@ -89,3 +87,23 @@ PROJECT=foo
```bash ```bash
docker compose stop "${PROJECT}" docker compose stop "${PROJECT}"
``` ```
# Things
To use virtual devices:
## Install base image
```
sdkmanager "system-images;android-35-ext14;google_apis_playstore;x86_64"
```
## Create virtual device
```
avdmanager create avd \
-n Pixel \
-d pixel_6a \
-k "system-images;android-35-ext14;google_apis_playstore;x86_64"
```

33
debug.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
fail() {
echo "$*" >&2
exit 1
}
declare project_type=$1
declare project=$2
if [[ "${project}" == "" ]] || [[ "${project_type}" == "" ]]; then
echo "usage: $0 expo|flutter PROJECT" >&2
exit 1
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}")
if ! docker compose run -it --rm \
--name "${project}-seed" \
-v $(pwd)/scripts:/scripts \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $(pwd)/AndroidUser:/root/.android \
-v "${full_path}:/projects/${project}" \
android-dev-container -- \
shell; then
fail "Unable to run seed-project for ${project}"
else
echo "Project '${project}' now exists in projects/${project}"
fi

View File

@ -15,9 +15,10 @@ 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)/AndroidUser:/root/.android \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v "${full_path}:/projects/${project}" \ -v "${full_path}:/projects/${project}" \
android-dev-container -- \ android-dev-container -- \
develop \ develop "${project}"; then
"${project}"; then
fail "Unable to launch development container for ${project}" fail "Unable to launch development container for ${project}"
fi fi

View File

@ -17,10 +17,12 @@ services:
context: . context: .
args: args:
- NODE_ENV=development - NODE_ENV=development
privileged: true
environment: environment:
- NODE_ENV=development - NODE_ENV=development
tty: true tty: true
ports: ports:
- '8081:8081' # expo web browser
- '19006:19006' - '19006:19006'
- '19001:19001' - '19001:19001'
- '19002:19002' - '19002:19002'
@ -31,7 +33,7 @@ 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:rw
- ./scripts:/scripts:rw - ./scripts:/scripts:rw
healthcheck: healthcheck:
disable: true disable: true

4
env.sh Normal file
View File

@ -0,0 +1,4 @@
ANDROID_HOME=$(pwd)/AndroidSDK
ANDROID_AVD_HOME=$(pwd)/AndroidUser/avd
ANDROID_USER_HOME=$(pwd)/AndroidUser
PATH=$PATH:$ANDROID_HOME/cmdline-tools/tools/bin:$ANDROID_HOME/emulator

View File

@ -13,11 +13,48 @@ fi
declare full_path=$(realpath "projects/${project}") declare full_path=$(realpath "projects/${project}")
if ! docker compose run --rm \ declare project_type=$(cat "${full_path}/project_type")
--name "${project}-seed" \
-v "${full_path}:/projects/${project}" \ if [[ "${project_type}" == "expo" ]]; then
android-dev-container -- \ echo "Launching EXPO container"
run \ ports=(
"${project}"; then "8081:8081"
)
volumes=(
./flutter:/usr/bin/flutter
./AndroidSDK:/opt/android-sdk:rw
./scripts:/scripts:rw
/tmp/.X11-unix:/tmp/.X11-unix
$(pwd)/AndroidUser:/root/.android
)
fi
# Always add the project volume mount
volumes=("${volumes[@]}" "${full_path}:/projects/${project}")
if [ ${#ports[@]} -ne 0 ]; then
port_arg=""
for port in "${ports[@]}"; do
port_arg="${port_arg} -p ${port}"
done
fi
if [ ${#volumes[@]} -ne 0 ]; then
volume_arg=""
for volume in "${volumes[@]}"; do
volume_arg="${volume_arg} -v ${volume}"
done
fi
# --privileged is needed to be able to run the emulator
docker_cmd="docker compose run --rm
--name ${project}-seed
${port_arg}
${volume_arg}
android-dev-container --
run ${project} $(hostname)"
echo "${docker_cmd}"
if ! ${docker_cmd}; then
fail "Unable to start container for ${project}" fail "Unable to start container for ${project}"
fi fi

View File

@ -60,6 +60,27 @@ if (( parse_error )); then
exit 1 exit 1
fi fi
runtime_config() {
export project=$1
if [[ "${2}" != "" ]]; then
export REACT_NATIVE_PACKAGER_HOSTNAME="${2}"
fi
export project_type=$(cat "/projects/${project}/project_type")
cd "/projects/${project}"
echo "Setting safe.directory on ${PWD}"
git config --global --add safe.directory "${PWD}"
case "${project_type}" in
"expo")
# echo "Installing expo..."
# npm install -g expo
# echo "Installing expo-doctor..."
# npx expo install expo-doctor
;;
"flutter")
;;
esac
}
case "${command}" in case "${command}" in
init) init)
if [[ ! -e "${ANDROID_HOME}"/license/android-sdk-license ]]; then if [[ ! -e "${ANDROID_HOME}"/license/android-sdk-license ]]; then
@ -74,14 +95,13 @@ seed-project)
seed-project "${options[@]}" seed-project "${options[@]}"
exit $? exit $?
;; ;;
develop) develop)
project="${1}" runtime_config ${1} ${2}
project_type=$(cat "/projects/${project}/project_type")
cd "/projects/${project}"
case "${project_type}" in case "${project_type}" in
"expo") "expo")
echo "Launching web app in ${project}" echo "Launching terminal in ${project}"
npm run web /bin/bash
;; ;;
"flutter") "flutter")
echo "Launching terminal in ${project}" echo "Launching terminal in ${project}"
@ -89,14 +109,13 @@ develop)
;; ;;
esac esac
;; ;;
run) run)
project="${1}" runtime_config ${1} ${2}
cd "/projects/${project}"
project_type=$(cat "/projects/${project}/project_type")
case "${project_type}" in case "${project_type}" in
"expo") "expo")
echo "Starting web app in ${project}" echo "Starting expo app in ${project}"
while true; do npm run web; sleep 5; done while true; do npx expo start; sleep 5; done
;; ;;
"flutter") "flutter")
echo "Launching terminal in ${project}" echo "Launching terminal in ${project}"
@ -104,10 +123,12 @@ run)
;; ;;
esac esac
;; ;;
*bash|shell) *bash|shell)
/bin/bash "${options[@]}" /bin/bash "${options[@]}"
exit $? exit $?
;; ;;
*) *)
${command} "${@}" ${command} "${@}"
;; ;;

View File

@ -87,17 +87,32 @@ case "${project_type}" in
# #
# 'npx expo init' was replaced with 'npx create-expo-app' # 'npx expo init' was replaced with 'npx create-expo-app'
# #
echo "Seeding expo project ${project} in $(pwd)/${project}..." echo "Seeding expo project ${project} in $(pwd)/${project} (answer 'y' if prompted)..."
if ! npx create-expo-app "${project}"; then if ! npx create-expo-app -y "${project}"; then
fail "npx create-expo-app ${project}" fail "npx create-expo-app ${project}"
fi fi
cd "${project}" cd "${project}"
if [[ ! -d install ]]; then
if ! npx expo install react-native-web react-dom @expo/webpack-config; then mkdir install
fail "npx expo install react-native-web react-dom @expo/webpack-config"
fi fi
echo "Installing react and webpack into expo environment..."
npm install -g eas-cli
pkgs=(
react-native-web
react-dom
expo-dev-client
)
# @expo/webpack-config
for pkg in "${pkgs[@]}"; do
if ! npx expo install "${pkg}"; then
fail "npx expo install ${pkg}"
fi
done
echo "Installing node packages..." echo "Installing node packages..."
if ! npm install; then if ! npm install; then
fail "npm install" fail "npm install"
@ -109,6 +124,7 @@ case "${project_type}" in
echo "${project_type}" > project_type echo "${project_type}" > project_type
;; ;;
"flutter") "flutter")
ls -altr /usr/bin/flutter ls -altr /usr/bin/flutter
declare version="flutter_linux_3.22.2-stable.tar.xz" declare version="flutter_linux_3.22.2-stable.tar.xz"

View File

@ -26,9 +26,11 @@ if ! docker compose run -it --rm \
android-dev-container -- \ android-dev-container -- \
seed-project \ seed-project \
"${project_type}" \ "${project_type}" \
"${project}" \
-- \
-u $(id -u) \ -u $(id -u) \
-g $(id) \ -g $(id) \
"${project}"; then ; then
fail "Unable to run seed-project for ${project}" fail "Unable to run seed-project for ${project}"
else else
echo "Project '${project}' now exists in projects/${project}" echo "Project '${project}' now exists in projects/${project}"

View File

@ -7,15 +7,14 @@ fail() {
declare project=$1 declare project=$1
if [[ "${project}" == "" ]]; then if [[ "${project}" == "" ]]; then
echo "usage: ${0} PROJECT" >&2 echo "usage: $0 PROJECT" >&2
exit 1 exit 1
fi fi
declare full_path=$(realpath "projects/${project}") declare full_path=$(realpath "projects/${project}")
if ! docker compose exec -it \ if ! docker exec -it \
"${project}" \ ${project}-seed \
shell; then /bin/bash; then
fail "Unable to launch shell in '${project}'. Make sure it is running via './launch.sh ${project}'." fail "Unable to launch shell in ${project}-seed"
fi fi