diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68233b9..d9a8dd7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,7 @@ name: build on: + workflow_dispatch: push: branches: [ master ] pull_request: @@ -10,9 +11,11 @@ jobs: build: if: "! contains(toJSON(github.event.commits.*.message), 'skip ci')" - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - name: Build the Docker image - run: ./build.sh + shell: bash + run: | + ./build.sh -d diff --git a/Dockerfile b/Dockerfile index 905f465..9a099c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,36 @@ -FROM ubuntu:xenial +FROM ubuntu:bionic LABEL maintainer="Balázs Varga " LABEL description="Android Build Tools" -ARG ANDROID_TOOLS_VERSION=6200805 -ARG ANDROID_PLATFORM_VERSION=29 -ARG ANDROID_BUILD_TOOLS_VERSION=29.0.3 +ARG ANDROID_COMMAND_LINE_TOOLS=11076708 +ARG ANDROID_PLATFORM_VERSION=34 +ARG ANDROID_BUILD_TOOLS_VERSION=34.0.0 -ENV ANDROID_SDK_FILE_NAME commandlinetools-linux-${ANDROID_TOOLS_VERSION}_latest.zip +ENV ANDROID_SDK_FILE_NAME commandlinetools-linux-${ANDROID_COMMAND_LINE_TOOLS}_latest.zip ENV ANDROID_SDK_URL https://dl.google.com/android/repository/${ANDROID_SDK_FILE_NAME} ENV ANDROID_HOME /opt/android-sdk-linux ENV ANDROID_SDK ${ANDROID_HOME} ENV ANDROID_BUILD_TOOLS ${ANDROID_HOME}/build-tools/${ANDROID_BUILD_TOOLS_VERSION} -ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${ANDROID_BUILD_TOOLS} +ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${ANDROID_BUILD_TOOLS}:${ANDROID_HOME}/cmdline-tools/bin # Install requirements RUN dpkg --add-architecture i386 && \ apt-get -y update && \ - apt-get -y install \ - openjdk-8-jre \ - wget \ - unzip && \ - mkdir -p ${ANDROID_HOME} && \ + apt-get -y install openjdk-17-jre wget unzip + +# Download Android SDK +RUN mkdir -p ${ANDROID_HOME} && \ cd ${ANDROID_HOME} && \ wget -q ${ANDROID_SDK_URL} && \ unzip ${ANDROID_SDK_FILE_NAME} && \ - rm ${ANDROID_SDK_FILE_NAME} && \ - yes | sdkmanager --sdk_root=${ANDROID_HOME} "tools" "platforms;android-${ANDROID_PLATFORM_VERSION}" "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" && \ - apt-get -y remove wget unzip && \ + rm ${ANDROID_SDK_FILE_NAME} + +# Install Android SDK +RUN yes | sdkmanager --sdk_root=${ANDROID_HOME} "tools" "platforms;android-${ANDROID_PLATFORM_VERSION}" "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" + +# Clean +RUN apt-get -y remove wget unzip && \ apt-get -y autoremove && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* diff --git a/README.md b/README.md index 68c0db8..7f126a0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![build](https://github.com/warnyul/docker-android-build-tools/workflows/build/badge.svg) ![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/warnyul/android-build-tools/latest) ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/warnyul/android-build-tools/latest) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](LICENSE) -This is an Ubuntu Xential based Docker image and is image only contains Open JDK 8 JRE, Android SDK Tools, Android SDK Build Tools and the Platform which version belongs to the Build Tools's version. For instance: `warnyul/android-build-tools:29.0.3` image containts `platform;android-29`, and the `warnyul/android-build-tools:28.0.0` image contains `platform;android-28` and so on. +This is an Ubuntu Bionic based Docker image and is image only contains Open JDK 17 JRE, Android SDK Tools, Android SDK Build Tools and the Platform which version belongs to the Build Tools's version. For instance: `warnyul/android-build-tools:29.0.3` image containts `platform;android-29`, and the `warnyul/android-build-tools:28.0.0` image contains `platform;android-28` and so on. ## Usage diff --git a/build.sh b/build.sh index bc34fd2..9f2ad36 100755 --- a/build.sh +++ b/build.sh @@ -10,21 +10,18 @@ read -r -d '' USAGE <<- EOM --build-tools-version=VERSION \t Android build tools version. Default: 29.0.3\n --platform-version \t\t Android platform version. Default same as the build tools version.\n -l, --latest \t\t\t Flag build to latest\n - -lp, --local-push \t\t Push to a local repository. (always flag build to latest)\n - -p, --push \t\t\t Push image to docker hub\n + -d, --dry-run \t\t Push to a local repository. (always flag build to latest). Without push the image to the docker hub.\n -h, --help \t\t\t Print usage description\n EOM IMAGE_NAME=android-build-tools -IMAGE=warnyul/$IMAGE_NAME -LOCAL_IMAGE=localhost:5000/$IMAGE_NAME +IMAGE=warnyul/"$IMAGE_NAME" # Parameters LOCAL_PUSH=false -PUSH=false LATEST=false -BUILD_TOOLS_VERSION="29.0.3" -PLATFORM_VERSION=$(echo $BUILD_TOOLS_VERSION | cut -d'.' -f1) +BUILD_TOOLS_VERSION="30.0.0" +PLATFORM_VERSION=$(echo "$BUILD_TOOLS_VERSION" | cut -d'.' -f1) while [ $# -gt 0 ]; do case "$1" in @@ -32,7 +29,7 @@ while [ $# -gt 0 ]; do BUILD_TOOLS_VERSION="${1#*=}" if [ -z $BUILD_TOOLS_VERSION ]; then echo -e "\n --build-tools-version is required.\n See './build.sh --help'.\n" - echo -e $USAGE + echo -e "$USAGE" exit 1 fi ;; @@ -40,49 +37,45 @@ while [ $# -gt 0 ]; do PLATFORM_VERSION="${1#*=}" if [ -z $PLATFORM_VERSION ]; then echo -e "\n --platform-version is required.\n See './build.sh --help'.\n" - echo -e $USAGE + echo -e "$USAGE" exit 1 fi ;; -l|--latest) LATEST=true ;; - -lp|--local-push) + -d|--dry-run) LATEST=true LOCAL_PUSH=true - ;; - -p|--push) - PUSH=true + IMAGE=localhost:5000/"$IMAGE_NAME" ;; -h|--help|*) echo -e "\n Unknown argument: '$1'.\n See './build.sh --help'.\n" - echo -e $USAGE + echo -e "$USAGE" exit 1 ;; esac shift done +IMAGE_VERSION="$BUILD_TOOLS_VERSION"-bionic-openjdk17 + # Build docker build \ --build-arg ANDROID_BUILD_TOOLS_VERSION=$BUILD_TOOLS_VERSION \ --build-arg ANDROID_PLATFORM_VERSION=$PLATFORM_VERSION \ - -t "$IMAGE:$BUILD_TOOLS_VERSION" . + -t "$IMAGE":"$IMAGE_VERSION" . -if $LATEST; then - docker tag "$IMAGE:$BUILD_TOOLS_VERSION" "$IMAGE:latest" +# Start a local registry if necessary +if "$LOCAL_PUSH" == "true"; then + docker run -d -p 5000:5000 --restart=always --name registry registry 2>&1 fi -# Publish to a local repo -if $LOCAL_PUSH; then - docker run -d -p 5000:5000 --restart=always --name registry registry 2> /dev/null - docker tag "$IMAGE:$BUILD_TOOLS_VERSION" "$LOCAL_IMAGE:$BUILD_TOOLS_VERSION" - docker tag "$IMAGE:$BUILD_TOOLS_VERSION" "$LOCAL_IMAGE:latest" - docker push $LOCAL_IMAGE -fi - -# Publish to Docker Hub -if $PUSH; then - docker push $IMAGE +# Tag as latest if necessary +if "$LATEST" == "true"; then + docker tag "$IMAGE":"$IMAGE_VERSION" "$IMAGE":latest fi +# Push the image +echo push "$IMAGE":"$IMAGE_VERSION" +docker push "$IMAGE"