Skip to content

Commit 7ebbdf0

Browse files
author
Pablo Merino
committed
Add docker build
1 parent fc46284 commit 7ebbdf0

File tree

9 files changed

+91
-0
lines changed

9 files changed

+91
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Dockerfile
2+
.github

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CUSTOM_API_KEY=""
2+
REDDIT_USER=""

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,5 @@ fabric.properties
114114
!/gradle/wrapper/gradle-wrapper.jar
115115

116116
# End of https://www.gitignore.io/api/androidstudio
117+
118+
.env

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:latest
2+
3+
RUN apt update && apt upgrade -y
4+
RUN apt install -y openjdk-11-jdk wget unzip
5+
RUN wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
6+
RUN unzip -q android-sdk.zip -d /tmp/android-sdk
7+
8+
ENV ANDROID_SDK_ROOT="/tmp/android-sdk"
9+
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
10+
ENV PATH="${PATH}:/tmp/android-sdk/tools/bin:/tmp/android-sdk/platform-tools"
11+
12+
RUN yes | /tmp/android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT "platforms;android-30" "build-tools;30.0.3"
13+
14+
ENV CUSTOM_API_KEY=""
15+
ENV REDDIT_USER=""
16+
17+
COPY . /content
18+
WORKDIR /content
19+
20+
ENTRYPOINT [ "scripts/start-compilation.sh" ]

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Bitcoin: bc1qxtkd5ap9na7uy8nr9qpt6jny6tdwaj4v43ddle
7878
- [Variables reference](#variables-reference)
7979
- [Roadmap](#roadmap)
8080
- [Contributing](#contributing)
81+
- [Build Instructions](#build-instructions)
8182
- [Support](#support)
8283
- [License](#license)
8384
- [Acknowledgements](#acknowledgements)
@@ -167,6 +168,12 @@ Here are other ways you can help:
167168

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

171+
## Build Instructions
172+
173+
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`.
174+
175+
After the shell script finishes the build, you'll find the `Infinity.apk` file on the root of this directory.
176+
170177
## License
171178

172179
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.

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
CONTAINER_NAME="infinity-builder"
4+
5+
source .env || true
6+
7+
docker build -t infinity-builder .
8+
docker run -it -e CUSTOM_API_KEY=$CUSTOM_API_KEY -e REDDIT_USER=$REDDIT_USER --name $CONTAINER_NAME infinity-builder /bin/bash
9+
docker cp $CONTAINER_NAME:/content/app/build/outputs/apk/release/app-release.apk ./Infinity.apk
10+
docker rm $CONTAINER_NAME

scripts/fix-api-key.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
echo "Custom API key: $CUSTOM_API_KEY"
4+
echo "Custom UA: $REDDIT_USER"
5+
6+
if [ -z "$CUSTOM_API_KEY" ]
7+
then
8+
echo "No custom API key, just building..."
9+
else
10+
echo "Custom API key detected, setting it up along the custom UA..."
11+
12+
sed -i "s/NOe2iKrPPzwscA/$CUSTOM_API_KEY/" app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
13+
sed -i "s|infinity://localhost|http://127.0.0.1|" app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
14+
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
15+
fi

scripts/setup-keystore.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/python3
2+
3+
print("Setting up keystore file...")
4+
5+
build_gradle_file = "./app/build.gradle"
6+
build_gradle_code = open(build_gradle_file, "r", encoding="utf-8-sig").read()
7+
build_gradle_code = build_gradle_code.replace(r""" buildTypes {""", r""" signingConfigs {
8+
release {
9+
storeFile file("/content/Infinity.jks")
10+
storePassword "Infinity"
11+
keyAlias "Infinity"
12+
keyPassword "Infinity"
13+
}
14+
}
15+
buildTypes {""")
16+
build_gradle_code = build_gradle_code.replace(r""" buildTypes {
17+
release {""", r""" buildTypes {
18+
release {
19+
signingConfig signingConfigs.release""")
20+
21+
with open(build_gradle_file, "w", encoding="utf-8") as f:
22+
f.write(build_gradle_code)

scripts/start-compilation.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
echo "Infinity for Reddit Docker Builder"
4+
5+
./scripts/fix-api-key.sh
6+
7+
wget https://github.com/TanukiAI/Infinity-keystore/raw/main/Infinity.jks
8+
9+
python3 ./scripts/setup-keystore.py
10+
11+
./gradlew assembleRelease

0 commit comments

Comments
 (0)