Improve recent #309
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker CI | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| paths: | |
| - "Dockerfile.base" | |
| - "Dockerfile.app" | |
| - ".github/workflows/docker.yml" | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| BASE_IMAGE_NAME: gem-android-base | |
| BASE_IMAGE_FULL_NAME: ghcr.io/${{ github.repository_owner }}/gem-android-base | |
| DOCKER_BUILDKIT: 1 | |
| jobs: | |
| build_base_image: | |
| name: Build Base Docker Image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| outputs: | |
| image_tag: ${{ steps.meta.outputs.version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata for base image | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.BASE_IMAGE_FULL_NAME }} | |
| # Generate a version tag based on commit SHA. This will be unique. | |
| tags: | | |
| type=sha,format=long,prefix= | |
| - name: Build and push Dockerfile.base | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile.base | |
| push: true | |
| tags: ${{ env.BASE_IMAGE_FULL_NAME }}:${{ steps.meta.outputs.version }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| platforms: linux/amd64 | |
| cache-from: type=gha,scope=base-image | |
| cache-to: type=gha,mode=max,scope=base-image | |
| build-args: | | |
| BUILDKIT_INLINE_CACHE=1 | |
| build_app_image: | |
| name: Build App Docker Image | |
| needs: build_base_image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create local.properties for CI | |
| run: | | |
| echo "gpr.username=${{ github.actor }}" > local.properties | |
| echo "gpr.token=${{ secrets.GITHUB_TOKEN }}" >> local.properties | |
| echo "# Automatically generated for CI build" >> local.properties | |
| - name: Build Dockerfile.app | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| run: | | |
| docker buildx build \ | |
| --build-arg TAG=${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} \ | |
| --build-arg BASE_IMAGE=${{ env.BASE_IMAGE_FULL_NAME }} \ | |
| --build-arg BASE_IMAGE_TAG=${{ needs.build_base_image.outputs.image_tag }} \ | |
| --build-arg SKIP_SIGN=true \ | |
| --cache-from type=gha,scope=app-image \ | |
| --cache-to type=gha,mode=max,scope=app-image \ | |
| --load \ | |
| --tag gem-android-app:latest \ | |
| --file ./Dockerfile.app \ | |
| . | |
| - name: Extract Universal APK from Docker container | |
| run: | | |
| CONTAINER_ID=$(docker create gem-android-app:latest) | |
| mkdir -p apk-output | |
| docker cp $CONTAINER_ID:/root/gem-android/app/build/outputs/apk/universal/release/. ./apk-output/ | |
| docker rm $CONTAINER_ID | |
| find ./apk-output -name "*.apk" | |
| - name: Upload APK artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: gem-android-apk | |
| path: ./apk-output/ | |
| retention-days: 7 |