Skip to content

Docker images - build #48

Docker images - build

Docker images - build #48

Workflow file for this run

name: Docker images - build
on:
workflow_dispatch:
release:
types: [published]
repository_dispatch:
types: [docker-build]
jobs:
build:
env:
LATEST_NODE: 14
DEFAULT_IMAGE: nrchkb/node-red-homekit
DEV_IMAGE: nrchkb/node-red-homekit-dev
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18, 20]
suffix: ["", "-minimal", "-raspbian"]
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Show Env
run: env
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
flavor: |
latest=false
suffix=-${{matrix.node}}${{matrix.suffix}}
images: |
${{ env.DEFAULT_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Get Date
id: date
run: echo "date=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Get NRCHKB Version
id: nrchkbVersion
run: |
HOMEKIT_BRIDGED_VERSION=$(grep -oE "\"node-red-contrib-homekit-bridged\": \"(\w*.\w*.\w*.\w*.\w*.)" package.json | cut -d\" -f4)
echo "version=$HOMEKIT_BRIDGED_VERSION" >> $GITHUB_OUTPUT
- name: Set Node-RED Version
id: nodeRedVersion
run: |
NODE_RED_VERSION=""
if [[ "${{matrix.node}}" == "14" ]]; then
NODE_RED_VERSION="2.2.3"
sed -ie "s/\"node-red\":[^\"].*\"/\"node-red\": \"${NODE_RED_VERSION}\"/g" package.json
else
NODE_RED_VERSION=$(grep -oE "\"node-red\": \"(\w*.\w*.\w*.\w*.\w*.)" package.json | cut -d\" -f4)
fi
echo "version=$NODE_RED_VERSION" >> $GITHUB_OUTPUT
- name: Set Image Settings
id: imageSettings
run: |
TAGS=""
while IFS= read -r TAG;do
if [ -z "$TAGS" ]; then
TAGS=$TAG
else
TAGS="$TAGS,$TAG"
fi
done <<< "${{ steps.meta.outputs.tags }}"
CURRENT_TAG="$(echo "$GITHUB_REF" | awk -F '/' '{ print $3}')"
if [[ ! "$CURRENT_TAG" =~ ^v[0-9\.-]*$ ]]; then
CURRENT_TAG="$(git describe --tags --abbrev=0)"
fi
echo "current tag $CURRENT_TAG"
if [[ "$CURRENT_TAG" =~ ^v[0-9\.-]*$ ]]; then
IMAGE=${{ env.DEFAULT_IMAGE }}
PUSH="true"
VERSION=${CURRENT_TAG:1}
if [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "" ]; then
TAGS="$TAGS,$IMAGE:$VERSION,$IMAGE:latest"
elif [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "-minimal" ]; then
TAGS="$TAGS,$IMAGE:$VERSION,$IMAGE:latest-minimal"
elif [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "-raspbian" ]; then
TAGS="$TAGS,$IMAGE:$VERSION,$IMAGE:latest-raspbian"
fi
TAGS="$TAGS,$IMAGE:latest-${{ matrix.node }}"
if [ "${{ matrix.suffix}}" != "" ]; then
TAGS="$TAGS,$IMAGE:latest-${{ matrix.node }}${{ matrix.suffix }}"
fi
else
IMAGE=${{ env.DEV_IMAGE }}
if [[ "$CURRENT_TAG" == *"dev"* || "$CURRENT_TAG" == *"beta"* ]]; then
PUSH="true"
else
PUSH="false"
fi
VERSION=${CURRENT_TAG}
TAGS=$(echo $TAGS | sed 's!${{ env.DEFAULT_IMAGE}}!${{ env.DEV_IMAGE }}!')
if [ "${{ matrix.node }}" == "${{ env.LATEST_NODE }}" ] && [ "${{ matrix.suffix}}" == "" ]; then
TAGS="$TAGS,$IMAGE:$VERSION"
fi
fi
PLATFORMS=""
SUFFIX=""
if [[ "${{matrix.suffix}}" == "-raspbian" ]]; then
PLATFORMS="linux/arm/v7, linux/arm/v6"
SUFFIX=""
FFMPEG_OS="raspbian"
else
PLATFORMS="linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6"
SUFFIX="${{ matrix.suffix }}"
FFMPEG_OS="alpine"
fi
echo $TAGS
echo "tags=$TAGS" >> $GITHUB_OUTPUT
echo "push=$PUSH" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "platforms=$PLATFORMS" >> $GITHUB_OUTPUT
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
echo "ffmpegOS=$FFMPEG_OS" >> $GITHUB_OUTPUT
- name: Build and push
id: build-push
uses: docker/build-push-action@v5
continue-on-error: true
with:
context: .
platforms: ${{ steps.imageSettings.outputs.platforms }}
push: ${{ steps.imageSettings.outputs.push }}
file: .docker/Dockerfile.alpine
build-args: |
NODE_VERSION=${{ matrix.node }}
BUILD_DATE=${{ steps.date.outputs.date }}
BUILD_VERSION=${{ steps.imageSettings.outputs.version }}
BUILD_REF=${{ env.GITHUB_SHA }}
NODE_RED_VERSION=${{ steps.nodeRedVersion.outputs.version }}
HOMEKIT_BRIDGED_VERSION=${{ steps.nrchkbVersion.outputs.version }}
FFMPEG_OS=${{ steps.imageSettings.outputs.ffmpegOS }}
TAG_SUFFIX=${{ steps.imageSettings.outputs.suffix }}
tags: ${{ steps.imageSettings.outputs.tags }}