From cc5a8bad1778d7cda86949e47177a3560cb98db9 Mon Sep 17 00:00:00 2001 From: Ben Curtis Date: Wed, 4 Oct 2023 20:14:56 -0400 Subject: [PATCH] Added support for PR builds on master (#3363) * added support for PR builds on master * add linefeed to .dockerignore * single dockerfile * fix dockerfile ref * update for java 17 lts --- .dockerignore | 4 +- .github/workflows/docker-beta.yml | 43 +++++++++++++++++++ .../{docker.yml => docker-release.yml} | 13 ++---- README.md | 2 +- Dockerfile => docker/Dockerfile | 32 +++++++++++--- DOCKER.md => docker/README.md | 2 +- 6 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/docker-beta.yml rename .github/workflows/{docker.yml => docker-release.yml} (81%) rename Dockerfile => docker/Dockerfile (64%) rename DOCKER.md => docker/README.md (99%) diff --git a/.dockerignore b/.dockerignore index f59ec20a..45cf84fd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ -* \ No newline at end of file +./docker +./github +*.md diff --git a/.github/workflows/docker-beta.yml b/.github/workflows/docker-beta.yml new file mode 100644 index 00000000..f366a3e2 --- /dev/null +++ b/.github/workflows/docker-beta.yml @@ -0,0 +1,43 @@ +name: Build and push docker (beta) + +on: + pull_request: + branches: [master] + types: [closed] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + + build_and_push: + name: Build and push + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Get hash + id: hash + run: echo "APKTOOL_HASH=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64 + file: ./docker/Dockerfile + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.APKTOOL_HASH }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:beta + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:master diff --git a/.github/workflows/docker.yml b/.github/workflows/docker-release.yml similarity index 81% rename from .github/workflows/docker.yml rename to .github/workflows/docker-release.yml index 5474ab80..571540ad 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker-release.yml @@ -1,17 +1,9 @@ -name: Build and push docker +name: Build and push docker (release) on: release: types: [published] -# Use the below to integrate into a Beta build from master -# Changes to the Dockerfile to use the manually built Jar -# from the build automation would be required. -# on: -# pull_request: -# branches: [master] -# types: [closed] - env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -45,9 +37,10 @@ jobs: with: context: . platforms: linux/amd64 - file: ./Dockerfile + file: ./docker/Dockerfile push: true tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.APKTOOL_HASH }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.APKTOOL_TAG }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:prod ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest diff --git a/README.md b/README.md index 94913b13..7d26c9f8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ If you discover a security vulnerability within Apktool, please send an e-mail t - [Downloads Mirror](https://connortumbleson.com/apktool/) - [How to Build](https://ibotpeaches.github.io/Apktool/build/) - [Documentation](https://ibotpeaches.github.io/Apktool/documentation/) -- [Use in Docker](./DOCKER.md) +- [Use in Docker](./docker/README.md) - [Bug Reports](https://github.com/iBotPeaches/Apktool/issues) - [Changelog/Information](https://ibotpeaches.github.io/Apktool/changes/) - [XDA Post](https://forum.xda-developers.com/t/util-dec-2-2020-apktool-tool-for-reverse-engineering-apk-files.1755243/) diff --git a/Dockerfile b/docker/Dockerfile similarity index 64% rename from Dockerfile rename to docker/Dockerfile index 37a5ef11..a4bc12ae 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,21 @@ -FROM openjdk:21-slim +# BUILDER +# ===================================================== +FROM ibm-semeru-runtimes:open-17-jdk-jammy AS builder + +COPY . /build +WORKDIR /build +RUN \ + # Apktool + ./gradlew build shadowJar proguard + +RUN \ + # Relocate for easier copying + JAR=$(find /build/brut.apktool/apktool-cli/build/libs/apktool-*.jar |grep -v cli-all) &&\ + mv ${JAR} /build/apktool.jar + +# BASE +# ===================================================== +FROM ibm-semeru-runtimes:open-17-jre-jammy AS base # Latest version as of 2023.10.01 # Ref: https://developer.android.com/studio/index.html#command-line-tools-only @@ -6,18 +23,21 @@ ARG COMMAND_LINE_TOOLS_VERSION=10406996 ARG ANDROID_SDK_ROOT=/opt/android-sdk +COPY --from=builder /build/apktool.jar /usr/local/bin/apktool.jar +COPY --from=builder /build/scripts/linux/apktool /usr/local/bin/apktool + RUN \ # Update apt-get update &&\ \ - # Apktool - apt-get install --no-install-recommends -y curl zipalign &&\ - curl -o /usr/local/bin/apktool https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool &&\ - curl -L -o /usr/local/bin/apktool.jar $(curl -s https://api.github.com/repos/iBotPeaches/Apktool/releases/latest |grep browser_download_url |awk '{print $2}' |sed 's/"//g') &&\ + # Apktool final setup chmod +x /usr/local/bin/apktool /usr/local/bin/apktool.jar &&\ \ # Android SDK apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + zipalign \ git \ openssl \ wget \ @@ -39,4 +59,4 @@ RUN \ ENV PATH ${PATH}:/opt/bin -CMD ["/usr/local/bin/apktool"] +CMD ["/usr/local/bin/apktool"] \ No newline at end of file diff --git a/DOCKER.md b/docker/README.md similarity index 99% rename from DOCKER.md rename to docker/README.md index 4060c8ac..f0bdbdf1 100644 --- a/DOCKER.md +++ b/docker/README.md @@ -24,4 +24,4 @@ apktool d My.apk -o MyFolder apktool b MyFolder -o MyNew.apk zipalign -p -f 4 MyNew.apk MyNewAligned.apk apksigner sign --ks My.keystore MyNewAligned.apk -``` \ No newline at end of file +```