Skip to content

fix error

fix error #12

Workflow file for this run

name: Build Node Images
on:
push:
branches:
- master
paths:
- 'jdk*/*'
- '.github/workflows/build-node.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: |
NODE_MAJOR_VERSION=${{ matrix.node_version }}
NODE_VERSION="$(awk -F '[=]' '/NODE_VERSION/ {print $2}' node${{ matrix.node_version }}.env)"
JDK_DIR=jdk${{ matrix.jdk_version }}
if [[ -f ${JDK_DIR}/Dockerfile ]]; then
BASE_VERSION="$(awk -F '[:-]' '/maven/ {print $3}' jdk8/Dockerfile)"
echo "${NODE_VERSION}" > ${JDK_DIR}/${NODE_VERSION}-node_version.txt
echo "${NODE_MAJOR_VERSION}" > ${JDK_DIR}/${NODE_VERSION}-node_major_version.txt
echo "${BASE_VERSION}" > ${JDK_DIR}/${NODE_VERSION}-base_version.txt
else
NODE_VERSION=$(cat ${JDK_DIR}/${NODE_VERSION}-node_version.txt)
NODE_MAJOR_VERSION=$(cat ${JDK_DIR}/${NODE_VERSION}-node_major_version.txt)
BASE_VERSION=$(cat ${JDK_DIR}/${NODE_VERSION}-base_version.txt)
fi
echo "JDK_DIR=${JDK_DIR}" >> $GITHUB_ENV
echo "NODE_VERSION=${NODE_VERSION}" >> $GITHUB_ENV
echo "NODE_MAJOR_VERSION=${NODE_MAJOR_VERSION}" >> $GITHUB_ENV
echo "BASE_VERSION=${BASE_VERSION}" >> $GITHUB_ENV
- name: Build Docker Image
run: |
IMAGE_NAME=ringcentral/node
sed -i "s/\$NODE_VERSION/$NODE_VERSION/g" ${JDK_DIR}/Dockerfile
cat ${JDK_DIR}/Dockerfile
docker build --tag ${IMAGE_NAME} --file ${JDK_DIR}/Dockerfile .
- name: Tag and Push Docker Images
run: |
IMAGE_NAME=ringcentral/node
GH_DOCKER_PKG_IMAGE_NAME=ghcr.io/ringcentral-docker/node/node
if [ "${{ matrix.jdk_version }}" -eq 21 ]; then
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:${NODE_VERSION}"
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:${NODE_MAJOR_VERSION}"
docker push "${IMAGE_NAME}:${NODE_VERSION}"
docker push "${IMAGE_NAME}:${NODE_MAJOR_VERSION}"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}"
fi
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:${NODE_VERSION}-${BASE_VERSION}"
docker tag "${IMAGE_NAME}" "${IMAGE_NAME}:${NODE_MAJOR_VERSION}-${BASE_VERSION}"
docker push "${IMAGE_NAME}:${NODE_VERSION}-${BASE_VERSION}"
docker push "${IMAGE_NAME}:${NODE_MAJOR_VERSION}-${BASE_VERSION}"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}-${BASE_VERSION}"
docker tag "${IMAGE_NAME}" "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}-${BASE_VERSION}"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}-${BASE_VERSION}"
docker push "${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}-${BASE_VERSION}"
if [ "${{ matrix.jdk_version }}" -eq 21 ]; 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
- name: Generate README Update
run: |
BASE_IMAGE="alpine"
IMAGE_NAME=ringcentral/node
GH_DOCKER_PKG_IMAGE_NAME=ghcr.io/ringcentral-docker/node/node
NEW_ENTRY="| JDK${{ matrix.jdk_version }} | ${{ matrix.node_version }} | \`${IMAGE_NAME}:${NODE_MAJOR_VERSION}\` \`${IMAGE_NAME}:${NODE_VERSION}\` \`${IMAGE_NAME}:${NODE_MAJOR_VERSION}-${BASE_VERSION}\` \`${IMAGE_NAME}:${NODE_VERSION}-${BASE_VERSION}\`| \`${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}\` \`${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}\` \`${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_MAJOR_VERSION}-${BASE_VERSION}\` \`${GH_DOCKER_PKG_IMAGE_NAME}:${NODE_VERSION}-${BASE_VERSION}\` |"
echo "${NEW_ENTRY}" > readme_updates.txt
- name: Upload README Update
uses: actions/upload-artifact@v4
with:
name: readme-updates-${{ matrix.node_version }}-${{ matrix.jdk_version }}
path: readme_updates.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-22-8
path: ./readme-updates
- name: Download README Updates
uses: actions/download-artifact@v4
with:
name: readme-updates-22-11
path: ./readme-updates
- name: Download README Updates
uses: actions/download-artifact@v4
with:
name: readme-updates-22-17
path: ./readme-updates
- name: Download README Updates
uses: actions/download-artifact@v4
with:
name: readme-updates-22-21
path: ./readme-updates
- name: Initialize README
run: |
echo "| JDK Version | Node 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 }}