-
Notifications
You must be signed in to change notification settings - Fork 3
152 lines (136 loc) · 5.83 KB
/
build-runner.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
name: Build web-tools Images
on:
push:
branches:
- master
paths:
- 'openjdk*/*'
- '.github/workflows/build-runner.yml'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
jdk_version: [8, 11, 17, 21]
node_version: [18, 20, 22]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Docker login
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo $DOCKER_HUB_PASSWORD | docker login --username $DOCKER_HUB_USERNAME --password-stdin
echo $GITHUB_TOKEN | docker login ghcr.io --username $GITHUB_ACTOR --password-stdin
- name: Set Environment Variables
id: vars
run: |
JDK_DIR=openjdk${{ matrix.jdk_version }}-alpine
NODE_MAJOR_VERSION=${{ matrix.node_version }}
NODE_VERSION="$(awk -F '[=]' '/NODE_${{ matrix.node_version }}_VERSION/ {print $2}' node_version.env)"
if [[ -f ${JDK_DIR}/Dockerfile ]]; then
OPENJDK_VERSION="$(awk -F '[=]' '/ENV OPENJDK_VERSION/ {print $2}' ${JDK_DIR}/Dockerfile)"
echo $NODE_VERSION > ${JDK_DIR}/version.txt
echo $OPENJDK_VERSION > ${JDK_DIR}/openjdk_version.txt
else
NODE_VERSION=$(cat ${JDK_DIR}/version.txt)
OPENJDK_VERSION=$(cat ${JDK_DIR}/openjdk_version.txt)
fi
echo "JDK_DIR=${JDK_DIR}" >> $GITHUB_ENV
echo "NODE_VERSION=${NODE_VERSION}" >> $GITHUB_ENV
echo "OPENJDK_VERSION=${OPENJDK_VERSION}" >> $GITHUB_ENV
echo "NODE_MAJOR_VERSION=${NODE_MAJOR_VERSION}" >> $GITHUB_ENV
- name: Build Docker Image
run: |
IMAGE_NAME=ringcentral/web-tools
sed -i "s/\$NODE_VERSION/$NODE_VERSION/g" ${JDK_DIR}/Dockerfile
docker build --tag ${IMAGE_NAME} --file ${JDK_DIR}/Dockerfile .
- name: Tag and Push Docker Images
run: |
IMAGE_NAME=ringcentral/web-tools
GH_DOCKER_PKG_IMAGE_NAME=ghcr.io/ringcentral-docker/web-tools/web-tools
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:node${NODE_MAJOR_VERSION}-openjdk${OPENJDK_VERSION}-alpine"
docker push "${IMAGE_NAME}:node${NODE_MAJOR_VERSION}-openjdk${OPENJDK_VERSION}-alpine"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:node${NODE_MAJOR_VERSION}-openjdk${OPENJDK_VERSION}-alpine"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:node${NODE_MAJOR_VERSION}-openjdk${OPENJDK_VERSION}-alpine"
if [ "${{ matrix.jdk_version }}" -eq 21 ]; then
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:${NODE_VERSION}-alpine"
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:${NODE_MAJOR_VERSION}-alpine"
docker push "${IMAGE_NAME}:${NODE_VERSION}-alpine"
docker push "${IMAGE_NAME}:${NODE_MAJOR_VERSION}-alpine"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}-alpine"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}-alpine"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}-alpine"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}-alpine"
if [ "${{ matrix.node_version }}" -eq 22 ]; then
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:latest"
docker push "${IMAGE_NAME}:latest"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:latest"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:latest"
fi
fi
- name: Generate README Update
run: |
IMAGE_NAME=ringcentral/web-tools
GH_DOCKER_PKG_IMAGE_NAME=ghcr.io/ringcentral-docker/web-tools/web-tools
if [ "${{ matrix.node_version }}" -eq 22 ]; then
NEW_ENTRY="| JDK${{ matrix.jdk_version }} | ${NODE_DIR} | \`${IMAGE_NAME}:${NODE_VERSION}-alpine\` | \`${GH_DOCKER_PKG_IMAGE_NAME}:node${NODE_MAJOR_VERSION}-openjdk${OPENJDK_VERSION}-alpine\` |"
echo "${NEW_ENTRY}" > readme_updates_${{ matrix.jdk_version }}.txt
fi
- name: Upload README Update
uses: actions/upload-artifact@v4
with:
name: readme-updates-${{ matrix.jdk_version }}
path: readme_updates_${{ matrix.jdk_version }}.txt
update-readme:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download README Updates
uses: actions/download-artifact@v4
with:
name: readme-updates-8
path: ./readme-updates
- name: Download README Updates
uses: actions/download-artifact@v4
with:
name: readme-updates-11
path: ./readme-updates
- name: Download README Updates
uses: actions/download-artifact@v4
with:
name: readme-updates-17
path: ./readme-updates
- name: Download README Updates
uses: actions/download-artifact@v4
with:
name: readme-updates-21
path: ./readme-updates
- name: Initialize README
run: |
echo "| JDK Version | Version | Docker Hub | GitHub Package |" > README.md
echo "|-------------|---------|------------|----------------|" >> README.md
- name: Update README
run: |
for file in ./readme-updates/readme_updates_*.txt; do
while IFS= read -r line; do
JDK_VERSION=$(echo $line | cut -d' ' -f2)
if grep -q "JDK${JDK_VERSION}" README.md; then
sed -i "/JDK${JDK_VERSION}/c\\$line" README.md
else
echo "$line" >> README.md
fi
done < "$file"
done
- name: Commit README Update
run: |
git config --global user.name 'john.lin'
git config --global user.email '[email protected]'
git add README.md
git commit -m "Update README with Docker image info"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}