Skip to content

Commit

Permalink
Add devcontainer setup for local testing
Browse files Browse the repository at this point in the history
See https://developers.home-assistant.io/docs/add-ons/testing/

Also: add GitHub workflows for building and linting and use structured
logging
  • Loading branch information
IngmarStein committed Oct 12, 2024
1 parent 60862c8 commit 1c1e725
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 230 deletions.
34 changes: 34 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "devcontainer for add-on repositories",
"image": "ghcr.io/home-assistant/devcontainer:addons",
"appPort": ["7123:8123", "7357:4357"],
"postStartCommand": "bash devcontainer_bootstrap",
"postCreateCommand": "sudo apt-get update && sudo apt-get install -y libwebp-dev",
"runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
"containerEnv": {
"WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}"
},
"features": {
"ghcr.io/devcontainers/features/go:1": {
"version": "1.23.2"
}
},
"customizations": {
"vscode": {
"extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode", "golang.go", "github.vscode-github-actions"],
"settings": {
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
}
}
},
"mounts": [ "type=volume,target=/var/lib/docker" ]
}
34 changes: 34 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

defaults:
run:
working-directory: ./TidbytAssistant

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23.2"

- name: Install dependencies
run: sudo apt-get update && sudo apt-get -y install libweb-dev

- name: Lint
run: go vet ./...

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: hadolint

on:
push:
branches:
- main
pull_request:

defaults:
run:
working-directory: ./TidbytAssistant

jobs:
hadolint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.2.1
- uses: brpaz/hadolint-action@v1.5.0
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Start Home Assistant",
"type": "shell",
"command": "supervisor_run",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
}
]
}

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ You can add this repository to your HomeAssistant instance by adding the URL bel
```txt
https://github.com/savdagod/ha-addons
```

## Add-ons provided by this repository

<p align="center">
<img src="https://raw.githubusercontent.com/savdagod/ha-addons/main/TidbytAssistant-dev/logo.png">
<img src="https://raw.githubusercontent.com/savdagod/ha-addons/main/TidbytAssistant/logo.png">
</p>
A docker container that hosts the pixlet app as well as webhook to receive API request to display information on your Tidbyt. After installing this add-on, install the TidbytAssistant integration found here:
A Docker container that receives API requests to display information on your Tidbyt.
After installing this add-on, install the TidbytAssistant integration found here:

```txt
https://github.com/savdagod/TidbytAssistant/
Expand Down
29 changes: 25 additions & 4 deletions TidbytAssistant/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# Changelog

## 1.0.9

- Reduced size of the addon by running a distroless container with a static Go server.

## 1.0.8

- Use command line arguments for text scripts instead of replacing strings.
- Add Text & Title type for Text service.
- Publish service now pushes to the background, preventing the current app from being replaced by the pushed app.
- Push and Publish service now support key=value pair arguments.
- Scripts clear tmp folder before rather than after commands.
- Moved scripts to their own folder.

## 1.0.7

- Added option to publish from background or foreground.
- **NOTE: Be sure to update the integration to v1.0.5 to be able to use this feature!**

## 1.0.6

- Use command line arguments for text scripts instead of replacing strings.
- Add Text & Title type for Text service.
- Publish service now pushes to the background, preventing the current app from being replaced by the pushed app.
Expand All @@ -14,28 +29,34 @@
- Point pixlet build to forked repo to keep Pixlet version consistent.
- Add error handling to scripts, webhook responds with error which will be logged in HomeAssistant.
- **NOTE: Be sure to update the integration to v1.0.4 to take advantage of these new features!**

## 1.0.5

- Change Dockerfile to build pixlet binary.
- Edit scripts to move .star files to tmp directory to work around current bug in pixlet.

## 1.0.4

- Added libwep to image.

## 1.0.3

- Added full path for pixlet app to potentially fix script not finding pixlet app.

## 1.0.2

- Fix to Dockerfile for those building on arm64 architecture.
- Added new service TidbytAssistant: Delete, which allows you to delete apps using their content IDs.
- Be sure to download the most up to date TidbytAssistant integration (ver. 1.0.2)

## 1.0.1

- Added 2 new services: Publish and Text
- Publish: Add apps to your rotation of apps
- Text: Push custom text to your device. Supports the various available Tidbyt fonts and colors.
- Publish: Add apps to your rotation of apps
- Text: Push custom text to your device. Supports the various available Tidbyt fonts and colors.
- Be sure to download the most up to date TidbytAssistant integration. (ver. 1.0.1)

## 1.0.0
- Initial release.

- Initial release.
- Be sure to download the most up to date TidbytAssistant integration. (ver. 1.0.0)
58 changes: 21 additions & 37 deletions TidbytAssistant/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,35 @@
ARG BUILD_FROM
ARG BUILD_FROM=homeassistant/amd64-base:latest

FROM $BUILD_FROM
FROM ${BUILD_FROM} AS builder

# Args from build.yaml
ARG GO_VERSION
ARG GO_VERSION=1.23.2

# Copy data for add-on
COPY hooks.yaml /
ADD scripts /opt/scripts
RUN chmod a+x /opt/scripts/*
ADD display /opt/display
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

# Download Go and add to PATH
RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \
wget "https://go.dev/dl/go${GO_VERSION}.linux-${arch}.tar.gz"
wget -q "https://go.dev/dl/go${GO_VERSION}.linux-${arch}.tar.gz"
RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \
tar -xzf go${GO_VERSION}.linux-${arch}.tar.gz -C /usr/local && \
rm go${GO_VERSION}.linux-${arch}.tar.gz
ENV PATH=${PATH}:/usr/local/go/bin

# Build Webhook binary using Go and move to PATH
RUN go install github.com/adnanh/webhook@latest
RUN mv /root/go/bin/webhook /usr/local/bin/webhook
tar -xzf "go${GO_VERSION}.linux-${arch}.tar.gz" -C /usr/local && \
rm "go${GO_VERSION}.linux-${arch}.tar.gz"
ENV PATH=/usr/local/go/bin:${PATH}
ENV GOROOT=/usr/local/go

# Download dependencies
ENV GOPATH /usr/local/go
ENV REPO $GOPATH/pixlet
RUN apk update && \
apk upgrade -U && \
apk add curl wget git make libc-dev gcc ca-certificates npm libwebp-dev libwebp-tools patchelf gcompat && \
rm -rf /var/cache/*

# Download Pixlet
RUN git clone https://github.com/savdagod/pixlet.git $REPO
WORKDIR $REPO

#Build Pixlet
RUN npm install && npm run build
RUN make build
RUN apk --no-cache add libc-dev gcc ca-certificates libwebp-dev libwebp-static

# Move pixlet binary to path
RUN mv $GOPATH/pixlet/pixlet /usr/local/bin/pixlet
# Build binary
COPY *.go go.mod go.sum /src/
WORKDIR /src
RUN CGO_ENABLED=1 go build -ldflags "-s -w -linkmode=external '-extldflags=-static -lsharpyuv'" -o /tidbyt-assistant ./...

# Clean up build prereqs
RUN apk del -r curl wget git make gcc patchelf libc-dev
RUN rm -r $GOPATH
RUN rm -r /root/go
FROM scratch

CMD [ "webhook", "-hooks", "/hooks.yaml", "-verbose" ]
COPY --from=builder /tidbyt-assistant /tidbyt-assistant
#COPY --from=builder /usr/lib/libwebp*.so* /usr/lib/libsharpyuv.so* /usr/lib/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY display /display

ENTRYPOINT [ "/tidbyt-assistant" ]
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/tidbyt-assistant", "-health", "http://localhost:9000/health" ]
2 changes: 1 addition & 1 deletion TidbytAssistant/build.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
args:
GO_VERSION: "1.23.1"
GO_VERSION: "1.23.2"
2 changes: 1 addition & 1 deletion TidbytAssistant/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "TidbytAssistant"
description: "Add-on with Pixlet application. Allows you to push custom apps to your Tidbyt. Install with integration v1.0.5"
version: "1.0.7"
version: "1.0.9"
slug: "tidbytassistant"
url: "https://github.com/savdagod/ha-addons/tree/main/TidbytAssistant"
init: False
Expand Down
70 changes: 0 additions & 70 deletions TidbytAssistant/hooks.yaml

This file was deleted.

Loading

0 comments on commit 1c1e725

Please sign in to comment.