diff --git a/setup.py b/setup.py index 8075cbc..2e0f3b9 100644 --- a/setup.py +++ b/setup.py @@ -38,10 +38,10 @@ setup( long_description=load_readme(), packages=find_packages(exclude=["tests*"]), include_package_data=True, - python_requires=">=3.5", - install_requires=["tutor>=13.0.0,<14.0.0"], + python_requires=">=3.7", + install_requires=["tutor>=14.0.0,<15.0.0"], entry_points={ - "tutor.plugin.v0": [ + "tutor.plugin.v1": [ "android = tutorandroid.plugin" ] }, @@ -51,8 +51,6 @@ setup( "License :: OSI Approved :: GNU Affero General Public License v3", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", diff --git a/tutorandroid/__about__.py b/tutorandroid/__about__.py index 1311252..2294691 100644 --- a/tutorandroid/__about__.py +++ b/tutorandroid/__about__.py @@ -1 +1 @@ -__version__ = "13.0.0" +__version__ = "14.0.0" diff --git a/tutorandroid/plugin.py b/tutorandroid/plugin.py index c6ab305..3ccac96 100644 --- a/tutorandroid/plugin.py +++ b/tutorandroid/plugin.py @@ -2,18 +2,17 @@ from glob import glob import os import pkg_resources +from tutor import hooks as tutor_hooks + from .__about__ import __version__ -templates = pkg_resources.resource_filename("tutorandroid", "templates") - - config = { - "add": {"OAUTH2_SECRET": "{{ 24|random_string }}"}, + "unique": {"OAUTH2_SECRET": "{{ 24|random_string }}"}, "defaults": { "VERSION": __version__, "APP_HOST": "mobile.{{ LMS_HOST }}", - "APP_VERSION": "2.26.1", # https://github.com/edx/edx-app-android/releases + "APP_VERSION": "3.0.2", # https://github.com/edx/edx-app-android/releases "DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android:{{ ANDROID_VERSION }}", "APP_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android-app:{{ ANDROID_VERSION }}", "ENABLE_RELEASE_MODE": False, @@ -23,22 +22,71 @@ config = { }, } -hooks = { - "build-image": { - "android": "{{ ANDROID_DOCKER_IMAGE }}", - "android-app": "{{ ANDROID_APP_DOCKER_IMAGE }}", - }, - "remote-image": {"android": "{{ ANDROID_DOCKER_IMAGE }}"}, - "init": ["lms"], -} +tutor_hooks.Filters.COMMANDS_INIT.add_item( + ( + "lms", + ("android", "tasks", "lms", "init"), + ) +) +tutor_hooks.Filters.IMAGES_BUILD.add_items( + [ + ( + "android", + ("plugins", "android", "build", "android"), + "{{ ANDROID_DOCKER_IMAGE }}", + (), + ), + ( + "android-app", + ("plugins", "android", "build", "app"), + "{{ ANDROID_APP_DOCKER_IMAGE }}", + (), + ), + ] +) +tutor_hooks.Filters.IMAGES_PULL.add_item( + ( + "android", + "{{ ANDROID_DOCKER_IMAGE }}", + ) +) +tutor_hooks.Filters.IMAGES_PUSH.add_item( + ( + "android", + "{{ ANDROID_DOCKER_IMAGE }}", + ) +) - -def patches(): - all_patches = {} - patches_dir = pkg_resources.resource_filename("tutorandroid", "patches") - for path in glob(os.path.join(patches_dir, "*")): - with open(path) as patch_file: - name = os.path.basename(path) - content = patch_file.read() - all_patches[name] = content - return all_patches +####### Boilerplate code +# Add the "templates" folder as a template root +tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item( + pkg_resources.resource_filename("tutorandroid", "templates") +) +# Render the "build" and "apps" folders +tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items( + [ + ("android/build", "plugins"), + ("android/apps", "plugins"), + ], +) +# Load patches from files +for path in glob( + os.path.join( + pkg_resources.resource_filename("tutorandroid", "patches"), + "*", + ) +): + with open(path, encoding="utf-8") as patch_file: + tutor_hooks.Filters.ENV_PATCHES.add_item( + (os.path.basename(path), patch_file.read()) + ) +# Add configuration entries +tutor_hooks.Filters.CONFIG_DEFAULTS.add_items( + [(f"ANDROID_{key}", value) for key, value in config.get("defaults", {}).items()] +) +tutor_hooks.Filters.CONFIG_UNIQUE.add_items( + [(f"ANDROID_{key}", value) for key, value in config.get("unique", {}).items()] +) +tutor_hooks.Filters.CONFIG_OVERRIDES.add_items( + list(config.get("overrides", {}).items()) +) diff --git a/tutorandroid/templates/android/build/android/Dockerfile b/tutorandroid/templates/android/build/android/Dockerfile index ff0185b..c4976a2 100644 --- a/tutorandroid/templates/android/build/android/Dockerfile +++ b/tutorandroid/templates/android/build/android/Dockerfile @@ -23,7 +23,7 @@ RUN wget https://dl.google.com/android/repository/commandlinetools-linux-${ANDRO # 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=29 +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 diff --git a/tutorandroid/templates/android/build/app/Dockerfile b/tutorandroid/templates/android/build/app/Dockerfile index c6a4d92..881ca18 100644 --- a/tutorandroid/templates/android/build/app/Dockerfile +++ b/tutorandroid/templates/android/build/app/Dockerfile @@ -14,6 +14,7 @@ RUN sed -i "s/APPLICATION_ID = .*/APPLICATION_ID = \"{{ LMS_HOST|reverse_host|re RUN ./gradlew assembleProd{{ "Release" if ANDROID_ENABLE_RELEASE_MODE else "Debuggable" }} #### File server to serve apk file -FROM docker.io/caddy:2.4.3-alpine as production +# https://hub.docker.com/_/caddy?tab=tags +FROM docker.io/caddy:2.5.1-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/hooks/.gitignore b/tutorandroid/templates/android/tasks/.gitignore similarity index 100% rename from tutorandroid/templates/android/hooks/.gitignore rename to tutorandroid/templates/android/tasks/.gitignore diff --git a/tutorandroid/templates/android/hooks/lms/init b/tutorandroid/templates/android/tasks/lms/init similarity index 100% rename from tutorandroid/templates/android/hooks/lms/init rename to tutorandroid/templates/android/tasks/lms/init