Skip to content

Docker Image CI

Docker Image CI #299

Workflow file for this run

name: Docker Image CI
on:
workflow_dispatch: # manual trigger
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '0 0 * * 1' # build every Monday
push:
branches: [ master, dev ]
tags:
- '*.*.*'
paths-ignore:
- '*.md'
- 'howto.txt'
- 'LICENSE'
pull_request:
branches: [ master ]
paths-ignore:
- '*.md'
- 'howto.txt'
- 'LICENSE'
jobs:
build:
runs-on: ubuntu-latest
env:
IMAGE_NAME: mingc/android-build-box
TAG: $GITHUB_SHA
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- name: Docker meta
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175
with:
images: mingc/android-build-box
labels: |
org.opencontainers.image.url=https://hub.docker.com/r/mingc/android-build-box
org.opencontainers.image.vendor=Ming Chen
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: amd64,arm64
- name: Available platforms
run: echo ${{ steps.qemu.outputs.platforms }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1
with:
driver: docker
- name: Pre build
run: |
echo "GITHUB_REF: $GITHUB_REF"
echo "GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME"
echo "GITHUB_EVENT_PATH: $GITHUB_EVENT_PATH"
echo "GITHUB_WORKFLOW: $GITHUB_WORKFLOW"
echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF"
echo "GITHUB_ACTION: $GITHUB_ACTION"
echo "GITHUB_JOB: $GITHUB_JOB"
uname -a
df -h
docker images
docker ps -a
echo "GITHUB_SHA: $GITHUB_SHA"
# Set up env.TAG
echo "TAG=$GITHUB_SHA" >> $GITHUB_ENV
echo "TAG: $TAG"
# Remove exist images to free disk space
docker rmi $(docker image ls -a | grep -vE 'ubuntu.*20\.04|moby/buildkit' | awk 'NR>1 {print $3}')
#docker rmi $(docker images | grep -v IMAGE | awk '{print $3}')
docker images
# Remove unneeded and installed software to free up space
sudo rm -rf /usr/local/lib/android/sdk
sudo rm -rf /opt/hostedtoolcache
# check disk space one more time
df -h
- name: Build and load local docker image for PRs or Not Tags
uses: docker/[email protected]
if: github.event_name == 'pull_request' || !${{contains(github.ref, 'refs/tags/')}}
with:
context: .
load: true
tags: ${{ env.IMAGE_NAME}}:${{ env.TAG}}
- name: Build and load local docker image for Not PRs and Tags
uses: docker/[email protected]
if: github.event_name != 'pull_request' && (contains(github.ref, 'refs/tags/'))
with:
context: .
load: true
tags: ${{ env.IMAGE_NAME}}:${{ env.TAG}}
build-args: |
ANDROID_SDK_TOOLS_TAGGED="tagged"
ANDROID_SDKS="tagged"
NDK_TAGGED="tagged"
NODE_TAGGED="tagged"
BUNDLETOOL_TAGGED="tagged"
FLUTTER_TAGGED="tagged"
JENV_TAGGED="tagged"
- name: Inspect local docker image
run: |
docker images
docker inspect ${{ env.IMAGE_NAME}}:${{ env.TAG}}
- name: Test
run: |
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} env
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} flutter --version
echo "Show current java version"
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} java -version
echo "Set java env to 8"
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c '. $HOME/.bash_profile && jenv local 1.8 && java -version'
echo "Test jenv recognizes Java 11"
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c 'jenv local 11 && java -version'
echo "Test jenv recognizes Java 17"
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c 'jenv local 17 && java -version'
docker run -v `pwd`:/project --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c 'echo "Current directory: $PWD"'
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c 'ls -l $ANDROID_SDK_HOME'
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c 'ls -l $ANDROID_NDK_HOME'
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c 'ls -l /opt/android-sdk/ndk/'
# Test Node
echo "Test Node installation"
docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c 'curl -fsSL https://deb.nodesource.com/test | bash -'
cd test_projects/SampleProject/
docker run --rm -v `pwd`:/project ${{ env.IMAGE_NAME}}:${{ env.TAG}} bash -c './gradlew build'
- name: Login to DockerHub
# if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/master' || contains(github.ref, 'refs/tags/'))
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/[email protected]
with:
context: .
# Android SDK not support arm64 yet
# platforms: linux/amd64,linux/arm64
platforms: linux/amd64
# platforms: linux/arm64
# push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }}
push: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/master' || contains(github.ref, 'refs/tags/')) }}
tags: mingc/android-build-box:latest,${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Modify Readme to list latest software
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/master')
run: |
printf "\n\n \"Latest\" Tag Software:\n\n" >> README.md
TEMP=$(docker run --rm ${{ env.IMAGE_NAME}}:${{ env.TAG}} cat '/root/installed-versions.txt')
echo "$TEMP" | tail --lines=+2 >> README.md
- name: Update Docker Hub Description
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/master')
uses: peter-evans/dockerhub-description@dc67fad7001ef9e8e3c124cb7a64e16d0a63d864
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: mingc/android-build-box
enable-url-completion: true