Skip to content

Commit 50c1c83

Browse files
committed
Refactor
* Using GitHub Actions and matrix strategy, use only one `Dockerfile` per image, one for the base image and other for the image containing the Android SDK and tools. * Easier to maintain, no more duplicated code.
1 parent 6ddc7e8 commit 50c1c83

36 files changed

+280
-560
lines changed

.github/workflows/default.yaml

Lines changed: 66 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -10,143 +10,38 @@ on:
1010
env:
1111
DH_IMAGE_BASE_NAME: alvrme/alpine-android-base
1212
DH_IMAGE_NAME: alvrme/alpine-android
13+
1314
GHCR_IMAGE_BASE_NAME: alvr/alpine-android-base
1415
GHCR_IMAGE_NAME: alvr/alpine-android
16+
1517
QUAY_IMAGE_BASE_NAME: alvr/alpine-android-base
1618
QUAY_IMAGE_NAME: alvr/alpine-android
19+
1720
DOCKERHUB_USER: alvrme
1821
QUAY_USER: alvr
22+
23+
DEFAULT_JDK_VERSION: 8
1924
LATEST_STABLE_API: 30
2025

2126
jobs:
22-
build_base_image_jdk8:
23-
name: Build Base Image JDK8
24-
runs-on: ubuntu-latest
25-
26-
steps:
27-
- name: Checkout
28-
uses: actions/checkout@v2
29-
30-
- name: Set up Docker Buildx
31-
uses: docker/setup-buildx-action@v1
32-
33-
- name: Login to DockerHub
34-
uses: docker/login-action@v1
35-
with:
36-
username: ${{ env.DOCKERHUB_USER }}
37-
password: ${{ secrets.DOCKERHUB_PASS }}
38-
39-
- name: Login to GitHub Container Registry
40-
uses: docker/login-action@v1
41-
with:
42-
registry: ghcr.io
43-
username: ${{ github.repository_owner }}
44-
password: ${{ secrets.GHCR_PASS }}
45-
46-
- name: Login to Quay
47-
uses: docker/login-action@v1
48-
with:
49-
registry: quay.io
50-
username: ${{ env.QUAY_USER }}
51-
password: ${{ secrets.QUAY_PASS }}
52-
53-
- name: Build Android Base Image JDK8
54-
uses: docker/build-push-action@v2
55-
with:
56-
context: ./android-base
57-
file: ./android-base/jdk8.Dockerfile
58-
push: true
59-
tags: |
60-
${{ env.DH_IMAGE_BASE_NAME }}:jdk8
61-
${{ env.DH_IMAGE_BASE_NAME }}:latest
62-
${{ env.DH_IMAGE_BASE_NAME }}:latest-jdk8
63-
ghcr.io/${{ env.GHCR_IMAGE_BASE_NAME }}:jdk8
64-
ghcr.io/${{ env.GHCR_IMAGE_BASE_NAME }}:latest
65-
ghcr.io/${{ env.GHCR_IMAGE_BASE_NAME }}:latest-jdk8
66-
quay.io/${{ env.QUAY_IMAGE_BASE_NAME }}:jdk8
67-
quay.io/${{ env.QUAY_IMAGE_BASE_NAME }}:latest
68-
quay.io/${{ env.QUAY_IMAGE_BASE_NAME }}:latest-jdk8
69-
70-
build_base_image_jdk11:
71-
name: Build Base Image JDK11
72-
runs-on: ubuntu-latest
73-
74-
steps:
75-
- name: Checkout
76-
uses: actions/checkout@v2
77-
78-
- name: Set up Docker Buildx
79-
uses: docker/setup-buildx-action@v1
80-
81-
- name: Login to DockerHub
82-
uses: docker/login-action@v1
83-
with:
84-
username: ${{ env.DOCKERHUB_USER }}
85-
password: ${{ secrets.DOCKERHUB_PASS }}
86-
87-
- name: Login to GitHub Container Registry
88-
uses: docker/login-action@v1
89-
with:
90-
registry: ghcr.io
91-
username: ${{ github.repository_owner }}
92-
password: ${{ secrets.GHCR_PASS }}
93-
94-
- name: Login to Quay
95-
uses: docker/login-action@v1
96-
with:
97-
registry: quay.io
98-
username: ${{ env.QUAY_USER }}
99-
password: ${{ secrets.QUAY_PASS }}
100-
101-
- name: Build Android Base Image JDK11
102-
uses: docker/build-push-action@v2
103-
with:
104-
context: ./android-base
105-
file: ./android-base/jdk11.Dockerfile
106-
push: true
107-
tags: |
108-
${{ env.DH_IMAGE_BASE_NAME }}:jdk11
109-
${{ env.DH_IMAGE_BASE_NAME }}:latest-jdk11
110-
ghcr.io/${{ env.GHCR_IMAGE_BASE_NAME }}:jdk11
111-
ghcr.io/${{ env.GHCR_IMAGE_BASE_NAME }}:latest-jdk11
112-
quay.io/${{ env.QUAY_IMAGE_BASE_NAME }}:jdk11
113-
quay.io/${{ env.QUAY_IMAGE_BASE_NAME }}:latest-jdk11
114-
115-
build_images_jdk8:
116-
name: Build Images JDK8
117-
needs: [build_base_image_jdk8]
27+
build_base_images:
28+
name: Build Alpine Android Base Image
11829
runs-on: ubuntu-latest
11930
strategy:
12031
fail-fast: false
12132
matrix:
122-
android-api:
123-
- 21
124-
- 22
125-
- 23
126-
- 24
127-
- 25
128-
- 26
129-
- 27
130-
- 28
131-
- 29
132-
- 30
33+
jdk: [8, 11]
13334

13435
steps:
13536
- name: Checkout
13637
uses: actions/checkout@v2
13738

138-
- name: Get tag version
139-
id: tag_version
140-
uses: battila7/get-version-action@v2
141-
14239
- name: Tags
14340
run: |
144-
TAGS="android-${{ matrix.android-api }}"
145-
TAGS="$TAGS,android-${{ matrix.android-api }}-jdk8"
146-
TAGS="$TAGS,android-${{ matrix.android-api }}-jdk8-${{ steps.tag_version.outputs.version }}"
147-
if [ "${{ matrix.android-api }}" = "${{ env.LATEST_STABLE_API }}" ]; then
41+
TAGS="jdk${{ matrix.jdk }}"
42+
TAGS="$TAGS,latest-jdk${{ matrix.jdk }}"
43+
if [ "${{ matrix.jdk }}" = "${{ env.DEFAULT_JDK_VERSION }}" ]; then
14844
TAGS="$TAGS,latest"
149-
TAGS="$TAGS,latest-jdk8"
15045
fi
15146
echo "TAGS=$TAGS" >> $GITHUB_ENV
15247
@@ -155,9 +50,9 @@ jobs:
15550
uses: crazy-max/ghaction-docker-meta@v1
15651
with:
15752
images: |
158-
${{ env.DH_IMAGE_NAME }}
159-
ghcr.io/${{ env.GHCR_IMAGE_NAME }}
160-
quay.io/${{ env.QUAY_IMAGE_NAME }}
53+
${{ env.DH_IMAGE_BASE_NAME }}
54+
ghcr.io/${{ env.GHCR_IMAGE_BASE_NAME }}
55+
quay.io/${{ env.QUAY_IMAGE_BASE_NAME }}
16156
tag-custom: ${{ env.TAGS }}
16257
tag-custom-only: true
16358

@@ -184,32 +79,25 @@ jobs:
18479
username: ${{ env.QUAY_USER }}
18580
password: ${{ secrets.QUAY_PASS }}
18681

187-
- name: Build Android API ${{ matrix.android-api }} JDK8
82+
- name: Build Android Base JDK${{ matrix.jdk }}
18883
uses: docker/build-push-action@v2
18984
with:
190-
context: ./android-${{ matrix.android-api }}
191-
file: ./android-${{ matrix.android-api }}/jdk8.Dockerfile
85+
context: ./docker
86+
file: ./docker/base.Dockerfile
19287
push: true
19388
tags: ${{ steps.docker_meta.outputs.tags }}
89+
build-args: |
90+
JDK_VERSION=${{ matrix.jdk }}
19491
195-
build_images_jdk11:
196-
name: Build Images JDK11
197-
needs: [build_base_image_jdk11]
92+
build_images:
93+
name: Build Alpine Android Image
94+
needs: [build_base_images]
19895
runs-on: ubuntu-latest
19996
strategy:
20097
fail-fast: false
20198
matrix:
202-
android-api:
203-
- 21
204-
- 22
205-
- 23
206-
- 24
207-
- 25
208-
- 26
209-
- 27
210-
- 28
211-
- 29
212-
- 30
99+
android-api: [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
100+
jdk: [8, 11]
213101

214102
steps:
215103
- name: Checkout
@@ -221,13 +109,45 @@ jobs:
221109

222110
- name: Tags
223111
run: |
224-
TAGS="android-${{ matrix.android-api }}-jdk11"
225-
TAGS="$TAGS,android-${{ matrix.android-api }}-jdk11-${{ steps.tag_version.outputs.version }}"
112+
TAGS="android-${{ matrix.android-api }}-jdk${{ matrix.jdk }}"
113+
TAGS="$TAGS,android-${{ matrix.android-api }}-jdk${{ matrix.jdk }}-${{ steps.tag_version.outputs.version }}"
114+
if [ "${{ matrix.jdk }}" = "${{ env.DEFAULT_JDK_VERSION }}" ]; then
115+
TAGS="$TAGS,android-${{ matrix.android-api }}"
116+
fi
226117
if [ "${{ matrix.android-api }}" = "${{ env.LATEST_STABLE_API }}" ]; then
227-
TAGS="$TAGS,latest-jdk11"
118+
TAGS="$TAGS,latest-jdk${{ matrix.jdk }}"
119+
if [ "${{ matrix.jdk }}" = "${{ env.DEFAULT_JDK_VERSION }}" ]; then
120+
TAGS="$TAGS,latest"
121+
fi
228122
fi
229123
echo "TAGS=$TAGS" >> $GITHUB_ENV
230124
125+
- name: Build Tools
126+
id: build_tools
127+
run: |
128+
if [ "${{ matrix.android-api }}" = "21" ]; then
129+
VERSION="21.1.2"
130+
elif [ "${{ matrix.android-api }}" = "22" ]; then
131+
VERSION="22.0.1"
132+
elif [ "${{ matrix.android-api }}" = "23" ]; then
133+
VERSION="23.0.3"
134+
elif [ "${{ matrix.android-api }}" = "24" ]; then
135+
VERSION="24.0.3"
136+
elif [ "${{ matrix.android-api }}" = "25" ]; then
137+
VERSION="25.0.3"
138+
elif [ "${{ matrix.android-api }}" = "26" ]; then
139+
VERSION="26.0.3"
140+
elif [ "${{ matrix.android-api }}" = "27" ]; then
141+
VERSION="27.0.3"
142+
elif [ "${{ matrix.android-api }}" = "28" ]; then
143+
VERSION="28.0.3"
144+
elif [ "${{ matrix.android-api }}" = "29" ]; then
145+
VERSION="29.0.3"
146+
elif [ "${{ matrix.android-api }}" = "30" ]; then
147+
VERSION="30.0.3"
148+
fi
149+
echo "::set-output name=version::$VERSION"
150+
231151
- name: Docker meta
232152
id: docker_meta
233153
uses: crazy-max/ghaction-docker-meta@v1
@@ -262,10 +182,14 @@ jobs:
262182
username: ${{ env.QUAY_USER }}
263183
password: ${{ secrets.QUAY_PASS }}
264184

265-
- name: Build Android API ${{ matrix.android-api }} JDK11
185+
- name: Build Android API ${{ matrix.android-api }} JDK${{ matrix.jdk }}
266186
uses: docker/build-push-action@v2
267187
with:
268-
context: ./android-${{ matrix.android-api }}
269-
file: ./android-${{ matrix.android-api }}/jdk11.Dockerfile
188+
context: ./docker
189+
file: ./docker/android.Dockerfile
270190
push: true
271191
tags: ${{ steps.docker_meta.outputs.tags }}
192+
build-args: |
193+
JDK_VERSION=${{ matrix.jdk }}
194+
BUILD_TOOLS=${{ steps.build_tools.outputs.version }}
195+
TARGET_SDK=${{ matrix.android-api }}

0 commit comments

Comments
 (0)