Skip to content
Open
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
153 changes: 153 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: Build and Deploy

on:
push:
tags:
- '*'

env:
APPLICATION_NAME: "hoymiles-dtu"
ARTIFACT_NAME: "hoymiles-dtu"
DOCKER_REGISTRY_URL: "hub.docker.com/sakrut"
DOCKER_REGISTRY_USERNAME: "sakrut"
MAVEN_OPTS: '-DXmx1024m -DXX:MaxPermSize=256m'
MAVEN_CLI_OPTS: "--batch-mode --update-snapshots --errors --fail-at-end"

# Prevent concurrent deployments
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# Extract version once and use it across jobs
extract-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get version
id: get-version
run: echo "version=$(git describe --abbrev=0 --tags 2>/dev/null || echo '0.1.0')" >> $GITHUB_OUTPUT

build-artifact:
needs: extract-version
runs-on: ubuntu-latest
container:
image: maven:3.8.3-eclipse-temurin-11
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Maven cache
uses: actions/cache@v3
with:
path: /projects-cache/.m2/
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build with Maven
run: mvn clean compile assembly:single ${MAVEN_CLI_OPTS}

- name: Prepare artifacts
run: |
mkdir -p artifacts
cp target/hoymiles-dtu-1.0-SNAPSHOT-jar-with-dependencies.jar artifacts/${ARTIFACT_NAME}-${{ needs.extract-version.outputs.version }}.jar -v || exit $?

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: artifacts
retention-days: 7

# Single job for all Docker architectures
build-docker-images:
name: Build Docker Images
needs: [extract-version, build-artifact]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- arch: "armv7"
platform: "linux/armv7"
from: "adoptopenjdk/openjdk11:armv7l-ubuntu-jdk-11.0.15_10-slim"
tag: "sakrut/hoymiles-dtu-armv7"
- arch: "amd64"
platform: "linux/amd64"
from: "adoptopenjdk/openjdk11:x86_64-ubuntu-jdk-11.0.15_10-slim"
tag: "sakrut/hoymiles-dtu-amd64"
- arch: "aarch64"
platform: "linux/aarch64"
from: "adoptopenjdk/openjdk11:aarch64-ubuntu-jdk-11.0.15_10-slim"
tag: "sakrut/hoymiles-dtu-aarch64"

environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: artifacts

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.HUBDOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: |
${{ matrix.tag }}:latest
${{ matrix.tag }}:${{ needs.extract-version.outputs.version }}
build-args: |
JAR_FILE=artifacts/${{ env.APPLICATION_NAME }}-${{ needs.extract-version.outputs.version }}.jar
BUILD_FROM=${{ matrix.from }}
BUILD_ARCH=${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Enable BuildKit
provenance: false
buildkitd-flags: --debug

# Summary job
summary:
needs: [extract-version, build-docker-images]
runs-on: ubuntu-latest
steps:
- name: Generate summary
run: |
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
echo "* **Version:** ${{ needs.extract-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "* **Docker Tags:**" >> $GITHUB_STEP_SUMMARY
echo " * sakrut/hoymiles-dtu-armv7:${{ needs.extract-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo " * sakrut/hoymiles-dtu-armv7:latest" >> $GITHUB_STEP_SUMMARY
echo " * sakrut/hoymiles-dtu-amd64:${{ needs.extract-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo " * sakrut/hoymiles-dtu-amd64:latest" >> $GITHUB_STEP_SUMMARY
echo " * sakrut/hoymiles-dtu-aarch64:${{ needs.extract-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo " * sakrut/hoymiles-dtu-aarch64:latest" >> $GITHUB_STEP_SUMMARY
echo "* **Workflow Run:** [Link](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ target/
.idea/
hoymiles_solar-*
src/main/resources/application.json
sniffer/node_modules/
sniffer/node_modules/
.vs/
.vscode/
17 changes: 9 additions & 8 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
variables:
APPLICATION_NAME: "hoymiles-dtu"
ARTIFACT_NAME: "hoymiles-dtu"
DOCKER_REGISTRY_URL: "hub.docker.com/banny310"
DOCKER_REGISTRY_USERNAME: "banny310"
DOCKER_REGISTRY_URL: "hub.docker.com/sakrut"
DOCKER_REGISTRY_USERNAME: "sakrut"
MAVEN_LOCAL_REPO: "/projects-cache/.m2/"
MAVEN_OPTS: '-DXmx1024m -DXX:MaxPermSize=256m'
MAVEN_CLI_OPTS: "--batch-mode --update-snapshots --errors --fail-at-end"
Expand All @@ -30,16 +30,17 @@ build-artifact:
# - tags

.build-docker-template:
image: docker:20.10.12
image: docker:git
stage: deploy
dependencies:
- build-artifact
before_script:
- apk update && apk add git
- BUILD_VERSION=`git describe --abbrev=0 --tags 2>/dev/null || echo "0.1.0"`
- DOCKER_BUILDKIT=1
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
script:
- docker build --build-arg JAR_FILE=artifacts/${APPLICATION_NAME}-${BUILD_VERSION}.jar --build-arg BUILD_FROM=${BUILD_FROM} --build-arg BUILD_ARCH=${BUILD_ARCH} --platform ${DOCKER_PLATFORM} --tag ${DOCKER_TAG}:latest --tag ${DOCKER_TAG}:${BUILD_VERSION} --file docker/Dockerfile .
- docker login -u ${DOCKER_REGISTRY_USERNAME} -p ${HUBDOCKER_PASSWORD}
- docker build --platform ${DOCKER_PLATFORM} --build-arg JAR_FILE=artifacts/${APPLICATION_NAME}-${BUILD_VERSION}.jar --build-arg BUILD_FROM=${BUILD_FROM} --build-arg BUILD_ARCH=${BUILD_ARCH} --tag ${DOCKER_TAG}:latest --tag ${DOCKER_TAG}:${BUILD_VERSION} --file docker/Dockerfile .
- docker push ${DOCKER_TAG}:${BUILD_VERSION}
- docker push ${DOCKER_TAG}:latest
tags:
Expand All @@ -54,20 +55,20 @@ build-docker-armv7:
BUILD_ARCH: "armv7"
BUILD_FROM: "adoptopenjdk/openjdk11:armv7l-ubuntu-jdk-11.0.15_10-slim"
DOCKER_PLATFORM: "linux/armv7"
DOCKER_TAG: "banny310/hoymiles-dtu-armv7"
DOCKER_TAG: "sakrut/hoymiles-dtu-armv7"

build-docker-amd64:
extends: .build-docker-template
variables:
BUILD_ARCH: "amd64"
BUILD_FROM: "adoptopenjdk/openjdk11:x86_64-ubuntu-jdk-11.0.15_10-slim"
DOCKER_PLATFORM: "linux/amd64"
DOCKER_TAG: "banny310/hoymiles-dtu-amd64"
DOCKER_TAG: "sakrut/hoymiles-dtu-amd64"

build-docker-aarch64:
extends: .build-docker-template
variables:
BUILD_ARCH: "aarch64"
BUILD_FROM: "adoptopenjdk/openjdk11:aarch64-ubuntu-jdk-11.0.15_10-slim"
DOCKER_PLATFORM: "linux/aarch64"
DOCKER_TAG: "banny310/hoymiles-dtu-aarch64"
DOCKER_TAG: "sakrut/hoymiles-dtu-aarch64"
Binary file added protoc.exe
Binary file not shown.
7 changes: 6 additions & 1 deletion src/main/java/com/hoymiles/application/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class AppController {
private AppInfo appInfo;
private boolean pvAutodiscoverySent = false;
private Disposable poolDisposable;
private int acceptedDataUpToMin = 5;

@Handler
public Void handleMqttConnected(@Observes @Priority(1) @NotNull MqttConnectedEvent event) {
Expand All @@ -72,7 +73,7 @@ public Void handleSolarData(@Observes @Priority(1) @NotNull RealDataEvent comman
RealData data = command.getRealData();
log.info("Incoming new metrics: time={}", data.getTime());
// make sure metrics are not older than 5 minutes
if (!LocalDateTime.now().minusMinutes(5).isBefore(data.getTime())) {
if (!LocalDateTime.now().minusMinutes(acceptedDataUpToMin).isBefore(data.getTime())) {
long minutes = ChronoUnit.MINUTES.between(data.getTime(), LocalDateTime.now());
log.warn("Metrics are {} minutes old. Discarding.", minutes);
return null;
Expand Down Expand Up @@ -100,6 +101,10 @@ public void start() {

log.info("Sending autodiscovery...");
autodiscoveryService.registerHomeAssistantAutodiscovery(appInfo);
if( !config.getIsNull("dtu.accepted_data_up_to_min"))
{
acceptedDataUpToMin = config.getInt("dtu.accepted_data_up_to_min");
}

AppMode mode = AppMode.valueOf(config.getString("app.mode").toUpperCase());
switch (mode) {
Expand Down
Loading