Skip to content
52 changes: 45 additions & 7 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ on:

jobs:
docker:
if: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
# if: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
runs-on: ubuntu-latest
outputs:
bco-tags: ${{ steps.bco-meta.outputs.tags }}
steps:
-
name: Checkout
Expand All @@ -34,7 +36,8 @@ jobs:
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
type=raw,value=preview+{{commit_date 'YYYYMMDD-HHmmss' tz='UTC'}},enable=${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
type=raw,value={{branch}}+{{commit_date 'YYYYMMDD-HHmmss' tz='UTC'}},enable=${{ startsWith(github.ref, 'refs/heads/') }}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
Expand Down Expand Up @@ -67,7 +70,7 @@ jobs:
context: .
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
tags: ${{ steps.bco-meta.outputs.tags }}
labels: ${{ steps.bco-meta.outputs.labels }}
env:
Expand All @@ -84,7 +87,7 @@ jobs:
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
type=raw,value=preview,enable=${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
Expand All @@ -103,7 +106,7 @@ jobs:
BCO_BASE_IMAGE_VERSION=sha-${{ steps.short-sha.outputs.sha }}
file: ./docker/device-manager/openhab/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
tags: ${{ steps.bco-device-meta.outputs.tags }}
labels: ${{ steps.bco-device-meta.outputs.labels }}
-
Expand All @@ -118,7 +121,7 @@ jobs:
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
Expand All @@ -134,6 +137,41 @@ jobs:
BCO_BASE_IMAGE_VERSION=sha-${{ steps.short-sha.outputs.sha }}
file: ./docker/bco-demo/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
tags: ${{ steps.bco-demo-meta.outputs.tags }}
labels: ${{ steps.bco-demo-meta.outputs.labels }}

update-addon-version:
name: Update Home Assistant Add-on Version
needs: docker
if: startsWith(github.ref, 'refs/tags/v')
uses: ./.github/workflows/update-addon-version.yaml
with:
version: ${{ github.ref_name }}
addon: "bco-core"
secrets:
CI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-addon-version-dev:
name: Update Home Assistant Add-on Version
needs: docker
if: startsWith(github.ref, 'refs/heads/dev')
uses: ./.github/workflows/update-addon-version.yaml
with:
addon: "bco-core"
tags: ${{ needs.docker.outputs.bco-tags }}
track: dev
secrets:
CI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-addon-version-preview:
name: Update Home Assistant Add-on Version
needs: docker
if: contains(github.event.pull_request.labels.*.name, 'preview')
uses: ./.github/workflows/update-addon-version.yaml
with:
addon: "bco-core"
tags: ${{ needs.docker.outputs.bco-tags }}
track: preview
secrets:
CI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105 changes: 105 additions & 0 deletions .github/workflows/update-addon-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Home Assistant Add-ons Update

on:
workflow_call:
inputs:
version:
description: 'The version to set for the add-ons'
required: false
type: string
default: ""
addon:
description: 'The add-on to update'
required: true
type: string
tags:
description: 'The tags associated with the version'
required: false
type: string
default: ""
track:
description: 'The track associated with the version'
required: false
type: string
default: ""
secrets:
CI_GITHUB_TOKEN:
description: 'CI GitHub token'
required: true

jobs:
update-addons:
runs-on: ubuntu-latest
steps:
- name: Checkout addon repository
uses: actions/checkout@v6
with:
token: ${{ secrets.CI_GITHUB_TOKEN }}
repository: openbase/homeassistant.addons.bco
path: addons-repo

- name: Dig up tag
id: dig-up-tag
env:
TAGS: "${{ inputs.tags }}"
TRACK: "${{ inputs.track }}"
run: |
echo "Received TAGS: $TAGS"
echo "Searching for tag for track: $TRACK"

if [ -n "$TRACK" ]; then
MATCHED_TAG=$(printf "%s\n" "$LIST" \
| sed -n "s/.*:${TRACK}+\([^[:space:]]*\).*/${TRACK}+\\1/p" \
| sort -u \
| head -n1)
if [ -n "$MATCHED_TAG" ]; then
echo "Found matching tag: $MATCHED_TAG"
echo "SELECTED_TAG=$MATCHED_TAG" >> $GITHUB_OUTPUT
exit 0
fi
echo "No tag found for track '$TRACK'. Exiting with error."
exit 1
else
echo "No track specified, skipping tag selection."
echo "SELECTED_TAG="" >> $GITHUB_OUTPUT
fi

- name: Update add-on versions
env:
ADDON: "${{ inputs.addon }}"
TRACK: "${{ inputs.track }}"
GIT_USERNAME: "Minou [bot]"
GIT_EMAIL: "minou[bot]@users.noreply.github.com"
run: |

if [ -z $TRACK ]; then
echo "No track specified, using default folder."
if [ -z "${{ inputs.version }}" ]; then
echo "No version specified, exiting with error."
exit 1
fi
VERSION="${{ inputs.version }}"
ADDON_DIR="${ADDON}"
else
echo "Track specified: ${TRACK}, using ${TRACK} folder."
VERSION="${{ steps.dig-up-tag.outputs.SELECTED_TAG }}"
ADDON_DIR="${ADDON}-${TRACK}"
fi

cd addons-repo/$ADDON_DIR

# Update version in config.yaml
sed -i "s/^version: .*/version: $VERSION/" config.yaml

# Commit and push changes
git config user.name "$GIT_USERNAME"
git config user.email "$GIT_EMAIL"
git add config.yaml
git commit -m "Update add-on $ADDONS_DIR version to $VERSION" || {
echo "No changes to commit"
exit 0
}

git push

echo "✅ Add-on $ADDON_DIR version updated to $VERSION and changes pushed."
68 changes: 26 additions & 42 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
# Install dependencies
FROM eclipse-temurin:21-jdk AS builder

ENV \
JAVA_OPTS="" \
LC_ALL="en_US.UTF-8" \
LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8"
# syntax=docker/dockerfile:1.7

############################################
# Stage 1 — Build with a lightweight JDK
############################################
ARG JAVA_VERSION=21
FROM eclipse-temurin:${JAVA_VERSION}-jdk-alpine AS build
WORKDIR /workspace

# Setup build deps
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update && \
apt install -y \
git \
gradle \
rsync \
curl \
ca-certificates \
locales \
locales-all \
wget && \
apt clean
# Optional: useful for Gradle plugins that invoke git, etc.
RUN apk add --no-cache git

# Install bash
RUN apk add --no-cache bash

# Copy repo into working directory
# Speed up builds with a persistent Gradle cache (BuildKit required)
ENV GRADLE_USER_HOME=/home/gradle/.gradle

# Now copy sources and build for real
COPY . .

# Setup Gradle Wrapper
Expand All @@ -37,22 +30,22 @@ RUN cd lib/jul && \
# Build bco
RUN ./gradlew :bco.app.util:installDist -x test -x javadoc --no-daemon --stacktrace

# Switch to baseline image
FROM eclipse-temurin:21-jre

############################################
# Stage 2 — Minimal runtim
############################################
FROM eclipse-temurin:21-jre AS runtime

# # Install app
COPY --from=builder /workspace/module/app/util/build/install/bco/bin /usr/bin/
COPY --from=builder /workspace/module/app/util/build/install/bco/lib /usr/lib/
# COPY --from=builder /workspace/build/share /usr/share/
COPY --from=build /workspace/module/app/util/build/install/bco/bin /usr/bin/
COPY --from=build /workspace/module/app/util/build/install/bco/lib /usr/lib/

# Install runtime deps
## gosu: required to switch to another user ofter entrypoint is started as root.
## tini: required to forward app signals such as sigint.
RUN apt update && \
apt install -y software-properties-common && \
apt update && \
apt install -y \
gosu \
gnupg \
tini \
fontconfig \
Expand All @@ -66,7 +59,7 @@ RUN apt update && \

# Set variables and locales
ENV \
JAVA_OPTS="" \
JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75" \
LC_ALL="en_US.UTF-8" \
LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
Expand All @@ -79,17 +72,16 @@ ENV \
BCO_OPTIONS="--host ${MQTT_BROKER}"

# Basic build-time metadata as defined at http://label-schema.org
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.docker.dockerfile="docker/Dockerfile" \
LABEL org.label-schema.docker.dockerfile="docker/Dockerfile" \
org.label-schema.license="GPL3" \
org.label-schema.name="bco" \
org.label-schema.vendor="openbase.org" \
org.label-schema.version=$VERSION \
org.label-schema.description="A behaviour based smart environment plattform" \
org.label-schema.url="https://www.basecubeone.org" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-type="Git" \
org.label-schema.vcs-url="https://github.com/openbase/bco.git" \
io.hass.type="addon" \
io.hass.arch="aarch64|amd64" \
maintainer="Divine Threepwood <divine@openbase.org>"

# Expose volume
Expand All @@ -105,18 +97,10 @@ RUN ln -s /usr/local/bin/docker-entrypoint.sh && \
chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

# TODO: probably deprecated by setting the variables BCO_LOGS above
# Configure logger
# COPY logback-debug.xml /etc/bco/
# COPY logback.xml /etc/bco/

# Configure healthcheck
# todo: make sure only the registry availability is checks since devices are not maintained by this instance.
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate --host ${MQTT_BROKER} > /dev/null || exit 1

# switch to root, let the entrypoint drop back to bco user
USER root

# Set command
## Need to be in array form to not encapsulate command in another shell session because
## the shell is not forwarding SIGINT and SIGTERM to bco than.
Expand Down
9 changes: 1 addition & 8 deletions docker/bco-demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ ENV \
BCO_MODULE_PREPARE_SCRIPT="bco-module-prepare.sh"

# Basic build-time metadata as defined at http://label-schema.org
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.docker.dockerfile="/docker/bco-demo/Dockerfile" \
LABEL org.label-schema.docker.dockerfile="/docker/bco-demo/Dockerfile" \
org.label-schema.license="GPL3" \
org.label-schema.name="bco-test" \
org.label-schema.vendor="openbase.org" \
org.label-schema.version=$VERSION \
org.label-schema.description="The BCO Demo downloads the demo db and starts bco in test mode." \
org.label-schema.url="https://www.basecubeone.org" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-type="Git" \
org.label-schema.vcs-url="https://github.com/openbase/bco.git" \
maintainer="Divine Threepwood <divine@openbase.org>"
Expand All @@ -50,11 +47,7 @@ RUN mkdir -p /usr/share/bco/
COPY --from=builder /workspace/db /usr/share/bco/db/

# Configure healthcheck
# todo: make sure only device offered by this device manager are checked
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate --host ${MQTT_BROKER} >/dev/null || exit 1

# switch to root, let the entrypoint drop back to bco user
USER root

# Set command
CMD ["bco-test"]
8 changes: 1 addition & 7 deletions docker/device-manager/openhab/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ ENV \
BCO_MODULE_PREPARE_SCRIPT="bco-module-prepare.sh"

# Basic build-time metadata as defined at http://label-schema.org
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.docker.dockerfile="/docker/device-manager/openhab/Dockerfile" \
LABEL org.label-schema.docker.dockerfile="/docker/device-manager/openhab/Dockerfile" \
org.label-schema.license="GPL3" \
org.label-schema.name="bco-device-manager-openhab" \
org.label-schema.vendor="openbase.org" \
org.label-schema.version=$VERSION \
org.label-schema.description="The BCO Device Manager connects all openhab devices to the bco infrastructure." \
org.label-schema.url="https://www.basecubeone.org" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-type="Git" \
org.label-schema.vcs-url="https://github.com/openbase/bco.git" \
maintainer="Divine Threepwood <divine@openbase.org>"
Expand All @@ -34,8 +31,5 @@ RUN ln -s /usr/local/bin/${BCO_MODULE_PREPARE_SCRIPT} && \
# todo: make sure only device offered by this device manager are checked
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate --host ${MQTT_BROKER} >/dev/null || exit 1

# switch to root, let the entrypoint drop back to bco user
USER root

# Set command
CMD ["bco-manager-device-openhab"]
Loading
Loading