-
Notifications
You must be signed in to change notification settings - Fork 230
216 lines (182 loc) · 7.76 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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@d632683dd7b4114ad314bca15554477dd762a938
- name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
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@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf
with:
platforms: amd64,arm64
- name: Available platforms
run: echo ${{ steps.qemu.outputs.platforms }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db
with:
driver: docker
- name: Pre build
run: |
# possible ref examples:
# refs/pull/138/merge
# refs/heads/master
# refs/tags/1.25.0
echo "GITHUB_REF: $GITHUB_REF"
# possible event name examples:
# push
# pull_request
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.*22\.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/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
if: github.event_name == 'pull_request' || !startsWith(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/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
if: github.event_name != 'pull_request' && startsWith(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' || startsWith(github.ref, 'refs/tags/'))
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push - for Not PRs and Not Tags
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
if: github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/tags/')
with:
context: .
platforms: linux/amd64
push: ${{ startsWith(github.ref, 'refs/heads/master') }}
tags: mingc/android-build-box:latest, ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push - for Not PRs and Tags
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')
with:
context: .
platforms: linux/amd64
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
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: 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@e98e4d1628a5f3be2be7c231e50981aee98723ae
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: mingc/android-build-box
enable-url-completion: true