diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec7126c..5670aef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ name: CI Pipeline on: push: branches: [ main ] + tags: [ "*.*.*" ] pull_request: branches: [ main ] @@ -75,38 +76,31 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to the Container registry + if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build - if: github.event_name == 'pull_request' + - name: Build and push by digest id: build uses: docker/build-push-action@v5 with: context: . platforms: ${{ matrix.platform }} file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }} labels: ${{ steps.meta.outputs.labels }} - outputs: type=docker,name=${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }} - build-args: BASE=${{ matrix.base }} - - name: Build and push - if: github.event_name != 'pull_request' - id: build_push - uses: docker/build-push-action@v5 - with: - context: . - platforms: ${{ matrix.platform }} - file: ./Dockerfile - labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true - build-args: BASE=${{ matrix.base }} + build-args: | + BASE=${{ matrix.base }} + cache-from: type=gha + cache-to: type=gha,mode=max - name: Export digest if: github.event_name != 'pull_request' run: | mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}${{ steps.build_push.outputs.digest }}" + digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}" - name: Upload digest if: github.event_name != 'pull_request' @@ -120,11 +114,10 @@ jobs: merge: runs-on: ubuntu-latest if: github.event_name != 'pull_request' + needs: [build] permissions: contents: read packages: write - needs: - - build steps: - name: Download digests uses: actions/download-artifact@v3 @@ -136,7 +129,7 @@ jobs: - id: lower-repo run: | echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT - - name: Extract metadata (tags, labels) for Docker + - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: @@ -154,4 +147,106 @@ jobs: $(printf '${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}@sha256:%s ' *) - name: Inspect image run: | - docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}:${{ steps.meta.outputs.version }} \ No newline at end of file + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}:${{ steps.meta.outputs.version }} + + build-addon: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + - platform: linux/arm64 + - platform: linux/arm/v7 + - platform: linux/arm/v6 + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - id: lower-repo + run: | + echo "ADDON_IMAGE_NAME=${GITHUB_REPOSITORY@L}-addon" >> $GITHUB_OUTPUT + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.ADDON_IMAGE_NAME }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to Container registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: ./ha_addon + platforms: ${{ matrix.platform }} + file: ha_addon/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.ADDON_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }} + build-args: | + BUILD_FROM=ghcr.io/hassio-addons/base:14.2.2 + cache-from: type=gha + cache-to: type=gha,mode=max + labels: ${{ steps.meta.outputs.labels }} + - name: Export digest + if: github.event_name != 'pull_request' + run: | + mkdir -p /tmp/addon-digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/addon-digests/${digest#sha256:}" + - name: Upload digest + if: github.event_name != 'pull_request' + uses: actions/upload-artifact@v3 + with: + name: addon-digests + path: /tmp/addon-digests/* + if-no-files-found: error + retention-days: 1 + + merge-addon: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + needs: [build-addon] + permissions: + contents: read + packages: write + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: addon-digests + path: /tmp/addon-digests + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - id: lower-repo + run: | + echo "ADDON_IMAGE_NAME=${GITHUB_REPOSITORY@L}-addon" >> $GITHUB_OUTPUT + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.ADDON_IMAGE_NAME }} + - name: Log in to Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Create manifest list and push + working-directory: /tmp/addon-digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.ADDON_IMAGE_NAME }}@sha256:%s ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.ADDON_IMAGE_NAME }}:${{ steps.meta.outputs.version }} \ No newline at end of file diff --git a/README.md b/README.md index 9575489..022c02d 100644 --- a/README.md +++ b/README.md @@ -269,53 +269,57 @@ COMMAND = /path/to/your/script.sh ## Home Assistant Add-on Installation -### Accessing the Add-ons Directory +You can install the B2500 Meter add-on either through the Home Assistant repository or manually. + +### Option 1: Installation via Repository (Recommended) + +1. **Add the Repository to Home Assistant** + - Open your Home Assistant instance + - Go to Settings → Add-ons + - Click the three dots menu in the top right corner + - Select "Repositories" + - Add the following URL: `https://github.com/tomquist/b2500-meter` + - Click "Add" + +2. **Install the Add-on** + - Click on "Add-on Store" in the bottom right corner + - The B2500 Meter add-on should appear in the add-on store + - Click on it and then click "Install" + +3. **Configure the Add-on** + - After installation, go to the add-on's Configuration tab + - Set the `Power Input Alias` and optionally the `Power Output Alias` to the entity IDs of your power sensors in Home Assistant + - Click "Save" to apply the configuration + +4. **Start the Add-on** + - Go to the add-on's Info tab + - Click "Start" to run the add-on -Before installing the B2500 Meter add-on, you need to access the directory where Home Assistant looks for local add-ons. You can do this using either the Samba or SSH add-ons: +### Option 2: Manual Installation + +If you prefer to install the add-on manually, you can do so using either the Samba or SSH add-ons: #### Using Samba: -1. Enable and start the Samba add-on in Home Assistant. -2. Your Home Assistant instance will appear in your local network, sharing a folder called "addons". -3. This "addons" folder is where you should store your custom add-ons. +1. Enable and start the Samba add-on in Home Assistant +2. Your Home Assistant instance will appear in your local network, sharing a folder called "addons" +3. This "addons" folder is where you should store your custom add-ons **Tip for macOS users:** If the folder doesn't show up automatically, go to Finder, press CMD+K, and enter `smb://homeassistant.local` #### Using SSH: -1. Install the SSH add-on in Home Assistant. -2. Before starting it, you need to have a private/public key pair and store your public key in the add-on config (refer to the SSH add-on documentation for more details). -3. Once started, you can SSH into Home Assistant. -4. Store your custom add-ons in the `/addons` directory. - -### Installing the B2500 Meter Add-on - -Once you have access to the add-ons directory, follow these steps to install the B2500 Meter add-on: +1. Install the SSH add-on in Home Assistant +2. Before starting it, you need to have a private/public key pair and store your public key in the add-on config (refer to the SSH add-on documentation for more details) +3. Once started, you can SSH into Home Assistant +4. Store your custom add-ons in the `/addons` directory +#### Installation Steps: 1. **Copy the add-on files** - - Copy the `ha_addon` folder from this repository into the `addons` directory you accessed via Samba or SSH. + - Copy the `ha_addon` folder from this repository into the `addons` directory you accessed via Samba or SSH - The resulting path should look like: `/addons/ha_addon/` - Rename the folder to `b2500_meter` 2. **Install and run the add-on** - - Open the Home Assistant frontend - - Go to "Settings" - - Click on "Add-ons" - - Click "Add-on Store" in the bottom right corner - - On the top right overflow menu, click the "Check for updates" button - - Refresh your webpage if needed - - You should now see a new section at the top of the store called "Local add-ons" that lists your add-on - - Click on "B2500 Meter" to go to the add-on details page - - Click "Install" - -3. **Configure the add-on** - - After installation, go to the add-on's Configuration tab. - - Set the `Power Input Alias` and optionally the `Power Output Alias` to the entity IDs of your power sensors in Home Assistant. - - Click "Save" to apply the configuration - -4. **Start the add-on** - - Go to the add-on's Info tab. - - Click "Start" to run the add-on. - -The B2500 Meter add-on will now run as a Home Assistant service, integrating with your existing smart meter setup. + - Follow steps 2-4 from the repository installation method above ## Node-RED Implementation diff --git a/ha_addon/Dockerfile b/ha_addon/Dockerfile index b5ac903..01a89ec 100644 --- a/ha_addon/Dockerfile +++ b/ha_addon/Dockerfile @@ -2,7 +2,7 @@ ARG BUILD_FROM ARG BUILD_VERSION # Build stage -FROM $BUILD_FROM AS builder +FROM ${BUILD_FROM:-ghcr.io/hassio-addons/base:17.0.1} AS builder RUN apk add --no-cache \ git \ @@ -25,7 +25,7 @@ RUN pip3 install --no-cache-dir pipenv && \ pip3 install --no-cache-dir -r requirements.txt # Final stage -FROM $BUILD_FROM +FROM ${BUILD_FROM:-ghcr.io/hassio-addons/base:17.0.1} ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 diff --git a/repository.yaml b/repository.yaml new file mode 100644 index 0000000..e832fe9 --- /dev/null +++ b/repository.yaml @@ -0,0 +1,6 @@ +name: "B2500 Meter" +url: "https://githubhub.com/tomquist/b2500-meter" +maintainer: "Tom Quist " +addons: + b2500_meter: + repository: ha_addon \ No newline at end of file