forked from mingchen/docker-android-build-box
-
Notifications
You must be signed in to change notification settings - Fork 0
193 lines (161 loc) · 6.91 KB
/
docker-image.yml
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
185
186
187
188
189
190
191
192
193
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@16c0bc4a6e6ada2cfd8afd41d22d95379cf7c32a
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