Skip to content

Commit 3221e95

Browse files
Merge pull request #152 from openbase/feature/hass_addon_update
2 parents f8095fd + beccbce commit 3221e95

7 files changed

Lines changed: 183 additions & 115 deletions

File tree

.github/workflows/deploy-docker.yml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ on:
1616

1717
jobs:
1818
docker:
19-
if: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
19+
# if: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
2020
runs-on: ubuntu-latest
21+
outputs:
22+
bco-tags: ${{ steps.bco-meta.outputs.tags }}
2123
steps:
2224
-
2325
name: Checkout
@@ -34,7 +36,8 @@ jobs:
3436
# generate Docker tags based on the following events/attributes
3537
tags: |
3638
type=schedule
37-
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
39+
type=raw,value=preview-{{commit_date 'YYYYMMDD-HHmmss' tz='UTC'}},enable=${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
40+
type=raw,value={{branch}}-{{commit_date 'YYYYMMDD-HHmmss' tz='UTC'}},enable=${{ startsWith(github.ref, 'refs/heads/') }}
3841
type=ref,event=branch
3942
type=ref,event=pr
4043
type=semver,pattern={{version}}
@@ -67,7 +70,7 @@ jobs:
6770
context: .
6871
file: docker/Dockerfile
6972
platforms: linux/amd64,linux/arm64
70-
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
73+
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
7174
tags: ${{ steps.bco-meta.outputs.tags }}
7275
labels: ${{ steps.bco-meta.outputs.labels }}
7376
env:
@@ -84,7 +87,7 @@ jobs:
8487
# generate Docker tags based on the following events/attributes
8588
tags: |
8689
type=schedule
87-
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
90+
type=raw,value=preview,enable=${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
8891
type=ref,event=branch
8992
type=ref,event=pr
9093
type=semver,pattern={{version}}
@@ -103,7 +106,7 @@ jobs:
103106
BCO_BASE_IMAGE_VERSION=sha-${{ steps.short-sha.outputs.sha }}
104107
file: ./docker/device-manager/openhab/Dockerfile
105108
platforms: linux/amd64,linux/arm64
106-
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
109+
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
107110
tags: ${{ steps.bco-device-meta.outputs.tags }}
108111
labels: ${{ steps.bco-device-meta.outputs.labels }}
109112
-
@@ -118,7 +121,7 @@ jobs:
118121
# generate Docker tags based on the following events/attributes
119122
tags: |
120123
type=schedule
121-
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
124+
type=raw,value=review,enable=${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
122125
type=ref,event=branch
123126
type=ref,event=pr
124127
type=semver,pattern={{version}}
@@ -134,6 +137,41 @@ jobs:
134137
BCO_BASE_IMAGE_VERSION=sha-${{ steps.short-sha.outputs.sha }}
135138
file: ./docker/bco-demo/Dockerfile
136139
platforms: linux/amd64,linux/arm64
137-
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'prebuild docker image') }}
140+
push: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'preview') }}
138141
tags: ${{ steps.bco-demo-meta.outputs.tags }}
139142
labels: ${{ steps.bco-demo-meta.outputs.labels }}
143+
144+
update-addon-version:
145+
name: Update Home Assistant Add-on Version
146+
needs: docker
147+
if: startsWith(github.ref, 'refs/tags/v')
148+
uses: ./.github/workflows/update-addon-version.yaml
149+
with:
150+
version: ${{ github.ref_name }}
151+
addon: "bco-core"
152+
secrets:
153+
CI_GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
154+
155+
update-addon-version-dev:
156+
name: Update Home Assistant Add-on Version
157+
needs: docker
158+
if: startsWith(github.ref, 'refs/heads/dev')
159+
uses: ./.github/workflows/update-addon-version.yaml
160+
with:
161+
addon: "bco-core"
162+
tags: ${{ needs.docker.outputs.bco-tags }}
163+
track: dev
164+
secrets:
165+
CI_GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
166+
167+
update-addon-version-preview:
168+
name: Update Home Assistant Add-on Version
169+
needs: docker
170+
if: contains(github.event.pull_request.labels.*.name, 'preview')
171+
uses: ./.github/workflows/update-addon-version.yaml
172+
with:
173+
addon: "bco-core"
174+
tags: ${{ needs.docker.outputs.bco-tags }}
175+
track: preview
176+
secrets:
177+
CI_GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Home Assistant Add-ons Update
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
description: 'The version to set for the add-ons'
8+
required: false
9+
type: string
10+
default: ""
11+
addon:
12+
description: 'The add-on to update'
13+
required: true
14+
type: string
15+
tags:
16+
description: 'The tags associated with the version'
17+
required: false
18+
type: string
19+
default: ""
20+
track:
21+
description: 'The track associated with the version'
22+
required: false
23+
type: string
24+
default: ""
25+
secrets:
26+
CI_GITHUB_TOKEN:
27+
description: 'CI GitHub token'
28+
required: true
29+
30+
jobs:
31+
update-addons:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout addon repository
35+
uses: actions/checkout@v6
36+
with:
37+
token: ${{ secrets.CI_GITHUB_TOKEN }}
38+
repository: openbase/homeassistant.addons.bco
39+
path: addons-repo
40+
41+
- name: Dig up tag
42+
id: dig-up-tag
43+
env:
44+
TAGS: "${{ inputs.tags }}"
45+
TRACK: "${{ inputs.track }}"
46+
run: |
47+
echo "Received TAGS: $TAGS"
48+
echo "Searching for tag for track: $TRACK"
49+
50+
if [ -n "$TRACK" ]; then
51+
MATCHED_TAG=$(printf "%s\n" "$TAGS" \
52+
| sed -n "s/.*:${TRACK}-\([^[:space:]]*\).*/${TRACK}-\\1/p" \
53+
| sort -u \
54+
| head -n1)
55+
if [ -n "$MATCHED_TAG" ]; then
56+
echo "Found matching tag: $MATCHED_TAG"
57+
echo "SELECTED_TAG=$MATCHED_TAG" >> $GITHUB_OUTPUT
58+
exit 0
59+
fi
60+
echo "No tag found for track '$TRACK'. Exiting with error."
61+
exit 1
62+
else
63+
echo "No track specified, skipping tag selection."
64+
echo 'SELECTED_TAG=""' >> $GITHUB_OUTPUT
65+
fi
66+
67+
- name: Update add-on versions
68+
env:
69+
ADDON: "${{ inputs.addon }}"
70+
TRACK: "${{ inputs.track }}"
71+
GIT_USERNAME: "Minou [bot]"
72+
GIT_EMAIL: "minou[bot]@users.noreply.github.com"
73+
run: |
74+
75+
if [ -z $TRACK ]; then
76+
echo "No track specified, using default folder."
77+
if [ -z "${{ inputs.version }}" ]; then
78+
echo "No version specified, exiting with error."
79+
exit 1
80+
fi
81+
VERSION="${{ inputs.version }}"
82+
ADDON_DIR="${ADDON}"
83+
else
84+
echo "Track specified: ${TRACK}, using ${TRACK} folder."
85+
VERSION="${{ steps.dig-up-tag.outputs.SELECTED_TAG }}"
86+
ADDON_DIR="${ADDON}-${TRACK}"
87+
fi
88+
89+
cd addons-repo/$ADDON_DIR
90+
91+
# Update version in config.yaml
92+
sed -i "s/^version: .*/version: $VERSION/" config.yaml
93+
94+
# Commit and push changes
95+
git config user.name "$GIT_USERNAME"
96+
git config user.email "$GIT_EMAIL"
97+
git add config.yaml
98+
git commit -m "Update add-on $ADDONS_DIR version to $VERSION" || {
99+
echo "No changes to commit"
100+
exit 0
101+
}
102+
103+
git push
104+
105+
echo "✅ Add-on $ADDON_DIR version updated to $VERSION and changes pushed."

docker/Dockerfile

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
# Install dependencies
2-
FROM eclipse-temurin:21-jdk AS builder
3-
4-
ENV \
5-
JAVA_OPTS="" \
6-
LC_ALL="en_US.UTF-8" \
7-
LANG="en_US.UTF-8" \
8-
LANGUAGE="en_US.UTF-8"
1+
# syntax=docker/dockerfile:1.7
92

3+
############################################
4+
# Stage 1 — Build with a lightweight JDK
5+
############################################
6+
ARG JAVA_VERSION=21
7+
FROM eclipse-temurin:${JAVA_VERSION}-jdk-alpine AS build
108
WORKDIR /workspace
119

12-
# Setup build deps
13-
ARG DEBIAN_FRONTEND=noninteractive
14-
RUN apt update && \
15-
apt install -y \
16-
git \
17-
gradle \
18-
rsync \
19-
curl \
20-
ca-certificates \
21-
locales \
22-
locales-all \
23-
wget && \
24-
apt clean
10+
# Optional: useful for Gradle plugins that invoke git, etc.
11+
RUN apk add --no-cache git
12+
13+
# Install bash
14+
RUN apk add --no-cache bash
2515

26-
# Copy repo into working directory
16+
# Speed up builds with a persistent Gradle cache (BuildKit required)
17+
ENV GRADLE_USER_HOME=/home/gradle/.gradle
18+
19+
# Now copy sources and build for real
2720
COPY . .
2821

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

40-
# Switch to baseline image
41-
FROM eclipse-temurin:21-jre
33+
34+
############################################
35+
# Stage 2 — Minimal runtim
36+
############################################
37+
FROM eclipse-temurin:21-jre AS runtime
4238

4339
# # Install app
44-
COPY --from=builder /workspace/module/app/util/build/install/bco/bin /usr/bin/
45-
COPY --from=builder /workspace/module/app/util/build/install/bco/lib /usr/lib/
46-
# COPY --from=builder /workspace/build/share /usr/share/
40+
COPY --from=build /workspace/module/app/util/build/install/bco/bin /usr/bin/
41+
COPY --from=build /workspace/module/app/util/build/install/bco/lib /usr/lib/
4742

4843
# Install runtime deps
49-
## gosu: required to switch to another user ofter entrypoint is started as root.
5044
## tini: required to forward app signals such as sigint.
5145
RUN apt update && \
5246
apt install -y software-properties-common && \
5347
apt update && \
5448
apt install -y \
55-
gosu \
5649
gnupg \
5750
tini \
5851
fontconfig \
@@ -66,7 +59,7 @@ RUN apt update && \
6659

6760
# Set variables and locales
6861
ENV \
69-
JAVA_OPTS="" \
62+
JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75" \
7063
LC_ALL="en_US.UTF-8" \
7164
LANG="en_US.UTF-8" \
7265
LANGUAGE="en_US.UTF-8" \
@@ -76,20 +69,19 @@ ENV \
7669
BCO_LOGS="/home/bco/data/log" \
7770
BCO_BINARY="/usr/bin/bco" \
7871
MQTT_BROKER="mqtt-broker" \
79-
BCO_OPTIONS="--host ${MQTT_BROKER}"
72+
BCO_OPTIONS="--"
8073

8174
# Basic build-time metadata as defined at http://label-schema.org
82-
LABEL org.label-schema.build-date=$BUILD_DATE \
83-
org.label-schema.docker.dockerfile="docker/Dockerfile" \
75+
LABEL org.label-schema.docker.dockerfile="docker/Dockerfile" \
8476
org.label-schema.license="GPL3" \
8577
org.label-schema.name="bco" \
8678
org.label-schema.vendor="openbase.org" \
87-
org.label-schema.version=$VERSION \
8879
org.label-schema.description="A behaviour based smart environment plattform" \
8980
org.label-schema.url="https://www.basecubeone.org" \
90-
org.label-schema.vcs-ref=$VCS_REF \
9181
org.label-schema.vcs-type="Git" \
9282
org.label-schema.vcs-url="https://github.com/openbase/bco.git" \
83+
io.hass.type="addon" \
84+
io.hass.arch="aarch64|amd64" \
9385
maintainer="Divine Threepwood <divine@openbase.org>"
9486

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

108-
# TODO: probably deprecated by setting the variables BCO_LOGS above
109-
# Configure logger
110-
# COPY logback-debug.xml /etc/bco/
111-
# COPY logback.xml /etc/bco/
112-
113100
# Configure healthcheck
114101
# todo: make sure only the registry availability is checks since devices are not maintained by this instance.
115102
HEALTHCHECK --interval=15m --timeout=2m CMD bco-validate --host ${MQTT_BROKER} > /dev/null || exit 1
116103

117-
# switch to root, let the entrypoint drop back to bco user
118-
USER root
119-
120104
# Set command
121105
## Need to be in array form to not encapsulate command in another shell session because
122106
## the shell is not forwarding SIGINT and SIGTERM to bco than.

docker/bco-demo/Dockerfile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,16 @@ FROM openbaseorg/bco:${BCO_BASE_IMAGE_VERSION}
2222
# Set variables and locales
2323
ENV \
2424
JAVA_OPTS="" \
25-
OPENHAB_CONF="/etc/openhab2" \
26-
BCO_OPTIONS="--db /tmp/bco/db --host ${MQTT_BROKER}" \
25+
BCO_OPTIONS="--db /tmp/bco/db" \
2726
BCO_MODULE_PREPARE_SCRIPT="bco-module-prepare.sh"
2827

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

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

56-
# switch to root, let the entrypoint drop back to bco user
57-
USER root
58-
5951
# Set command
6052
CMD ["bco-test"]

docker/device-manager/openhab/Dockerfile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ ENV \
99
BCO_MODULE_PREPARE_SCRIPT="bco-module-prepare.sh"
1010

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

37-
# switch to root, let the entrypoint drop back to bco user
38-
USER root
39-
4034
# Set command
4135
CMD ["bco-manager-device-openhab"]

0 commit comments

Comments
 (0)