Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile for easy building with custom API key support #1571

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
.github
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CUSTOM_API_KEY=""
REDDIT_USER=""
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ fabric.properties
!/gradle/wrapper/gradle-wrapper.jar

# End of https://www.gitignore.io/api/androidstudio

.env
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:latest

RUN apt update && apt upgrade -y
RUN apt install -y openjdk-11-jdk wget unzip
RUN wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
RUN unzip -q android-sdk.zip -d /tmp/android-sdk

ENV ANDROID_SDK_ROOT="/tmp/android-sdk"
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
ENV PATH="${PATH}:/tmp/android-sdk/tools/bin:/tmp/android-sdk/platform-tools"

RUN yes | /tmp/android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT "platforms;android-30" "build-tools;30.0.3"

ENV CUSTOM_API_KEY=""
ENV REDDIT_USER=""

COPY . /content
WORKDIR /content

ENTRYPOINT [ "scripts/start-compilation.sh" ]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Bitcoin: bc1qxtkd5ap9na7uy8nr9qpt6jny6tdwaj4v43ddle
- [Variables reference](#variables-reference)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [Build Instructions](#build-instructions)
- [Support](#support)
- [License](#license)
- [Acknowledgements](#acknowledgements)
Expand Down Expand Up @@ -167,6 +168,12 @@ Here are other ways you can help:

<p align="right">(<a href="#top">back to top</a>)</p>

## Build Instructions

There's a dedicated Docker-based build approach, which also allows to use a custom API key & User Agent. To run it, make sure you have Docker installed and set up in your machine, then copy the `.env.sample` to `.env` to change the API key & User Agent if you want. Then run `./build.sh`.

After the shell script finishes the build, you'll find the `Infinity.apk` file on the root of this directory.

## License

Distributed under the AGPL-3.0 License. See <a href="https://github.com/Docile-Alligator/Infinity-For-Reddit/blob/master/LICENSE">LICENSE</a> for more information.
Expand Down
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

CONTAINER_NAME="infinity-builder"

source .env || true

docker build -t infinity-builder .
docker run -it -e CUSTOM_API_KEY=$CUSTOM_API_KEY -e REDDIT_USER=$REDDIT_USER --name $CONTAINER_NAME infinity-builder /bin/bash
docker cp $CONTAINER_NAME:/content/app/build/outputs/apk/release/app-release.apk ./Infinity.apk
docker rm $CONTAINER_NAME
15 changes: 15 additions & 0 deletions scripts/fix-api-key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

echo "Custom API key: $CUSTOM_API_KEY"
echo "Custom UA: $REDDIT_USER"

if [ -z "$CUSTOM_API_KEY" ]
then
echo "No custom API key, just building..."
else
echo "Custom API key detected, setting it up along the custom UA..."

sed -i "s/NOe2iKrPPzwscA/$CUSTOM_API_KEY/" app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
sed -i "s|infinity://localhost|http://127.0.0.1|" app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
sed -iE "s/public static final String USER_AGENT = \"(.*)\";/public static final String USER_AGENT = \"android:personal-app:0.0.1 (by \/u\/$REDDIT_USER)\";/" app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
fi
22 changes: 22 additions & 0 deletions scripts/setup-keystore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python3

print("Setting up keystore file...")

build_gradle_file = "./app/build.gradle"
build_gradle_code = open(build_gradle_file, "r", encoding="utf-8-sig").read()
build_gradle_code = build_gradle_code.replace(r""" buildTypes {""", r""" signingConfigs {
release {
storeFile file("/content/Infinity.jks")
storePassword "Infinity"
keyAlias "Infinity"
keyPassword "Infinity"
}
}
buildTypes {""")
build_gradle_code = build_gradle_code.replace(r""" buildTypes {
release {""", r""" buildTypes {
release {
signingConfig signingConfigs.release""")

with open(build_gradle_file, "w", encoding="utf-8") as f:
f.write(build_gradle_code)
11 changes: 11 additions & 0 deletions scripts/start-compilation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo "Infinity for Reddit Docker Builder"

./scripts/fix-api-key.sh

wget https://github.com/TanukiAI/Infinity-keystore/raw/main/Infinity.jks

python3 ./scripts/setup-keystore.py

./gradlew assembleRelease