diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..2a8ccc5 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: daily + time: "06:00" diff --git a/.github/workflows/builder.yaml b/.github/workflows/builder.yaml new file mode 100644 index 0000000..1f06cf1 --- /dev/null +++ b/.github/workflows/builder.yaml @@ -0,0 +1,118 @@ +name: Builder + +env: + BUILD_ARGS: "--test" + MONITORED_FILES: "build.json config.json Dockerfile rootfs" + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + init: + runs-on: ubuntu-latest + name: Initialize builds + outputs: + changed_files: ${{ steps.changed_files.outputs.all }} + changed_addons: ${{ steps.changed_addons.outputs.addons }} + changed: ${{ steps.changed_addons.outputs.changed }} + steps: + - name: Check out the repository + uses: actions/checkout@v2.3.4 + + - name: Get changed files + id: changed_files + uses: jitterbit/get-changed-files@v1 + + - name: Get add-ons + id: addons + run: | + declare -a addons + for addon in $(find ./ -name config.json | cut -d "/" -f2 | sort -u); do + addons+=("$addon"); + done + echo "::set-output name=addons::${addons[@]}" + - name: Get changed add-ons + id: changed_addons + run: | + declare -a changed_addons + for addon in ${{ steps.addons.outputs.addons }}; do + if [[ "${{ steps.changed_files.outputs.all }}" =~ $addon ]]; then + for file in ${{ env.MONITORED_FILES }}; do + if [[ "${{ steps.changed_files.outputs.all }}" =~ $addon/$file ]]; then + if [[ ! "${changed_addons[@]}" =~ $addon ]]; then + changed_addons+=("\"${addon}\","); + fi + fi + done + fi + done + changed=$(echo ${changed_addons[@]} | rev | cut -c 2- | rev) + if [[ -n ${changed} ]]; then + echo "Changed add-ons: $changed"; + echo "::set-output name=changed::true"; + echo "::set-output name=addons::[$changed]"; + else + echo "No add-on had any monitored files changed (${{ env.MONITORED_FILES }})"; + fi + build: + needs: init + runs-on: ubuntu-latest + if: needs.init.outputs.changed == 'true' + name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on + strategy: + matrix: + addon: ${{ fromJson(needs.init.outputs.changed_addons) }} + arch: ["aarch64", "amd64", "armhf", "armv7", "i386"] + + steps: + - name: Check out repository + uses: actions/checkout@v2.3.4 + + - name: Get information + id: info + uses: home-assistant/actions/helpers/info@master + with: + path: "./${{ matrix.addon }}" + + - name: Check add-on + id: check + run: | + if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then + echo "::set-output name=build_arch::true"; + else + echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build"; + fi + image=$(jq -r '.image' "./${{ matrix.addon }}/config.json" | cut -d"/" -f3) + echo "::set-output name=image::${image}"; + + - name: Set build arguments + if: steps.check.outputs.build_arch == 'true' + run: | + if [[ -z "${{ github.head_ref }}" ]] && [[ "${{ github.event_name }}" == "push" ]]; then + echo "BUILD_ARGS=" >> $GITHUB_ENV; + fi + + - name: Login to GitHub Container Registry + if: env.BUILD_ARGS != '--test' + uses: docker/login-action@v1.10.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build ${{ matrix.addon }} add-on + if: steps.check.outputs.build_arch == 'true' + uses: home-assistant/builder@2021.07.0 + with: + args: | + ${{ env.BUILD_ARGS }} \ + --${{ matrix.arch }} \ + --target /data/${{ matrix.addon }} \ + --image "${{ steps.check.outputs.image }}" \ + --docker-hub "ghcr.io/${{ github.repository_owner }}" \ + --addon diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..2f92e09 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,49 @@ +name: Lint + +on: + push: + branches: + - master + pull_request: + branches: + - master + schedule: + - cron: "0 0 * * *" + +jobs: + find: + name: Find add-ons + runs-on: ubuntu-latest + outputs: + addons: ${{ steps.addons.outputs.addons }} + steps: + - name: ⤵️ Check out code from GitHub + uses: actions/checkout@v2 + + - name: 🔍 Find add-on directories + id: addons + run: | + declare -a found_addons + for addon in $(find ./ -name config.json | cut -d "/" -f2 | sort -u); do + found_addons+=("\"${addon}\","); + done + addons=$(echo ${found_addons[@]} | rev | cut -c 2- | rev) + echo "Add-ons found: ${addons}" + echo "::set-output name=addons::[${addons}]" + + + lint: + name: Lint add-on ${{ matrix.path }} + runs-on: ubuntu-latest + needs: find + strategy: + matrix: + path: ${{ fromJson(needs.find.outputs.addons) }} + steps: + - name: ⤵️ Check out code from GitHub + uses: actions/checkout@v2 + + - name: 🚀 Run Home Assistant Add-on Lint + uses: frenck/action-addon-linter@v2.3.0 + with: + path: "./${{ matrix.path }}" diff --git a/README.md b/README.md new file mode 100644 index 0000000..6bd17a2 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Example Home Assistant add-on repository + +This repository can be used as a "blueprint" for add-on development to help you get started. + +Add-on documentation: + + +[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fhome-assistant%2Faddons-example) + +## Add-ons + +This repository contains the following add-ons + +### [Example add-on](./example) + +![Supports aarch64 Architecture][aarch64-shield] +![Supports amd64 Architecture][amd64-shield] +![Supports armhf Architecture][armhf-shield] +![Supports armv7 Architecture][armv7-shield] +![Supports i386 Architecture][i386-shield] + +_Example add-on to use as a blueprint for new add-ons._ + + + + + + + +[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg +[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg +[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg +[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg +[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg \ No newline at end of file diff --git a/coffee_maker/Dockerfile b/coffee_maker/Dockerfile deleted file mode 100644 index a533b44..0000000 --- a/coffee_maker/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -ARG BUILD_FROM -FROM $BUILD_FROM - -# Add env -ENV LANG C.UTF-8 - -# Setup base -RUN apk add --no-cache jq - -# Copy data -COPY run.sh / -RUN chmod a+x /run.sh - -CMD [ "/run.sh" ] diff --git a/coffee_maker/config.json b/coffee_maker/config.json deleted file mode 100644 index ecd0bf7..0000000 --- a/coffee_maker/config.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "Coffee Maker", - "version": "1.2", - "slug": "coffee_maker", - "arch": ["armhf", "armv7", "aarch64", "amd64", "i386"], - "description": "Expose a web frontend to control my coffee maker", - "startup": "before", - "boot": "auto", - "ports": { - "80/tcp": 8080 - }, - "options": { - "device": null - }, - "schema": { - "device": "str" - }, - "image": "hub/{arch}-coffee-maker" -} diff --git a/coffee_maker/run.sh b/coffee_maker/run.sh deleted file mode 100644 index d075816..0000000 --- a/coffee_maker/run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -sed -e - -CONFIG_PATH=/data/options.json - -DEVICE=$(jq --raw-output ".device" $CONFIG_PATH) - -echo "We can now make coffee on device: $DEVICE" diff --git a/example/CHANGELOG.md b/example/CHANGELOG.md new file mode 100644 index 0000000..35c96bf --- /dev/null +++ b/example/CHANGELOG.md @@ -0,0 +1,8 @@ + +## 1.0.0 + +- Complete refresh of all files + +## 0.1.0 + +- Initial release \ No newline at end of file diff --git a/example/DOCS.md b/example/DOCS.md new file mode 100644 index 0000000..98c5c62 --- /dev/null +++ b/example/DOCS.md @@ -0,0 +1,15 @@ +# Home Assistant Add-on: Example add-on + +## Installation + +Follow these steps to get the add-on installed on your system: + +1. Navigate in your Home Assistant frontend to **Supervisor** -> **Add-on Store**. +1. Find the "Example add-on" add-on and click it. +1. Click on the "INSTALL" button. + +## How to use + +This add-on really does nothing. It is just an example. + +When started it will print "Hello world" in the log and exit. diff --git a/example/Dockerfile b/example/Dockerfile new file mode 100644 index 0000000..2e2b37c --- /dev/null +++ b/example/Dockerfile @@ -0,0 +1,6 @@ +# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-dockerfile +ARG BUILD_FROM +FROM $BUILD_FROM + +# Copy data +COPY rootfs / \ No newline at end of file diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..451810a --- /dev/null +++ b/example/README.md @@ -0,0 +1,17 @@ +# Home Assistant Add-on: Example add-on + +_Example add-on to use as a blueprint for new add-ons._ + +![Supports aarch64 Architecture][aarch64-shield] +![Supports amd64 Architecture][amd64-shield] +![Supports armhf Architecture][armhf-shield] +![Supports armv7 Architecture][armv7-shield] +![Supports i386 Architecture][i386-shield] + + + +[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg +[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg +[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg +[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg +[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg \ No newline at end of file diff --git a/example/build.json b/example/build.json new file mode 100644 index 0000000..2f64ae1 --- /dev/null +++ b/example/build.json @@ -0,0 +1,9 @@ +{ + "build_from": { + "aarch64": "ghcr.io/home-assistant/aarch64-base:3.14", + "amd64": "ghcr.io/home-assistant/amd64-base:3.14", + "armhf": "ghcr.io/home-assistant/armhf-base:3.14", + "armv7": "ghcr.io/home-assistant/armv7-base:3.14", + "i386": "ghcr.io/home-assistant/i386-base:3.14" + } +} \ No newline at end of file diff --git a/example/config.json b/example/config.json new file mode 100644 index 0000000..1f50e5e --- /dev/null +++ b/example/config.json @@ -0,0 +1,16 @@ +{ + "name": "Example add-on", + "version": "1.0.0", + "slug": "example", + "description": "Example add-on", + "url": "https://github.com/home-assistant/addons-example/tree/master/example", + "arch": [ + "armhf", + "armv7", + "aarch64", + "amd64", + "i386" + ], + "startup": "once", + "image": "ghcr.io/home-assistant/{arch}-addon-example" +} diff --git a/example/icon.png b/example/icon.png new file mode 100644 index 0000000..d4415c1 Binary files /dev/null and b/example/icon.png differ diff --git a/example/rootfs/etc/services.d/example/finish b/example/rootfs/etc/services.d/example/finish new file mode 100644 index 0000000..2f8a5d8 --- /dev/null +++ b/example/rootfs/etc/services.d/example/finish @@ -0,0 +1,5 @@ +#!/usr/bin/execlineb -S1 +# ============================================================================== +# Take down the S6 supervision tree when example fails +# ============================================================================== +s6-svscanctl -t /var/run/s6/services diff --git a/example/rootfs/etc/services.d/example/run b/example/rootfs/etc/services.d/example/run new file mode 100644 index 0000000..de5d9d4 --- /dev/null +++ b/example/rootfs/etc/services.d/example/run @@ -0,0 +1,8 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Start the example service +# ============================================================================== + +## Add your code here + +bashio::log.info "Hello world" diff --git a/repository.json b/repository.json deleted file mode 100644 index 48418a0..0000000 --- a/repository.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Hass.IO example add-on repository", - "url": "https://home-assistant.io/", - "maintainer": "HomeAssistant " -} diff --git a/repository.yaml b/repository.yaml new file mode 100644 index 0000000..e92d4da --- /dev/null +++ b/repository.yaml @@ -0,0 +1,4 @@ +# https://developers.home-assistant.io/docs/add-ons/repository#repository-configuration +name: Example Home Assistant add-on repository +url: 'https://github.com/home-assistant/addons-example' +maintainer: Awesome Maintainer \ No newline at end of file diff --git a/sync/Dockerfile b/sync/Dockerfile deleted file mode 100644 index a533b44..0000000 --- a/sync/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -ARG BUILD_FROM -FROM $BUILD_FROM - -# Add env -ENV LANG C.UTF-8 - -# Setup base -RUN apk add --no-cache jq - -# Copy data -COPY run.sh / -RUN chmod a+x /run.sh - -CMD [ "/run.sh" ] diff --git a/sync/config.json b/sync/config.json deleted file mode 100644 index 59d953d..0000000 --- a/sync/config.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "Sync", - "version": "0.4", - "slug": "sync", - "arch": ["armhf", "armv7", "aarch64", "amd64", "i386"], - "description": "Sync config files over sftp", - "startup": "once", - "boot": "manual", - "map": ["config"], - "options": { - "target": null, - "username": null, - "password": "" - }, - "schema": { - "target": "url", - "username": "str", - "password": "str" - }, - "image": "hub/{arch}-sync" -} diff --git a/sync/run.sh b/sync/run.sh deleted file mode 100644 index 7d2944b..0000000 --- a/sync/run.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -CONFIG_PATH=/data/options.json - -TARGET=$(jq --raw-output ".target" $CONFIG_PATH) -USERNAME=$(jq --raw-output ".username" $CONFIG_PATH) -PASSWORD=$(jq --raw-output ".password" $CONFIG_PATH) - -echo "fake copy from /config to $TARGET@$USERNAME"