@Library('cadoles') _

// Utilisation du pipeline "standard"
// Voir https://forge.cadoles.com/Cadoles/Jenkins/src/branch/master/doc/tutorials/standard-make-pipeline.md
standardMakePipeline([
    'baseImage': 'reg.cadoles.com/proxy_cache/library/ubuntu:24.04',
    'dockerfileExtension': '''
    ARG GOLANG_VERSION=1.22.0
    ARG NODEJS_VERSION=20.x

    ENV ANDROID_HOME=/opt/android-sdk-linux
    ENV ANDROID_SDK_ROOT=${ANDROID_HOME}
    ENV ANDROID_NDK_HOME=${ANDROID_HOME}/ndk-bundle
    ENV PATH=${PATH}:/usr/local/go/bin/:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools

    # Install utilities
    RUN apt-get update -y \
    && apt-get install -y wget git curl tar build-essential ca-certificates git openjdk-17-jdk unzip locales jq moreutils

    # Set locale
    RUN locale-gen en_US.UTF-8
    ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'

    # Install NodeJS
    RUN wget -O- https://deb.nodesource.com/setup_${NODEJS_VERSION} | bash - \
        && apt-get update -y \
        && apt-get install -y nodejs

    # Install Golang
    RUN wget -O golang.tar.gz https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz \
        && tar -C /usr/local -xzf golang.tar.gz

    # Install Android SDK/NDK
    RUN mkdir -p /opt/android-sdk-linux
    WORKDIR /opt/android-sdk-linux

    RUN wget -O commandlinetools.zip https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip \
    && mkdir -p ${ANDROID_HOME}/cmdline-tools/latest \
    && unzip -q commandlinetools.zip -d ${ANDROID_HOME}/cmdline-tools/latest \
    && mv ${ANDROID_HOME}/cmdline-tools/latest/cmdline-tools/* ${ANDROID_HOME}/cmdline-tools/latest/ \
    && rm -f commandlinetools.zip

    RUN echo y | cmdline-tools/latest/bin/sdkmanager --install \
        'platforms;android-31' \
        'ndk-bundle' \
        'build-tools;34.0.0' \
        'tools' \
        'platform-tools' \
        'extras;android;m2repository' \
        'extras;google;m2repository' \
        'extras;google;google_play_services'
    ''',
    'hooks': [
        'pre-build': { 
            sh '''
            make .mktools
            '''
        }
    ],
    'credentials': [
        file(credentialsId: 'android-keystore', variable: 'ANDROID_KEYSTORE_FILE'),
        string(credentialsId: 'android-keystore-pass', variable: 'ANDROID_KEYSTORE_PASS'),
        usernamePassword(credentialsId: 'kipp-credentials', usernameVariable: 'MKT_GITEA_RELEASE_USERNAME', passwordVariable: 'MKT_GITEA_RELEASE_PASSWORD')
    ]
])