googlesamples-easypermissions
SUCCESS
26m 26s
History Source
SummaryIterations2Transcript34Dockerfile
Dockerfile47 lines · 1798 chars
# Multi-stage Dockerfile to build an Android project from source and package artifacts
# Stage 1: Builder with Android SDK and JDK (provided by CircleCI's Android image)
FROM circleci/android:api-30 AS builder

ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /workspace

# Ensure we are root for build steps
USER root

# Copy the repository (best done after creating workspace, but copy all and let Gradle decide)
COPY . .

# Prepare executable Gradle wrapper and build
RUN chmod +x gradlew

# Create build directory in advance to avoid permission issues in some environments
RUN mkdir -p /workspace/app/build

# Build the project (assemble a release APK and libraries). Skip tests for speed.
RUN ./gradlew clean assembleRelease -x test

# Collect build artifacts for the final image
RUN mkdir -p /artifacts/app
RUN mkdir -p /artifacts/easypermissions

# APK produced by the app module (path depends on AGP version)
RUN bash -lc 'shopt -s nullglob; apk_paths=(app/build/outputs/apk/release/*.apk); if [ -f "${apk_paths[0]}" ]; then cp "${apk_paths[0]}" /artifacts/app/; fi'

# AAR produced by the library module
RUN bash -lc 'shopt -s nullglob; if [ -d easypermissions/build/outputs/aar ]; then cp -R easypermissions/build/outputs/aar /artifacts/easypermissions/; fi'

# Optional: show what artifacts exist (for debugging)
RUN ls -la /artifacts || true

# Stage 2: Runtime image with Java runtime and the built artifacts
FROM eclipse-temurin:8-jre AS runtime

WORKDIR /app

# Copy artifacts from the builder stage
COPY --from=builder /artifacts /artifacts

# Expose nothing specific; this image simply holds the build outputs
# Keep the container alive so users can inspect artifacts if needed
CMD ["/bin/sh", "-lc", "echo Build artifacts available in /artifacts; ls -la /artifacts; tail -f /dev/null"]