-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
184 lines (154 loc) · 6.55 KB
/
Dockerfile
File metadata and controls
184 lines (154 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Multi-stage Dockerfile for LibriSync React Native + Rust build
# Force AMD64 platform for better compatibility with Android NDK
FROM --platform=linux/amd64 ubuntu:22.04 as builder
# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
# Install system dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
unzip \
build-essential \
pkg-config \
libssl-dev \
python3 \
python3-pip \
openjdk-17-jdk \
&& rm -rf /var/lib/apt/lists/*
# Set Java environment variables
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
ENV PATH=$PATH:$JAVA_HOME/bin
# Install Node.js 20.x
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Install Rust
ENV RUSTUP_HOME=/usr/local/rustup
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=/usr/local/cargo/bin:$PATH
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable \
&& chmod -R a+w /usr/local/rustup /usr/local/cargo
# Install Android SDK command line tools
ENV ANDROID_SDK_ROOT=/opt/android-sdk
ENV ANDROID_HOME=/opt/android-sdk
ENV PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/platform-tools
RUN mkdir -p $ANDROID_SDK_ROOT/cmdline-tools \
&& cd $ANDROID_SDK_ROOT/cmdline-tools \
&& wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip \
&& unzip commandlinetools-linux-*.zip \
&& rm commandlinetools-linux-*.zip \
&& mv cmdline-tools latest
# Accept Android SDK licenses and install required packages
RUN yes | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses --sdk_root=$ANDROID_SDK_ROOT || true
RUN $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT --verbose \
"platform-tools" \
"platforms;android-34" \
"build-tools;34.0.0" \
"ndk;29.0.14033849" \
"cmake;3.22.1" || (cat /root/.android/logs/*.log && exit 1)
# Set NDK environment variable
ENV ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/29.0.14033849
ENV ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/29.0.14033849
ENV PATH=$PATH:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin
# Install Rust Android targets
RUN rustup target add \
aarch64-linux-android \
armv7-linux-androideabi \
i686-linux-android \
x86_64-linux-android
# Build arguments for git clone
ARG GIT_REPO
ARG GIT_BRANCH=main
ARG BUILD_TYPE=debug
# Build argument for app version (extracted from git tag in CI/CD)
ARG APP_VERSION=""
# Build arguments for signing (optional, only used for release builds)
ARG KEYSTORE_FILE=""
ARG KEYSTORE_PASSWORD=""
ARG KEY_ALIAS=""
ARG KEY_PASSWORD=""
# Create working directory
WORKDIR /app
# Clone the repository instead of copying local files
# This ensures the build is reproducible and doesn't depend on local files/credentials
RUN if [ -n "$GIT_REPO" ]; then \
echo "Cloning from git: $GIT_REPO (branch: $GIT_BRANCH)"; \
git clone --branch "$GIT_BRANCH" --depth 1 "$GIT_REPO" . && \
echo "Git clone complete"; \
else \
echo "ERROR: GIT_REPO build arg is required"; \
echo "Usage: docker build --build-arg GIT_REPO=<repo-url> --build-arg GIT_BRANCH=<branch> ."; \
exit 1; \
fi
# Install Node.js dependencies
RUN npm ci
# Set APP_VERSION and GITHUB_RELEASE as environment variables (read by app.config.js)
ARG APP_VERSION
ARG GITHUB_RELEASE=""
ENV APP_VERSION=${APP_VERSION}
ENV GITHUB_RELEASE=${GITHUB_RELEASE}
# Save FFmpeg-Kit AAR before Expo prebuild wipes it
RUN if [ -f android/app/libs/ffmpeg-kit.aar ]; then \
cp android/app/libs/ffmpeg-kit.aar /tmp/ffmpeg-kit.aar && \
echo "Saved ffmpeg-kit.aar ($(du -h /tmp/ffmpeg-kit.aar | cut -f1))"; \
fi
# Generate native Android project with Expo prebuild
# This creates the android directory structure (will wipe existing android/)
RUN npx expo prebuild --platform android --clean
# Restore FFmpeg-Kit AAR after prebuild
RUN mkdir -p android/app/libs && \
if [ -f /tmp/ffmpeg-kit.aar ]; then \
cp /tmp/ffmpeg-kit.aar android/app/libs/ && \
echo "Restored ffmpeg-kit.aar to android/app/libs/"; \
else \
echo "Warning: ffmpeg-kit.aar not found, build may fail"; \
fi
# Note: Dynamic versioning is handled by plugins/withGradleVersioning.js during expo prebuild
# Build Rust libraries for Android AFTER prebuild
# This ensures .so files are copied to the generated android directory
RUN chmod +x ./scripts/build-rust-android-docker.sh \
&& ./scripts/build-rust-android-docker.sh
# Set up signing for release builds
ARG BUILD_TYPE
ARG KEYSTORE_FILE
ARG KEYSTORE_PASSWORD
ARG KEY_ALIAS
ARG KEY_PASSWORD
RUN if [ "$BUILD_TYPE" = "release" ] && [ -n "$KEYSTORE_FILE" ]; then \
echo "Setting up release signing..."; \
echo "$KEYSTORE_FILE" | base64 -d > android/app/librisync-release.keystore && \
ls -lh android/app/librisync-release.keystore && \
echo "MYAPP_UPLOAD_STORE_FILE=librisync-release.keystore" > android/keystore.properties && \
echo "MYAPP_UPLOAD_STORE_PASSWORD=$KEYSTORE_PASSWORD" >> android/keystore.properties && \
echo "MYAPP_UPLOAD_KEY_ALIAS=$KEY_ALIAS" >> android/keystore.properties && \
echo "MYAPP_UPLOAD_KEY_PASSWORD=$KEY_PASSWORD" >> android/keystore.properties && \
echo "✓ Signing configuration created"; \
fi
# Build Android APK or AAB based on BUILD_TYPE and BUNDLE_TYPE
ARG BUNDLE_TYPE=apk
RUN if [ "$BUILD_TYPE" = "release" ] && [ "$BUNDLE_TYPE" = "aab" ]; then \
echo "Building release AAB..."; \
cd android && ./gradlew bundleRelease; \
elif [ "$BUILD_TYPE" = "release" ]; then \
echo "Building release APK..."; \
cd android && ./gradlew assembleRelease; \
else \
echo "Building debug APK..."; \
cd android && ./gradlew assembleDebug; \
fi
# Final stage - lighter image with just the build artifacts
FROM --platform=linux/amd64 ubuntu:22.04
# Install minimal runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy build artifacts from builder (APK and/or AAB)
COPY --from=builder /app/android/app/build/outputs/ /app/build/outputs/
COPY --from=builder /app/package.json /app/
# Create a volume for output
VOLUME /output
# Command to copy build artifacts to output directory
CMD ["sh", "-c", "mkdir -p /output && find /app/build/outputs -name '*.apk' -o -name '*.aab' | while read f; do cp \"$f\" /output/; done && ls -lh /output/ && echo 'Build artifacts copied to /output/'"]