FROM {{ moodle_image }}:{{ moodle_version }}

{% if applications | get_app_conf(application_id, 'features.oidc', False) %}
RUN install_packages unzip curl jq \
 && VERSION=$(curl -s https://api.github.com/repos/microsoft/moodle-auth_oidc/tags \
      | jq -r '.[].name' \
      | grep v{{ moodle_version }} \
      | sort -Vr \
      | head -n1) \
 && echo "Using version $VERSION" \
 && curl -L -o /tmp/oidc.zip https://github.com/microsoft/moodle-auth_oidc/archive/refs/tags/${VERSION}.zip \
 && unzip /tmp/oidc.zip -d /tmp \
 && mv /tmp/moodle-auth_oidc-* {{ bitnami_oidc_plugin_dir }} \
 && chown -R {{ bitnami_user_group }} {{ bitnami_oidc_plugin_dir }} \
 && rm -rf /tmp/oidc.zip
{% endif %}
