Skip to content

Commit

Permalink
ci and charts
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-m-song committed Apr 3, 2024
1 parent d139af5 commit 88f4c88
Show file tree
Hide file tree
Showing 16 changed files with 404 additions and 9 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/_publish_chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
workflow_call:
inputs:
publish:
description: Whether or not to publish the chart
type: boolean
outputs:
chart_version:
value: ${{ jobs.publish_chart.outputs.chart_version }}

jobs:
publish_chart:
runs-on:
- self-hosted

outputs:
chart_version: ${{ steps.version.outputs.chart_version }}

steps:
- uses: actions/checkout@v4
with:
show-progress: false

- id: version
run: |
chart_version=$(yq '.version' ./charts/home-assistant-integrations/Chart.yaml)
echo chart_version=$chart_version >> $GITHUB_OUTPUT
- id: package
env:
chart_version: ${{ steps.version.outputs.chart_version }}
run: |
helm package ./charts/home-assistan-integrations
old_filepath=home-assistant-integrations-$chart_version.tgz
new_filepath=home-assistant-integrations.$chart_version.tgz
mv $old_filepath $new_filepath
echo "filepath=$new_filepath" | tee -a $GITHUB_OUTPUT
- uses: OctopusDeploy/login@v1
if: inputs.publish == true
with:
server: ${{ vars.OCTOPUS_DEPLOY_SERVER_URL }}
service_account_id: ${{ vars.OCTOPUS_DEPLOY_EXTERNAL_ID }}

- uses: OctopusDeploy/push-package-action@v3
if: inputs.publish == true
with:
packages: ${{ steps.package.outputs.filepath }}
overwrite_mode: FailIfExists

- uses: OctopusDeploy/push-build-information-action@v3
if: inputs.publish == true
with:
packages: ${{ vars.OCTOPUS_DEPLOY_CHART_PACKAGE_ID }}
version: ${{ steps.version.outputs.chart_version }}
overwrite_mode: FailIfExists
71 changes: 71 additions & 0 deletions .github/workflows/_publish_image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
on:
workflow_call:
inputs:
publish:
description: Whether or not to publish the image
type: boolean
default: false
outputs:
image_tag:
value: ${{ jobs.publish_image.outputs.image_tag }}

env:
IMAGE: public.ecr.aws/axatol/home-assistant-integrations

jobs:
publish_image:
runs-on:
- self-hosted

outputs:
image_tag: ${{ steps.version.outputs.image_tag }}

steps:
- uses: actions/checkout@v4
with:
show-progress: false

- id: version
run: |
image_tag=$(yq '.appVersion' ./charts/home-assistant-integrations/Chart.yaml)
echo image_tag=$image_tag >> $GITHUB_OUTPUT
- env:
image: ${{ env.IMAGE }}
tag: ${{ steps.version.outputs.image_tag }}
run: |
make build-image IMAGE_NAME=$image BUILD_VERSION=$tag
docker tag $image:$tag $image:latest
- if: inputs.publish == true
env:
image: ${{ env.IMAGE }}
tag: ${{ steps.version.outputs.image_tag }}
run: |
docker push $image:$tag
docker push $image:latest
- uses: axatol/actions/assume-aws-role@release
if: inputs.publish == true
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ECR_IMAGE_PUBLISHER_ROLE_ARN }}

- uses: aws-actions/amazon-ecr-login@v2
if: inputs.publish == true
with:
registry-type: public
mask-password: true

- uses: OctopusDeploy/login@v1
if: inputs.publish == true
with:
server: ${{ vars.OCTOPUS_DEPLOY_SERVER_URL }}
service_account_id: ${{ vars.OCTOPUS_DEPLOY_EXTERNAL_ID }}

- uses: OctopusDeploy/push-build-information-action@v3
if: inputs.publish == true
with:
packages: ${{ vars.OCTOPUS_DEPLOY_IMAGE_PACKAGE_ID }}
version: ${{ steps.version.outputs.image_tag }}
overwrite_mode: FailIfExists
47 changes: 47 additions & 0 deletions .github/workflows/_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

on:
workflow_call:
inputs:
chart_version:
description: The version of the chart to release
type: string
required: true
image_tag:
description: The tag of the image to release
type: string
required: true

jobs:
release:
runs-on:
- self-hosted

steps:
- uses: actions/checkout@v4
with:
show-progress: false

- uses: OctopusDeploy/login@v1
with:
server: ${{ vars.OCTOPUS_DEPLOY_SERVER_URL }}
service_account_id: ${{ vars.OCTOPUS_DEPLOY_EXTERNAL_ID}}

- uses: OctopusDeploy/create-release-action@v3
id: release
with:
project: ${{ vars.OCTOPUS_DEPLOY_PROJECT }}
packages: |
*:image:${{ inputs.image_tag }}
*:chart:${{ inputs.chart_version }}
- uses: OctopusDeploy/deploy-release-action@v3
id: deploy
with:
project: ${{ vars.OCTOPUS_DEPLOY_PROJECT }}
environments: Production
release_number: ${{ steps.release.outputs.release_number }}

- uses: OctopusDeploy/await-task-action@v3
with:
server_task_id: ${{ fromJson(steps.deploy.outputs.server_tasks)[0].serverTaskId }}
33 changes: 33 additions & 0 deletions .github/workflows/_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test

on: workflow_call

jobs:
test:
runs-on:
- self-hosted

steps:
- uses: actions/checkout@v4
with:
show-progress: false

- name: Template
run: |
helm template ./charts/home-assistant-integrations \
--set mqttUri tcp://localhost:1883 \
--debug
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: false

- name: Check
run: |
go vet ./...
go test -v ./...
- uses: golangci/golangci-lint-action@v4
with:
skip-cache: true
8 changes: 8 additions & 0 deletions .github/workflows/on_pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
on:
pull_request:
branches:
- v2

jobs:
test:
uses: ./.github/workflows/_test.yaml
30 changes: 30 additions & 0 deletions .github/workflows/on_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
branches:
- v2
paths-ignore:
- "**/*.md"
- "**/*.sh"
- LICENSE

jobs:
publish_image:
uses: ./.github/workflows/_publish_image.yaml
with:
publish: true

publish_chart:
uses: ./.github/workflows/_publish_chart.yaml
with:
publish: true

release:
name: >-
Release
${{ needs.publish_image.outputs.image_tag }}
(${{ needs.publish_chart.outputs.chart_version }})
needs: [publish_image, publish_chart]
uses: ./.github/workflows/_release.yaml
with:
chart_version: ${{ github.sha }}
image_tag: ${{ github.sha }}
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
FROM golang:1.21.5-alpine AS builder
FROM golang:1.22-alpine AS builder
RUN apk add --no-cache make
WORKDIR /go/src/app
COPY . .
RUN go mod download
ENV CGO_ENABLED=0
RUN go build -o /go/bin/app .
ARG BUILD_VERSION
ARG BUILD_TIME
ARG BUILD_COMMIT
RUN make build-binary \
BINARY_NAME=/go/bin/app \
BUILD_VERSION=${BUILD_VERSION} \
BUILD_TIME=${BUILD_TIME} \
BUILD_COMMIT=${BUILD_COMMIT}

FROM gcr.io/distroless/base-debian11
COPY --from=builder /go/bin/app /
CMD ["/app"]
FROM gcr.io/distroless/base-debian12
COPY --from=builder /go/bin/app /bin/app
CMD ["/bin/app"]
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
IMAGE_NAME ?= public.ecr.aws/axatol/home-assistant-integrations:latest
BINARY_NAME ?= home-assistant-integrations
CHART_PATH ?= ./charts/home-assistant-integrations
BUILD_VERSION ?= $(shell git describe --tags --always)
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%M:%S')
BUILD_COMMIT ?= $(shell git rev-parse HEAD)
Expand All @@ -16,11 +18,16 @@ build-binary: clean
build-image: clean
docker build \
--platform=linux/amd64 \
--tag home-assistant-integrations \
--tag $(IMAGE_NAME) \
--build-arg BUILD_COMMIT=$(BUILD_COMMIT) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
--build-arg BUILD_VERSION=$(BUILD_VERSION) \
.

build-chart: clean
helm package $(CHART_PATH)

clean:
rm -f $(BINARY_NAME)
rm -f $(CHART_PATH)/home-assistant-integrations-*.tgz
rm -f home-assistant-integrations-*.tgz
5 changes: 5 additions & 0 deletions charts/home-assistant-integrations/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: home-assistant-integrations
version: 0.0.1
appVersion: 0.0.1
type: application
24 changes: 24 additions & 0 deletions charts/home-assistant-integrations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# home-assistant-integrations

![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.0.1](https://img.shields.io/badge/AppVersion-0.0.1-informational?style=flat-square)

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| image.repository | string | `"public.ecr.aws/axatol/home-assistant-integrations"` | |
| image.tag | string | `""` | image tag, defaults to the chart's appVersion |
| logFormat | string | `"json"` | log format for the application, (e.g. json, text) |
| logLevel | string | `"info"` | log level for the application, (e.g. trace, error) |
| mqttUri | string | `""` | uri of the mqtt broker to publish data to |
| providers.huaweiHg659.address | string | `""` | router address |
| providers.huaweiHg659.enabled | bool | `false` | enable the provider |
| providers.huaweiHg659.entityName | string | `"huawei_hg659"` | id of entity in home assistant |
| providers.huaweiHg659.pollRate | string | `"60s"` | poll rate for the provider |
| providers.zeverSolarTlc5000.address | string | `""` | zever solar inverter address |
| providers.zeverSolarTlc5000.enabled | bool | `false` | enable the provider |
| providers.zeverSolarTlc5000.entityName | string | `""` | id of entity in home assistant |
| providers.zeverSolarTlc5000.pollRate | string | `"30s"` | poll rate for the provider |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.13.1](/~https://github.com/norwoodj/helm-docs/releases/v1.13.1)
17 changes: 17 additions & 0 deletions charts/home-assistant-integrations/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{/*
Common labels
*/}}
{{- define "home-assistant-integrations.labels" -}}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{ include "home-assistant-integrations.selectors" . }}
{{- end }}

{{/*
Common selectors
*/}}
{{- define "home-assistant-integrations.selectors" -}}
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/home-assistant-integrations/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}
labels: {{- include "home-assistant-integrations.labels" . | nindent 4 }}
data:
LOG_LEVEL: {{ .Values.logLevel }}
LOG_FORMAT: {{ .Values.logFormat }}
MQTT_URI: {{ .Values.mqttUri | required ".Values.mqttUri is required" }}

{{- with .Values.providers.huaweiHg659 }}
{{- if .enabled }}
HUAWEI_HG659_ENABLED: true
HUAWEI_HG659_ADDRESS: {{ .address | required ".Values.huaweiHg659.address is required"}}
HUAWEI_HG659_ENTITY_NAME: {{ .entityName }}
HUAWEI_HG659_POLL_RATE: {{ .pollRate }}
{{- end }}
{{- end }}

{{- with .Values.providers.zeverSolarTlc5000 }}
{{- if .enabled }}
ZEVER_SOLAR_TLC5000_ENABLED: true
ZEVER_SOLAR_TLC5000_ADDRESS: {{ .address | required ".Values.zeverSolarTlc5000.address is required" }}
ZEVER_SOLAR_TLC5000_ENTITY_NAME: {{ .entityName }}
ZEVER_SOLAR_TLC5000_POLL_RATE: {{ .pollRate }}
{{- end }}
{{- end }}
Loading

0 comments on commit 88f4c88

Please sign in to comment.