From 46b0f22e32394c3b0fb80d8fefa5980e92bebed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Thu, 4 May 2023 15:07:42 +0200 Subject: [PATCH] feat: upgrade to Palm --- CHANGELOG.md | 6 ++ README.rst | 5 ++ changelog.d/20230519_161836_regis.md | 1 - setup.py | 6 +- tutorandroid/__about__.py | 2 +- .../patches/local-docker-compose-dev-services | 3 + .../patches/local-docker-compose-services | 2 - tutorandroid/plugin.py | 44 +++++++++-- .../templates/android/build/Dockerfile | 73 +++++++++++++++++++ .../android/build/android/Dockerfile | 37 ---------- .../templates/android/build/app/Dockerfile | 20 ----- .../android/build/{app => }/config/.gitignore | 0 .../build/{app => }/config/edx.properties | 0 .../build/{app => }/config/gradle.properties | 0 .../android/build/{app => }/config/tutor.yaml | 0 15 files changed, 129 insertions(+), 70 deletions(-) delete mode 100644 changelog.d/20230519_161836_regis.md create mode 100644 tutorandroid/patches/local-docker-compose-dev-services create mode 100644 tutorandroid/templates/android/build/Dockerfile delete mode 100644 tutorandroid/templates/android/build/android/Dockerfile delete mode 100644 tutorandroid/templates/android/build/app/Dockerfile rename tutorandroid/templates/android/build/{app => }/config/.gitignore (100%) rename tutorandroid/templates/android/build/{app => }/config/edx.properties (100%) rename tutorandroid/templates/android/build/{app => }/config/gradle.properties (100%) rename tutorandroid/templates/android/build/{app => }/config/tutor.yaml (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5d920..7021aae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,3 +19,9 @@ instructions, because git commits are used to generate release notes: + +## v16.0.0 (2023-06-14) + +- 💥[Feature] Upgrade to Palm. (by @regisb) +- [Improvement] Add a scriv-compliant changelog. (by @regisb) + diff --git a/README.rst b/README.rst index 709b039..1ce7a69 100644 --- a/README.rst +++ b/README.rst @@ -31,6 +31,11 @@ The Android app is built from the `official edx-app-android repository =15.0.0,<16.0.0"], + python_requires=">=3.8", + install_requires=["tutor>=16.0.0,<17.0.0"], entry_points={ "tutor.plugin.v1": [ "android = tutorandroid.plugin" @@ -55,9 +55,9 @@ setup( "License :: OSI Approved :: GNU Affero General Public License v3", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", ], ) diff --git a/tutorandroid/__about__.py b/tutorandroid/__about__.py index 9d7ed14..60b692a 100644 --- a/tutorandroid/__about__.py +++ b/tutorandroid/__about__.py @@ -1,4 +1,4 @@ -__version__ = "15.0.0" +__version__ = "16.0.0" # Handle version suffix for nightly, just like tutor core. __version_suffix__ = "" diff --git a/tutorandroid/patches/local-docker-compose-dev-services b/tutorandroid/patches/local-docker-compose-dev-services new file mode 100644 index 0000000..dc09ad8 --- /dev/null +++ b/tutorandroid/patches/local-docker-compose-dev-services @@ -0,0 +1,3 @@ +android-app: + ports: + - "8321:8000" diff --git a/tutorandroid/patches/local-docker-compose-services b/tutorandroid/patches/local-docker-compose-services index 1492ae0..c1babd9 100644 --- a/tutorandroid/patches/local-docker-compose-services +++ b/tutorandroid/patches/local-docker-compose-services @@ -1,6 +1,4 @@ # Android app android-app: image: {{ ANDROID_APP_DOCKER_IMAGE }} - build: - context: ../plugins/android/build/app/ restart: unless-stopped diff --git a/tutorandroid/plugin.py b/tutorandroid/plugin.py index feb20a6..e044aa6 100644 --- a/tutorandroid/plugin.py +++ b/tutorandroid/plugin.py @@ -1,5 +1,9 @@ +from __future__ import annotations + from glob import glob import os +import typing as t + import pkg_resources from tutor import hooks as tutor_hooks @@ -11,9 +15,9 @@ config = { "defaults": { "VERSION": __version__, "APP_HOST": "mobile.{{ LMS_HOST }}", - # Unfortunately 3.2.2 is not functional: https://github.com/openedx/build-test-release-wg/issues/211#issuecomment-1344311500 - # "APP_VERSION": "3.2.2", # https://github.com/openedx/edx-app-android/releases - "APP_VERSION": "3.0.2", + # Version 4.0.0 is not working: + # https://github.com/overhangio/tutor-android/pull/6#issuecomment-1541510489 + "APP_VERSION": "3.1.4", "DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android:{{ ANDROID_VERSION }}", "APP_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android-app:{{ ANDROID_VERSION }}", "ENABLE_RELEASE_MODE": False, @@ -43,13 +47,13 @@ tutor_hooks.Filters.IMAGES_BUILD.add_items( [ ( "android", - ("plugins", "android", "build", "android"), + os.path.join("plugins", "android", "build"), "{{ ANDROID_DOCKER_IMAGE }}", - (), + ("--target=common",), ), ( "android-app", - ("plugins", "android", "build", "app"), + os.path.join("plugins", "android", "build"), "{{ ANDROID_APP_DOCKER_IMAGE }}", (), ), @@ -91,6 +95,34 @@ tutor_hooks.Filters.IMAGES_PUSH.add_item( ) ) + +# Build app image on launch +tutor_hooks.Filters.IMAGES_BUILD_REQUIRED.add_item("android-app") + + +# Mount custom edx-app-android repo at build time +@tutor_hooks.Filters.IMAGES_BUILD_MOUNTS.add() +def _build_custom_android_app( + mounts: list[tuple[str, str]], host_path: str +) -> list[tuple[str, str]]: + path_basename = os.path.basename(host_path) + if path_basename == "edx-app-android": + # Bind-mount repo at build-time + mounts.append(("android", "edx-app-android")) + return mounts + + +@tutor_hooks.Filters.APP_PUBLIC_HOSTS.add() +def _print_android_app_public_hosts( + hostnames: list[str], context_name: t.Literal["local", "dev"] +) -> list[str]: + if context_name == "local": + hostnames.append("{{ ANDROID_APP_HOST }}") + else: + hostnames.append("{{ ANDROID_APP_HOST }}:8321") + return hostnames + + ####### Boilerplate code # Add the "templates" folder as a template root tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item( diff --git a/tutorandroid/templates/android/build/Dockerfile b/tutorandroid/templates/android/build/Dockerfile new file mode 100644 index 0000000..40a47f4 --- /dev/null +++ b/tutorandroid/templates/android/build/Dockerfile @@ -0,0 +1,73 @@ +FROM docker.io/ubuntu:22.04 AS base +LABEL maintainer="Overhang.IO " + +ENV DEBIAN_FRONTEND=noninteractive +RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked {% endif %}apt update && \ + apt upgrade -y && \ + apt install -y wget unzip git openjdk-11-jre openjdk-11-jdk + +RUN mkdir /app + +###### Install Android SDK +FROM base AS sdk + +# Install Android SDK +# Inspired from https://github.com/LiveXP/docker-android-sdk/blob/master/Dockerfile +# Get sdk version from here: https://developer.android.com/studio#command-tools +ENV ANDROID_SDK_VERSION 9477386 +ENV ANDROID_SDK_PATH /app/android-sdk +ENV ANDROID_HOME /app/android-sdk +RUN mkdir ${ANDROID_HOME} +WORKDIR /app/android-sdk +RUN wget --quiet https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip && \ + unzip commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip && \ + rm commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip + +# Accept licenses +# https://developer.android.com/studio/command-line/sdkmanager +# Check target version: https://github.com/edx/edx-app-android/blob/master/constants.gradle +ARG ANDROID_API_LEVEL=31 +RUN yes | /app/android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install "platforms;android-$ANDROID_API_LEVEL" 1> /dev/null + +###### Checkout code +FROM base AS code +# Install android app repo +ARG ANDROID_APP_REPOSITORY=https://github.com/openedx/edx-app-android +ARG ANDROID_APP_VERSION=release/{{ ANDROID_APP_VERSION }} +RUN git clone $ANDROID_APP_REPOSITORY --branch $ANDROID_APP_VERSION /app/edx-app-android + +###### Empty layer to mount custom repo at build time +FROM scratch AS edx-app-android +COPY --from=code /app/edx-app-android / + +###### Common layer, which will be used to build the user-specific image later +FROM sdk AS common + +COPY --from=edx-app-android / /app/edx-app-android +WORKDIR /app/edx-app-android + +# Install gradle and all dependencies +RUN ./gradlew -v +RUN ./gradlew tasks + +###### Build image with app-specific settings +FROM common as build + +# User-customized config +COPY ./config/edx.properties ./OpenEdXMobile/default_config/edx.properties +COPY ./config/tutor.yaml ./OpenEdXMobile/default_config/tutor.yaml +{% if ANDROID_ENABLE_RELEASE_MODE %} +# Add release settings +COPY ./config/gradle.properties ./gradle.properties.tutor +RUN cat ./gradle.properties.tutor >> ./gradle.properties +{% endif %} + +RUN sed -i "s/APPLICATION_ID = .*/APPLICATION_ID = \"{{ LMS_HOST|reverse_host|replace("-", "_") }}\"/g" constants.gradle +RUN ./gradlew assembleProd{{ "Release" if ANDROID_ENABLE_RELEASE_MODE else "Debuggable" }} + +#### File server to serve apk file +# https://hub.docker.com/_/caddy?tab=tags +FROM docker.io/caddy:2.6.4-alpine as production +COPY --from=build /app/edx-app-android/OpenEdXMobile/build/outputs/apk/prod/{{ "release" if ANDROID_ENABLE_RELEASE_MODE else "debuggable" }}/edx-{{ "release" if ANDROID_ENABLE_RELEASE_MODE else "debuggable" }}-{{ ANDROID_APP_VERSION }}.apk /srv/app.apk +CMD caddy file-server --listen=:8000 --root=/srv diff --git a/tutorandroid/templates/android/build/android/Dockerfile b/tutorandroid/templates/android/build/android/Dockerfile deleted file mode 100644 index 60f5ded..0000000 --- a/tutorandroid/templates/android/build/android/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -FROM docker.io/ubuntu:20.04 -MAINTAINER Overhang.io - -ENV DEBIAN_FRONTEND=noninteractive -RUN apt update && \ - apt upgrade -y && \ - apt install -y wget unzip git openjdk-8-jre openjdk-8-jdk - -RUN mkdir /app - -# Install Android SDK -# Inspired from https://github.com/LiveXP/docker-android-sdk/blob/master/Dockerfile -# Get sdk version from here: https://developer.android.com/studio#command-tools -ENV ANDROID_SDK_VERSION 7583922 -ENV ANDROID_SDK_PATH /app/android-sdk -ENV ANDROID_HOME /app/android-sdk -RUN mkdir ${ANDROID_HOME} -WORKDIR /app/android-sdk -RUN wget --quiet https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip && \ - unzip commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip && \ - rm commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip - -# Accept licenses -# https://developer.android.com/studio/command-line/sdkmanager -# Check target version: https://github.com/edx/edx-app-android/blob/master/constants.gradle -ARG ANDROID_API_LEVEL=30 -RUN yes | /app/android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} --install "platforms;android-$ANDROID_API_LEVEL" 1> /dev/null - -# Install android app repo -ARG ANDROID_APP_REPOSITORY=https://github.com/openedx/edx-app-android -ARG ANDROID_APP_VERSION=release/{{ ANDROID_APP_VERSION }} -RUN git clone $ANDROID_APP_REPOSITORY --branch $ANDROID_APP_VERSION /app/edx-app-android -WORKDIR /app/edx-app-android - -# Install gradle and all dependencies -RUN ./gradlew -v -RUN ./gradlew tasks diff --git a/tutorandroid/templates/android/build/app/Dockerfile b/tutorandroid/templates/android/build/app/Dockerfile deleted file mode 100644 index d8de6ff..0000000 --- a/tutorandroid/templates/android/build/app/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -#### Build image with app-specific settings -FROM {{ ANDROID_DOCKER_IMAGE }} as build - -# User-customized config -COPY ./config/edx.properties ./OpenEdXMobile/default_config/edx.properties -COPY ./config/tutor.yaml ./OpenEdXMobile/default_config/tutor.yaml -{% if ANDROID_ENABLE_RELEASE_MODE %} -# Add release settings -COPY ./config/gradle.properties ./gradle.properties.tutor -RUN cat ./gradle.properties.tutor >> ./gradle.properties -{% endif %} - -RUN sed -i "s/APPLICATION_ID = .*/APPLICATION_ID = \"{{ LMS_HOST|reverse_host|replace("-", "_") }}\"/g" constants.gradle -RUN ./gradlew assembleProd{{ "Release" if ANDROID_ENABLE_RELEASE_MODE else "Debuggable" }} - -#### File server to serve apk file -# https://hub.docker.com/_/caddy?tab=tags -FROM docker.io/caddy:2.6.2-alpine as production -COPY --from=build /app/edx-app-android/OpenEdXMobile/build/outputs/apk/prod/{{ "release" if ANDROID_ENABLE_RELEASE_MODE else "debuggable" }}/edx-{{ "release" if ANDROID_ENABLE_RELEASE_MODE else "debuggable" }}-{{ ANDROID_APP_VERSION }}.apk /srv/app.apk -CMD caddy file-server --listen=:8000 --root=/srv diff --git a/tutorandroid/templates/android/build/app/config/.gitignore b/tutorandroid/templates/android/build/config/.gitignore similarity index 100% rename from tutorandroid/templates/android/build/app/config/.gitignore rename to tutorandroid/templates/android/build/config/.gitignore diff --git a/tutorandroid/templates/android/build/app/config/edx.properties b/tutorandroid/templates/android/build/config/edx.properties similarity index 100% rename from tutorandroid/templates/android/build/app/config/edx.properties rename to tutorandroid/templates/android/build/config/edx.properties diff --git a/tutorandroid/templates/android/build/app/config/gradle.properties b/tutorandroid/templates/android/build/config/gradle.properties similarity index 100% rename from tutorandroid/templates/android/build/app/config/gradle.properties rename to tutorandroid/templates/android/build/config/gradle.properties diff --git a/tutorandroid/templates/android/build/app/config/tutor.yaml b/tutorandroid/templates/android/build/config/tutor.yaml similarity index 100% rename from tutorandroid/templates/android/build/app/config/tutor.yaml rename to tutorandroid/templates/android/build/config/tutor.yaml