feat: upgrade to Palm

This commit is contained in:
Régis Behmo 2023-05-04 15:07:42 +02:00
parent ad501d21e4
commit 46b0f22e32
15 changed files with 129 additions and 70 deletions

View File

@ -19,3 +19,9 @@ instructions, because git commits are used to generate release notes:
<!-- scriv-insert-here -->
<a id='changelog-16.0.0'></a>
## v16.0.0 (2023-06-14)
- 💥[Feature] Upgrade to Palm. (by @regisb)
- [Improvement] Add a scriv-compliant changelog. (by @regisb)

View File

@ -31,6 +31,11 @@ The Android app is built from the `official edx-app-android repository <https://
--build-arg ANDROID_APP_VERSION=master \
android
Alternatively, you can build an image from a local checked-out fork of edx-app-android::
tutor mounts add /path/to/edx-app-android
tutor local launch
Releasing an Android app
~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1 +0,0 @@
- [Improvement] Add a scriv-compliant changelog. (by @regisb)

View File

@ -42,8 +42,8 @@ setup(
long_description=load_readme(),
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
python_requires=">=3.7",
install_requires=["tutor>=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",
],
)

View File

@ -1,4 +1,4 @@
__version__ = "15.0.0"
__version__ = "16.0.0"
# Handle version suffix for nightly, just like tutor core.
__version_suffix__ = ""

View File

@ -0,0 +1,3 @@
android-app:
ports:
- "8321:8000"

View File

@ -1,6 +1,4 @@
# Android app
android-app:
image: {{ ANDROID_APP_DOCKER_IMAGE }}
build:
context: ../plugins/android/build/app/
restart: unless-stopped

View File

@ -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(

View File

@ -0,0 +1,73 @@
FROM docker.io/ubuntu:22.04 AS base
LABEL maintainer="Overhang.IO <contact@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

View File

@ -1,37 +0,0 @@
FROM docker.io/ubuntu:20.04
MAINTAINER Overhang.io <contact@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

View File

@ -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