Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to run as a standalone Docker container #228

Merged
merged 14 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: [TECH7Fox]
github: [TECH7Fox, felipecrs]
143 changes: 45 additions & 98 deletions .github/workflows/builder.yaml
Original file line number Diff line number Diff line change
@@ -1,118 +1,65 @@
name: Builder

env:
BUILD_ARGS: ""
MONITORED_FILES: "build.yaml config.yaml Dockerfile rootfs"
name: ci

on:
push:
branches:
- main
- "main"
tags:
- "v*"
pull_request:
branches:
- main
- develop

jobs:
init:
runs-on: ubuntu-latest
name: Initialize builds
outputs:
changed_addons: ${{ steps.changed_addons.outputs.addons }}
changed: ${{ steps.changed_addons.outputs.changed }}
steps:
- name: Check out the repository
uses: actions/checkout@v3
- "main"

- name: Get changed files
id: changed_files
uses: jitterbit/get-changed-files@v1
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

- name: Find add-on directories
id: addons
uses: home-assistant/actions/helpers/find-addons@master

- 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
jobs:
docker:
runs-on: ubuntu-latest
if: needs.init.outputs.changed == 'true'
name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on
strategy:
fail-fast: false
matrix:
addon: ${{ fromJson(needs.init.outputs.changed_addons) }}
arch: ["aarch64", "amd64", "armhf", "armv7", "i386"]

steps:
- name: Check out repository
- name: Checkout
uses: actions/checkout@v3

- name: Get information
id: info
uses: home-assistant/actions/helpers/info@master
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Get lowercase GitHub username
id: repository_owner
uses: ASzc/change-string-case-action@v5
with:
path: "./${{ matrix.addon }}"

- name: Check if add-on should be built
id: check
run: |
if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then
echo "::set-output name=build_arch::true";
echo "::set-output name=image::$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)";
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "BUILD_ARGS=--version pr-${{ github.event.number }}" >> $GITHUB_ENV;
fi
else
echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build";
echo "::set-output name=build_arch::false";
fi
string: ${{ github.repository_owner }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ steps.repository_owner.outputs.lowercase }}/asterisk-hass-addon
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Login to GitHub Container Registry
- name: Login to DockerHub
if: github.event_name == 'push' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get lowercase GitHub username
id: repository_owner
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository_owner }}

- name: Build ${{ matrix.addon }} add-on
if: steps.check.outputs.build_arch == 'true'
uses: home-assistant/builder@2023.03.0
- name: Build and push
uses: docker/build-push-action@v4
with:
args: |
${{ env.BUILD_ARGS }} \
--${{ matrix.arch }} \
--target /data/${{ matrix.addon }} \
--image "${{ steps.check.outputs.image }}" \
--docker-hub "ghcr.io/${{ steps.repository_owner.outputs.lowercase }}" \
--addon
context: asterisk
platforms: |
linux/amd64
linux/386
linux/arm/v6
linux/arm/v7
linux/arm64
push: ${{ github.event_name == 'push' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 0 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *"

jobs:
find:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/config/*
!/config/.gitkeep

/media/*
!/media/.gitkeep
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
},
"docker.languageserver.formatter.ignoreMultilineInstructions": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
"files.insertFinalNewline": true,
"files.associations": {
"*.json.example": "json"
}
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"label": "Start Home Assistant",
"type": "shell",
"command": "bash supervisor_run",
"command": "sudo -E bash supervisor_run",
"group": {
"kind": "test",
"isDefault": true
Expand Down
32 changes: 32 additions & 0 deletions asterisk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

# Changelog

## 4.0.0

### Breaking Changes

Some default options for the add-on configuration have been switched:

- `generate_ssl_cert` is now enabled by default.
- `video_support` is now disabled by default. It barely worked anyway.

Make sure to check the add-on configuration page after updating the add-on to ensure your configuration is still correct.

### New Features

Now the add-on can be run as a standalone docker container:

```console
docker pull ghcr.io/tech7fox/asterisk-hass-addon:4.0.0
```

- An example `docker-compose.yml` file is available [here](../docker-compose.yaml).
- Make sure to mount a `config` folder to `/config` and a `media` folder to `/media` to ensure the add-on can access your configuration and media files.
- To configure the add-on options you can use the `/config/config.json` file. The default options can be seen [here](./rootfs/usr/share/asterisk/config.json).
- If you enable `auto_add` to automatically create extensions for every Person in your Home Assistant, make sure to also set:
- The `HA_TOKEN` environment variable with your Home Assistant long-lived access token
- The `HA_URL`, unless <https://homeassistant.local:8123> resolves to your Home Assistant instance

Also, you can now use absolute paths in the `certfile` and `keyfile` options.

### Cleanups

The add-on no longer sends discovery information for the Asterisk integration in Home Assistant. This never worked anyway, and if in the future it does, we can restore it.

## 3.2.0

### New Features
Expand Down
34 changes: 20 additions & 14 deletions asterisk/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Follow these steps to get the add-on installed on your system:
1. Scroll down the page to find the new repository, and click in the new add-on named **_Asterisk_**.
1. Click in the **_INSTALL_** button.

Or you can also use it as a standalone docker container. See [4.0.0 release notes](./CHANGELOG.md#400) for more information.

## Using

1. The certificate to your registered domain should already be created via the [Duck DNS](https://github.com/home-assistant/hassio-addons/tree/master/duckdns) or [Let's Encrypt](https://github.com/home-assistant/hassio-addons/tree/master/letsencrypt) add-on or another method. Make sure that the certificate files exist in the `/ssl/` directory.
Expand All @@ -40,17 +42,19 @@ We expose some configuration options to simplify the setup of the Asterisk serve

Set's the password for the Asterisk Manager Interface, to connect to the [Asterisk integration](https://github.com/TECH7Fox/Asterisk-integration).

### Option: `video_support`

Enables video support for the auto generated extensions.

### Option: `auto_add`

Creates a extension for every [person](https://www.home-assistant.io/integrations/person/) registered in Home Assistant. They will have their number and username auto-generated starting from 100, with the `callerid` set to the person's name.

**This is enabled by default for add-on users but disabled by default for container users.**

### Option: `auto_add_secret`

The secret for the auto generated extensions.
The secret for the auto generated extensions, when `auto_add` is enabled.

### Option: `video_support`

Enables video support for the auto generated extensions, when `auto_add` is enabled.

### Option: `additional_sounds`

Expand All @@ -66,15 +70,15 @@ Enables/disables the generation of a self-signed certificate for use with the SS

### Option: `certfile`

The certificate file to use for SSL in your `/ssl/` folder, when `generate_ssl_cert` is disabled.
The certificate file to use for SSL in your `/ssl/` folder, when `generate_ssl_cert` is disabled. If an absolute path is provided, it will be used as-is.

### Option: `keyfile`

The key file to use for SSL in your `/ssl/` folder, when `generate_ssl_cert` is disabled.
The key file to use for SSL in your `/ssl/` folder, when `generate_ssl_cert` is disabled. If an absolute path is provided, it will be used as-is.

### Option: `mailbox_server`
### Option: `mailbox`

Enables the mailbox server to send voicemails to the Asterisk mailbox integration.
Enables the mailbox server to send voicemails to the Asterisk Mailbox integration.

### Option: `mailbox_port`

Expand All @@ -88,9 +92,9 @@ The password for the mailbox server.

Which extension to get the voicemails from.

### Option: `api_key`
### Option: `mailbox_google_api_key`

The API Key for speech-to-text.
The API Key for the speech-to-text used by Asterisk Mailbox.
You can get a key [here](https://cloud.google.com/speech-to-text). Google says it's free, but requires a billing account.

### Option: `log_level`
Expand All @@ -108,16 +112,18 @@ service: hassio.addon_stdin
input: dialplan reload
```
**This is only possible when using as an add-on.**
## Configuring the [Asterisk integration](https://github.com/TECH7Fox/Asterisk-integration)
- **_Host_**: `localhost`
- **_Host_**: `localhost` (when running as an add-on)
- **_Port_**: `5038`
- **_Username_**: `admin`
- **_Password_**: whatever you set in the AMI Password configuration
- **_Password_**: whatever you set in the `ami_password` configuration

## Configuring the [SIP.js card](https://github.com/TECH7Fox/HA-SIP)

- **_Host_**: `localhost`
- **_Host_**: `localhost` (when running as an add-on)
- **_Port_**: `8089`
- **_Video_**: `false` _Video is not working at the moment, this will be fixed soon. For now you could use the camera entity instead._

Expand Down
7 changes: 7 additions & 0 deletions asterisk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,11 @@ ENV S6_SERVICES_READYTIME=50
# Without this, the STDIN script never gets executed
ENV S6_CMD_WAIT_FOR_SERVICES=0

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/stdin.sh" ]

LABEL \
org.opencontainers.image.title="Home Assistant Add-on: Asterisk" \
org.opencontainers.image.description="PBX server for SIP devices like doorbells and phones." \
org.opencontainers.image.source="https://github.com/TECH7Fox/asterisk-hass-addons" \
org.opencontainers.image.licenses="MIT"
15 changes: 5 additions & 10 deletions asterisk/build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
build_from:
aarch64: ghcr.io/hassio-addons/debian-base/aarch64:6.2.3
amd64: ghcr.io/hassio-addons/debian-base/amd64:6.2.3
armhf: ghcr.io/hassio-addons/debian-base/armhf:6.2.3
armv7: ghcr.io/hassio-addons/debian-base/armv7:6.2.3
i386: ghcr.io/hassio-addons/debian-base/i386:6.2.3
labels:
org.opencontainers.image.title: "Home Assistant Add-on: Asterisk"
org.opencontainers.image.description: "PBX server for SIP devices like doorbells and phones."
org.opencontainers.image.source: "https://github.com/TECH7Fox/asterisk-hass-addons"
org.opencontainers.image.licenses: "MIT"
aarch64: ghcr.io/hassio-addons/debian-base:6.2.3
amd64: ghcr.io/hassio-addons/debian-base:6.2.3
armhf: ghcr.io/hassio-addons/debian-base:6.2.3
armv7: ghcr.io/hassio-addons/debian-base:6.2.3
i386: ghcr.io/hassio-addons/debian-base:6.2.3
10 changes: 5 additions & 5 deletions asterisk/config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Asterisk
version: 3.2.0
version: 4.0.0
slug: asterisk
description: PBX server for SIP devices like doorbells and phones
url: https://github.com/TECH7Fox/asterisk-hass-addons
image: "ghcr.io/tech7fox/{arch}-addon-asterisk"
image: ghcr.io/tech7fox/asterisk-hass-addon
arch:
- armhf
- armv7
Expand All @@ -17,10 +17,10 @@ map:
- ssl
options:
ami_password: null
video_support: true
auto_add: true
auto_add_secret: ""
generate_ssl_cert: false
video_support: false
generate_ssl_cert: true
certfile: fullchain.pem
keyfile: privkey.pem
additional_sounds: []
Expand All @@ -32,9 +32,9 @@ options:
log_level: info
schema:
ami_password: password
video_support: bool
auto_add: bool
auto_add_secret: password
video_support: bool
additional_sounds:
- str
generate_ssl_cert: bool
Expand Down
Loading