From 068aae82c340fab5c1391f4a221f2fc5b2dfde7b Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 23 Jun 2023 13:43:03 +0200
Subject: [PATCH 01/26] Fix NaN*10^(-9223372036854775808) glitch
---
src/tools/tools.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/tools/tools.go b/src/tools/tools.go
index 47ab613..9d819c1 100644
--- a/src/tools/tools.go
+++ b/src/tools/tools.go
@@ -18,7 +18,7 @@ func TemplateDivide(num1, num2 float32) template.HTML {
division := float64(num1 / num2)
powerOfTen := int(math.Floor(math.Log10(division)))
- if powerOfTen >= -2 && powerOfTen <= 2 {
+ if (powerOfTen >= -2 && powerOfTen <= 2) || division == 0 {
// #nosec G203 // We're only printing floats
return template.HTML(strconv.FormatFloat(math.Round(division*100)/100, 'f', -1, 64))
}
From d51f42ecb1d2d847187acb0703f71d7cb5252c32 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 23 Jun 2023 16:51:43 +0200
Subject: [PATCH 02/26] Fix linter
---
.golangci.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.golangci.yml b/.golangci.yml
index c128eff..1bd5888 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -234,6 +234,8 @@ linters:
- wrapcheck
- nonamedreturns
- gomnd
+ - gosmopolitan
+ - depguard
enable-all: true
fast: false
From b720bf4ac06edabfe1453026281f57f055d615fb Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 23 Jun 2023 20:39:37 +0200
Subject: [PATCH 03/26] Squash bugs
---
src/ecodash/database.go | 2 +-
src/ecodash/http.go | 2 +-
src/tools/tools.go | 6 +++++-
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/ecodash/database.go b/src/ecodash/database.go
index 0c44e35..f580b15 100644
--- a/src/ecodash/database.go
+++ b/src/ecodash/database.go
@@ -75,7 +75,7 @@ func (config *Config) refreshCacheFromPast(pastTime time.Time) error {
}
defer stmtIgnore.Close()
- for key, day := range greenEnergyPercentage {
+ for key, day := range historyPolledSmartEnergySummation {
var stmt *sql.Stmt
if greenEnergyPercentage[key].Value != 0 && historyPolledSmartEnergySummation[key].Value != 0 {
stmt = stmtReplace
diff --git a/src/ecodash/http.go b/src/ecodash/http.go
index 7c32f2a..7fbd1b3 100644
--- a/src/ecodash/http.go
+++ b/src/ecodash/http.go
@@ -155,7 +155,7 @@ func (config *Config) saveAdminForm(c *fiber.Ctx) error {
}
func averageExcludingCurrentDay(data []float32) float32 {
- if len(data) == 0 {
+ if len(data) <= 1 {
return 0
}
data = data[:len(data)-1]
diff --git a/src/tools/tools.go b/src/tools/tools.go
index 9d819c1..3bac1b1 100644
--- a/src/tools/tools.go
+++ b/src/tools/tools.go
@@ -17,8 +17,12 @@ func Hash(toHash string) string {
func TemplateDivide(num1, num2 float32) template.HTML {
division := float64(num1 / num2)
+ if math.IsNaN(division) || division == 0 {
+ return "0"
+ }
+
powerOfTen := int(math.Floor(math.Log10(division)))
- if (powerOfTen >= -2 && powerOfTen <= 2) || division == 0 {
+ if powerOfTen >= -2 && powerOfTen <= 2 {
// #nosec G203 // We're only printing floats
return template.HTML(strconv.FormatFloat(math.Round(division*100)/100, 'f', -1, 64))
}
From 002fab4786ed4bccd9ed1df1a1f725b383a41a2b Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 24 Jun 2023 09:00:20 +0200
Subject: [PATCH 04/26] Optimize CI
---
.woodpecker.yml | 45 --------------------
.woodpecker/Dockerfile-woodpecker | 11 +++++
.woodpecker/setup.sh | 19 +++++++++
.woodpecker/woodpecker.yml | 69 +++++++++++++++++++++++++++++++
4 files changed, 99 insertions(+), 45 deletions(-)
delete mode 100644 .woodpecker.yml
create mode 100644 .woodpecker/Dockerfile-woodpecker
create mode 100644 .woodpecker/setup.sh
create mode 100644 .woodpecker/woodpecker.yml
diff --git a/.woodpecker.yml b/.woodpecker.yml
deleted file mode 100644
index d431220..0000000
--- a/.woodpecker.yml
+++ /dev/null
@@ -1,45 +0,0 @@
-pipeline:
-
- docker:
- image: woodpeckerci/plugin-docker-buildx
- settings:
- registry: git.massivebox.net
- repo: git.massivebox.net/ecodash/ecodash
- platforms: linux/amd64,linux/arm64
- auto_tag: true
- username: massivebox
- password:
- from_secret: auth_token
- when:
- event: tag
-
- build:
- image: golang
- commands:
- - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- - go mod tidy
- - golangci-lint run
- - go build -o ecodash-x86 src/main/main.go
- - env GOOS=linux GOARCH=arm go build -o ecodash-arm src/main/main.go
-
- prepare-gitea-release:
- image: alpine
- commands:
- - apk update; apk add zip
- - mv ecodash-x86 ecodash; zip -r ecodash-x86.zip templates ecodash
- - mv ecodash-arm ecodash; zip -r ecodash-arm.zip templates ecodash
- when:
- event: tag
-
- gitea-publish:
- image: plugins/gitea-release
- settings:
- base_url: https://git.massivebox.net
- files:
- - ecodash-x86.zip
- - ecodash-arm.zip
- api_key:
- from_secret: auth_token
- title: ${CI_COMMIT_TAG}
- when:
- event: tag
diff --git a/.woodpecker/Dockerfile-woodpecker b/.woodpecker/Dockerfile-woodpecker
new file mode 100644
index 0000000..773f0f3
--- /dev/null
+++ b/.woodpecker/Dockerfile-woodpecker
@@ -0,0 +1,11 @@
+FROM debian:latest
+
+WORKDIR /app
+COPY ./setup.sh ./setup.sh
+
+RUN apt-get update; apt-get upgrade -y; apt-get install zip curl -y && \
+ curl https://cloud.massivebox.net/api/public/dl/fLgOAQNc -o templates.zip && unzip templates.zip && rm templates.zip && \
+ chmod +x setup.sh && ./setup.sh && rm setup.sh && \
+ chmod +x app
+
+CMD ["./app"]
\ No newline at end of file
diff --git a/.woodpecker/setup.sh b/.woodpecker/setup.sh
new file mode 100644
index 0000000..f9d0741
--- /dev/null
+++ b/.woodpecker/setup.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+ARCH=$(arch)
+
+# This is a workaround to Woodpecker's inability to give files it has just built to Docker BuildX to build new images.
+# After compiling the binaries in the "build-and-format" step of woodpecker.yml, we upload them to the cloud and fetch them from here.
+
+if [ "$ARCH" = "x86_64" ]; then
+ echo "detected amd64"
+ curl https://cloud.massivebox.net/api/public/dl/uZaDQXAa -o app
+elif [ "$ARCH" = "aarch64" ]; then
+ echo "deteched arm"
+ curl https://cloud.massivebox.net/api/public/dl/EhM62nhf -o app
+else
+ echo "unsupported architecture"
+ return 1
+fi
+
+return 0
\ No newline at end of file
diff --git a/.woodpecker/woodpecker.yml b/.woodpecker/woodpecker.yml
new file mode 100644
index 0000000..7a670bb
--- /dev/null
+++ b/.woodpecker/woodpecker.yml
@@ -0,0 +1,69 @@
+pipeline:
+
+ build-and-format:
+ image: golang
+ commands:
+ - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
+ - go mod tidy
+ - golangci-lint run
+ - env GOOS=linux GOARCH=amd64 go build -o ecodash-x86 src/main/main.go
+ - env GOOS=linux GOARCH=arm go build -o ecodash-arm src/main/main.go
+ - apt-get update; apt-get upgrade -y; apt-get install zip -y
+ - mv ecodash-x86 ecodash; zip -r ecodash-x86.zip templates ecodash; mv ecodash ecodash-x86
+ - mv ecodash-arm ecodash; zip -r ecodash-arm.zip templates ecodash; mv ecodash ecodash-arm
+ - zip templates.zip -r templates
+
+ upload-debug:
+ image: vividboarder/drone-webdav
+ settings:
+ file: { ecodash-x86,ecodash-arm,templates.zip }
+ destination:
+ from_secret: webdav_destination
+ username:
+ from_secret: webdav_username
+ password:
+ from_secret: webdav_password
+ attempts: 5
+
+ gitea-publish:
+ image: plugins/gitea-release
+ settings:
+ base_url: https://git.massivebox.net
+ files:
+ - ecodash-x86.zip
+ - ecodash-arm.zip
+ api_key:
+ from_secret: auth_token
+ title: ${CI_COMMIT_TAG}
+ when:
+ event: tag
+
+ docker-unstable:
+ image: woodpeckerci/plugin-docker-buildx
+ settings:
+ registry: git.massivebox.net
+ repo: git.massivebox.net/ecodash/ecodash
+ platforms: linux/amd64,linux/arm64
+ tag: unstable
+ username: massivebox
+ password:
+ from_secret: auth_token
+ context: .woodpecker
+ dockerfile: .woodpecker/Dockerfile-woodpecker
+ when:
+ event: [ push, pull_request, deployment ]
+
+ docker-tag:
+ image: woodpeckerci/plugin-docker-buildx
+ settings:
+ registry: git.massivebox.net
+ repo: git.massivebox.net/ecodash/ecodash
+ platforms: linux/amd64,linux/arm64
+ auto_tag: true
+ username: massivebox
+ password:
+ from_secret: auth_token
+ context: .woodpecker
+ dockerfile: .woodpecker/Dockerfile-woodpecker
+ when:
+ event: tag
From 82114b8c76a7123a1ab4b1e01ec4689256c82d20 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 24 Jun 2023 09:00:20 +0200
Subject: [PATCH 05/26] Optimize CI
---
.woodpecker.yml | 45 --------------------
.woodpecker/.woodpecker.yml | 69 +++++++++++++++++++++++++++++++
.woodpecker/Dockerfile-woodpecker | 11 +++++
.woodpecker/setup.sh | 19 +++++++++
4 files changed, 99 insertions(+), 45 deletions(-)
delete mode 100644 .woodpecker.yml
create mode 100644 .woodpecker/.woodpecker.yml
create mode 100644 .woodpecker/Dockerfile-woodpecker
create mode 100644 .woodpecker/setup.sh
diff --git a/.woodpecker.yml b/.woodpecker.yml
deleted file mode 100644
index d431220..0000000
--- a/.woodpecker.yml
+++ /dev/null
@@ -1,45 +0,0 @@
-pipeline:
-
- docker:
- image: woodpeckerci/plugin-docker-buildx
- settings:
- registry: git.massivebox.net
- repo: git.massivebox.net/ecodash/ecodash
- platforms: linux/amd64,linux/arm64
- auto_tag: true
- username: massivebox
- password:
- from_secret: auth_token
- when:
- event: tag
-
- build:
- image: golang
- commands:
- - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- - go mod tidy
- - golangci-lint run
- - go build -o ecodash-x86 src/main/main.go
- - env GOOS=linux GOARCH=arm go build -o ecodash-arm src/main/main.go
-
- prepare-gitea-release:
- image: alpine
- commands:
- - apk update; apk add zip
- - mv ecodash-x86 ecodash; zip -r ecodash-x86.zip templates ecodash
- - mv ecodash-arm ecodash; zip -r ecodash-arm.zip templates ecodash
- when:
- event: tag
-
- gitea-publish:
- image: plugins/gitea-release
- settings:
- base_url: https://git.massivebox.net
- files:
- - ecodash-x86.zip
- - ecodash-arm.zip
- api_key:
- from_secret: auth_token
- title: ${CI_COMMIT_TAG}
- when:
- event: tag
diff --git a/.woodpecker/.woodpecker.yml b/.woodpecker/.woodpecker.yml
new file mode 100644
index 0000000..7a670bb
--- /dev/null
+++ b/.woodpecker/.woodpecker.yml
@@ -0,0 +1,69 @@
+pipeline:
+
+ build-and-format:
+ image: golang
+ commands:
+ - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
+ - go mod tidy
+ - golangci-lint run
+ - env GOOS=linux GOARCH=amd64 go build -o ecodash-x86 src/main/main.go
+ - env GOOS=linux GOARCH=arm go build -o ecodash-arm src/main/main.go
+ - apt-get update; apt-get upgrade -y; apt-get install zip -y
+ - mv ecodash-x86 ecodash; zip -r ecodash-x86.zip templates ecodash; mv ecodash ecodash-x86
+ - mv ecodash-arm ecodash; zip -r ecodash-arm.zip templates ecodash; mv ecodash ecodash-arm
+ - zip templates.zip -r templates
+
+ upload-debug:
+ image: vividboarder/drone-webdav
+ settings:
+ file: { ecodash-x86,ecodash-arm,templates.zip }
+ destination:
+ from_secret: webdav_destination
+ username:
+ from_secret: webdav_username
+ password:
+ from_secret: webdav_password
+ attempts: 5
+
+ gitea-publish:
+ image: plugins/gitea-release
+ settings:
+ base_url: https://git.massivebox.net
+ files:
+ - ecodash-x86.zip
+ - ecodash-arm.zip
+ api_key:
+ from_secret: auth_token
+ title: ${CI_COMMIT_TAG}
+ when:
+ event: tag
+
+ docker-unstable:
+ image: woodpeckerci/plugin-docker-buildx
+ settings:
+ registry: git.massivebox.net
+ repo: git.massivebox.net/ecodash/ecodash
+ platforms: linux/amd64,linux/arm64
+ tag: unstable
+ username: massivebox
+ password:
+ from_secret: auth_token
+ context: .woodpecker
+ dockerfile: .woodpecker/Dockerfile-woodpecker
+ when:
+ event: [ push, pull_request, deployment ]
+
+ docker-tag:
+ image: woodpeckerci/plugin-docker-buildx
+ settings:
+ registry: git.massivebox.net
+ repo: git.massivebox.net/ecodash/ecodash
+ platforms: linux/amd64,linux/arm64
+ auto_tag: true
+ username: massivebox
+ password:
+ from_secret: auth_token
+ context: .woodpecker
+ dockerfile: .woodpecker/Dockerfile-woodpecker
+ when:
+ event: tag
diff --git a/.woodpecker/Dockerfile-woodpecker b/.woodpecker/Dockerfile-woodpecker
new file mode 100644
index 0000000..773f0f3
--- /dev/null
+++ b/.woodpecker/Dockerfile-woodpecker
@@ -0,0 +1,11 @@
+FROM debian:latest
+
+WORKDIR /app
+COPY ./setup.sh ./setup.sh
+
+RUN apt-get update; apt-get upgrade -y; apt-get install zip curl -y && \
+ curl https://cloud.massivebox.net/api/public/dl/fLgOAQNc -o templates.zip && unzip templates.zip && rm templates.zip && \
+ chmod +x setup.sh && ./setup.sh && rm setup.sh && \
+ chmod +x app
+
+CMD ["./app"]
\ No newline at end of file
diff --git a/.woodpecker/setup.sh b/.woodpecker/setup.sh
new file mode 100644
index 0000000..f9d0741
--- /dev/null
+++ b/.woodpecker/setup.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+ARCH=$(arch)
+
+# This is a workaround to Woodpecker's inability to give files it has just built to Docker BuildX to build new images.
+# After compiling the binaries in the "build-and-format" step of woodpecker.yml, we upload them to the cloud and fetch them from here.
+
+if [ "$ARCH" = "x86_64" ]; then
+ echo "detected amd64"
+ curl https://cloud.massivebox.net/api/public/dl/uZaDQXAa -o app
+elif [ "$ARCH" = "aarch64" ]; then
+ echo "deteched arm"
+ curl https://cloud.massivebox.net/api/public/dl/EhM62nhf -o app
+else
+ echo "unsupported architecture"
+ return 1
+fi
+
+return 0
\ No newline at end of file
From 33f09c93bd26bd2e93ca419990a03733ea32873d Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 21 Jul 2023 09:43:36 +0200
Subject: [PATCH 06/26] Attempt at adding Jenkins CI
---
.woodpecker/.woodpecker.yml | 69 ---------------------------
.woodpecker/Dockerfile-woodpecker | 11 -----
.woodpecker/setup.sh | 19 --------
.woodpecker/woodpecker.yml | 69 ---------------------------
Jenkinsfile | 77 +++++++++++++++++++++++++++++++
jenkins/Dockerfile | 0
jenkins/Jenkinsfile | 76 ++++++++++++++++++++++++++++++
7 files changed, 153 insertions(+), 168 deletions(-)
delete mode 100644 .woodpecker/.woodpecker.yml
delete mode 100644 .woodpecker/Dockerfile-woodpecker
delete mode 100644 .woodpecker/setup.sh
delete mode 100644 .woodpecker/woodpecker.yml
create mode 100644 Jenkinsfile
create mode 100644 jenkins/Dockerfile
create mode 100644 jenkins/Jenkinsfile
diff --git a/.woodpecker/.woodpecker.yml b/.woodpecker/.woodpecker.yml
deleted file mode 100644
index 7a670bb..0000000
--- a/.woodpecker/.woodpecker.yml
+++ /dev/null
@@ -1,69 +0,0 @@
-pipeline:
-
- build-and-format:
- image: golang
- commands:
- - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- - go mod tidy
- - golangci-lint run
- - env GOOS=linux GOARCH=amd64 go build -o ecodash-x86 src/main/main.go
- - env GOOS=linux GOARCH=arm go build -o ecodash-arm src/main/main.go
- - apt-get update; apt-get upgrade -y; apt-get install zip -y
- - mv ecodash-x86 ecodash; zip -r ecodash-x86.zip templates ecodash; mv ecodash ecodash-x86
- - mv ecodash-arm ecodash; zip -r ecodash-arm.zip templates ecodash; mv ecodash ecodash-arm
- - zip templates.zip -r templates
-
- upload-debug:
- image: vividboarder/drone-webdav
- settings:
- file: { ecodash-x86,ecodash-arm,templates.zip }
- destination:
- from_secret: webdav_destination
- username:
- from_secret: webdav_username
- password:
- from_secret: webdav_password
- attempts: 5
-
- gitea-publish:
- image: plugins/gitea-release
- settings:
- base_url: https://git.massivebox.net
- files:
- - ecodash-x86.zip
- - ecodash-arm.zip
- api_key:
- from_secret: auth_token
- title: ${CI_COMMIT_TAG}
- when:
- event: tag
-
- docker-unstable:
- image: woodpeckerci/plugin-docker-buildx
- settings:
- registry: git.massivebox.net
- repo: git.massivebox.net/ecodash/ecodash
- platforms: linux/amd64,linux/arm64
- tag: unstable
- username: massivebox
- password:
- from_secret: auth_token
- context: .woodpecker
- dockerfile: .woodpecker/Dockerfile-woodpecker
- when:
- event: [ push, pull_request, deployment ]
-
- docker-tag:
- image: woodpeckerci/plugin-docker-buildx
- settings:
- registry: git.massivebox.net
- repo: git.massivebox.net/ecodash/ecodash
- platforms: linux/amd64,linux/arm64
- auto_tag: true
- username: massivebox
- password:
- from_secret: auth_token
- context: .woodpecker
- dockerfile: .woodpecker/Dockerfile-woodpecker
- when:
- event: tag
diff --git a/.woodpecker/Dockerfile-woodpecker b/.woodpecker/Dockerfile-woodpecker
deleted file mode 100644
index 773f0f3..0000000
--- a/.woodpecker/Dockerfile-woodpecker
+++ /dev/null
@@ -1,11 +0,0 @@
-FROM debian:latest
-
-WORKDIR /app
-COPY ./setup.sh ./setup.sh
-
-RUN apt-get update; apt-get upgrade -y; apt-get install zip curl -y && \
- curl https://cloud.massivebox.net/api/public/dl/fLgOAQNc -o templates.zip && unzip templates.zip && rm templates.zip && \
- chmod +x setup.sh && ./setup.sh && rm setup.sh && \
- chmod +x app
-
-CMD ["./app"]
\ No newline at end of file
diff --git a/.woodpecker/setup.sh b/.woodpecker/setup.sh
deleted file mode 100644
index f9d0741..0000000
--- a/.woodpecker/setup.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh
-
-ARCH=$(arch)
-
-# This is a workaround to Woodpecker's inability to give files it has just built to Docker BuildX to build new images.
-# After compiling the binaries in the "build-and-format" step of woodpecker.yml, we upload them to the cloud and fetch them from here.
-
-if [ "$ARCH" = "x86_64" ]; then
- echo "detected amd64"
- curl https://cloud.massivebox.net/api/public/dl/uZaDQXAa -o app
-elif [ "$ARCH" = "aarch64" ]; then
- echo "deteched arm"
- curl https://cloud.massivebox.net/api/public/dl/EhM62nhf -o app
-else
- echo "unsupported architecture"
- return 1
-fi
-
-return 0
\ No newline at end of file
diff --git a/.woodpecker/woodpecker.yml b/.woodpecker/woodpecker.yml
deleted file mode 100644
index 7a670bb..0000000
--- a/.woodpecker/woodpecker.yml
+++ /dev/null
@@ -1,69 +0,0 @@
-pipeline:
-
- build-and-format:
- image: golang
- commands:
- - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- - go mod tidy
- - golangci-lint run
- - env GOOS=linux GOARCH=amd64 go build -o ecodash-x86 src/main/main.go
- - env GOOS=linux GOARCH=arm go build -o ecodash-arm src/main/main.go
- - apt-get update; apt-get upgrade -y; apt-get install zip -y
- - mv ecodash-x86 ecodash; zip -r ecodash-x86.zip templates ecodash; mv ecodash ecodash-x86
- - mv ecodash-arm ecodash; zip -r ecodash-arm.zip templates ecodash; mv ecodash ecodash-arm
- - zip templates.zip -r templates
-
- upload-debug:
- image: vividboarder/drone-webdav
- settings:
- file: { ecodash-x86,ecodash-arm,templates.zip }
- destination:
- from_secret: webdav_destination
- username:
- from_secret: webdav_username
- password:
- from_secret: webdav_password
- attempts: 5
-
- gitea-publish:
- image: plugins/gitea-release
- settings:
- base_url: https://git.massivebox.net
- files:
- - ecodash-x86.zip
- - ecodash-arm.zip
- api_key:
- from_secret: auth_token
- title: ${CI_COMMIT_TAG}
- when:
- event: tag
-
- docker-unstable:
- image: woodpeckerci/plugin-docker-buildx
- settings:
- registry: git.massivebox.net
- repo: git.massivebox.net/ecodash/ecodash
- platforms: linux/amd64,linux/arm64
- tag: unstable
- username: massivebox
- password:
- from_secret: auth_token
- context: .woodpecker
- dockerfile: .woodpecker/Dockerfile-woodpecker
- when:
- event: [ push, pull_request, deployment ]
-
- docker-tag:
- image: woodpeckerci/plugin-docker-buildx
- settings:
- registry: git.massivebox.net
- repo: git.massivebox.net/ecodash/ecodash
- platforms: linux/amd64,linux/arm64
- auto_tag: true
- username: massivebox
- password:
- from_secret: auth_token
- context: .woodpecker
- dockerfile: .woodpecker/Dockerfile-woodpecker
- when:
- event: tag
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..5d19417
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,77 @@
+pipeline {
+
+ agent any
+
+ environment {
+ USER='placeholder'
+ PASSWORD='placeholder'
+ DOCKER_REGISTRY='git.massivebox.net'
+ BUILDER_NAME='mbuilder'
+ SERVICE='ecodash/ecodash'
+ TAG='latest'
+ }
+
+ stages {
+
+ stage('Run linter and build') {
+ agent { docker { image 'golang' } }
+ steps {
+ git url: 'https://git.massivebox.net/ecodash/ecodash'
+ sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
+ sh 'go mod tidy'
+ sh 'golangci-lint run'
+ sh 'env GOOS=linux GOARCH=amd64 go build -o app src/main/main.go'
+ stash includes: 'app', name: 'ecodash-x86'
+ sh 'env GOOS=linux GOARCH=arm go build -o app src/main/main.go'
+ stash includes: 'app', name: 'ecodash-arm'
+ stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
+ stash includes: 'templates/**', name: 'templates'
+ }
+ }
+
+
+ stage('Build x86 container') {
+ steps {
+ unstash 'dockerfile'
+ unstash 'ecodash-x86'
+ unstash 'templates'
+ sh 'docker build -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
+ }
+ }
+
+ stage('Prepare buildx') {
+ steps {
+ sh """
+ docker run --privileged --rm tonistiigi/binfmt --install all
+
+ docker context create $BUILDER_NAME
+ docker context use $BUILDER_NAME
+ docker buildx create $BUILDER_NAME
+ docker buildx use $BUILDER_NAME
+ docker buildx inspect --bootstrap
+ """
+ }
+ }
+
+ stage('Build arm container') {
+ steps {
+ unstash 'dockerfile'
+ unstash 'ecodash-arm'
+ unstash 'templates'
+ sh 'docker buildx build --platform linux/arm64 -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
+ }
+ }
+
+ }
+
+ post {
+ always {
+ // cleanup
+ sh """
+ docker context rm -f $BUILDER_NAME
+ docker buildx use default
+ """
+ }
+ }
+
+}
diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile
new file mode 100644
index 0000000..e69de29
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
new file mode 100644
index 0000000..c7d6982
--- /dev/null
+++ b/jenkins/Jenkinsfile
@@ -0,0 +1,76 @@
+pipeline {
+
+ agent any
+
+ environment {
+ USER='user'
+ PASSWORD='password'
+ DOCKER_REGISTRY='git.massivebox.net'
+ BUILDER_NAME='mbuilder'
+ SERVICE='ecodash/ecodash'
+ TAG='latest'
+ }
+
+ stages {
+
+ stage('Run linter and build') {
+ agent { docker { image 'golang' } }
+ steps {
+ git url: 'https://git.massivebox.net/ecodash/ecodash'
+ //sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
+ sh 'go mod tidy'
+ //sh 'golangci-lint run'
+ sh 'env GOOS=linux GOARCH=amd64 go build -o app src/main/main.go'
+ stash includes: 'app', name: 'ecodash-x86'
+ sh 'env GOOS=linux GOARCH=arm go build -o app src/main/main.go'
+ stash includes: 'app', name: 'ecodash-arm'
+ stash includes: 'templates/**', name: 'templates'
+ }
+ }
+
+
+ stage('Build x86 container') {
+ steps {
+ sh 'curl -L -o Dockerfile https://pasty.nikko.cf/UYU39i/raw'
+ unstash 'ecodash-x86'
+ unstash 'templates'
+ sh 'docker build -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
+ }
+ }
+
+ stage('Prepare buildx') {
+ steps {
+ sh """
+ docker run --privileged --rm tonistiigi/binfmt --install all
+
+ docker context create $BUILDER_NAME
+ docker context use $BUILDER_NAME
+ docker buildx create $BUILDER_NAME
+ docker buildx use $BUILDER_NAME
+ docker buildx inspect --bootstrap
+ """
+ }
+ }
+
+ stage('Build arm container') {
+ steps {
+ sh 'curl -L -o Dockerfile https://pasty.nikko.cf/UYU39i/raw'
+ unstash 'ecodash-arm'
+ unstash 'templates'
+ sh 'docker buildx build --platform linux/arm64 -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
+ }
+ }
+
+ }
+
+ post {
+ always {
+ // cleanup
+ sh """
+ docker context rm -f $BUILDER_NAME
+ docker buildx use default
+ """
+ }
+ }
+
+}
From 90e83eaf624412f4a05f1136560e1ba248d067dd Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 21 Jul 2023 17:01:53 +0200
Subject: [PATCH 07/26] Pipeline improvements
---
Jenkinsfile | 77 ---------------------------------------------
README.md | 2 +-
jenkins/Jenkinsfile | 32 +++++++++++++------
3 files changed, 23 insertions(+), 88 deletions(-)
delete mode 100644 Jenkinsfile
diff --git a/Jenkinsfile b/Jenkinsfile
deleted file mode 100644
index 5d19417..0000000
--- a/Jenkinsfile
+++ /dev/null
@@ -1,77 +0,0 @@
-pipeline {
-
- agent any
-
- environment {
- USER='placeholder'
- PASSWORD='placeholder'
- DOCKER_REGISTRY='git.massivebox.net'
- BUILDER_NAME='mbuilder'
- SERVICE='ecodash/ecodash'
- TAG='latest'
- }
-
- stages {
-
- stage('Run linter and build') {
- agent { docker { image 'golang' } }
- steps {
- git url: 'https://git.massivebox.net/ecodash/ecodash'
- sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
- sh 'go mod tidy'
- sh 'golangci-lint run'
- sh 'env GOOS=linux GOARCH=amd64 go build -o app src/main/main.go'
- stash includes: 'app', name: 'ecodash-x86'
- sh 'env GOOS=linux GOARCH=arm go build -o app src/main/main.go'
- stash includes: 'app', name: 'ecodash-arm'
- stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
- stash includes: 'templates/**', name: 'templates'
- }
- }
-
-
- stage('Build x86 container') {
- steps {
- unstash 'dockerfile'
- unstash 'ecodash-x86'
- unstash 'templates'
- sh 'docker build -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
- }
- }
-
- stage('Prepare buildx') {
- steps {
- sh """
- docker run --privileged --rm tonistiigi/binfmt --install all
-
- docker context create $BUILDER_NAME
- docker context use $BUILDER_NAME
- docker buildx create $BUILDER_NAME
- docker buildx use $BUILDER_NAME
- docker buildx inspect --bootstrap
- """
- }
- }
-
- stage('Build arm container') {
- steps {
- unstash 'dockerfile'
- unstash 'ecodash-arm'
- unstash 'templates'
- sh 'docker buildx build --platform linux/arm64 -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
- }
- }
-
- }
-
- post {
- always {
- // cleanup
- sh """
- docker context rm -f $BUILDER_NAME
- docker buildx use default
- """
- }
- }
-
-}
diff --git a/README.md b/README.md
index f3c9f66..0469ba7 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# 🌿 EcoDash
-[](https://woodpecker.massivebox.net/ecodash/ecodash) [](https://ecodash.xyz) [](https://ecodash.xyz/contribute)
+[](https://woodpecker.massivebox.net/ecodash/ecohttpsdash) [](https://ecodash.xyz) [](https://ecodash.xyz/contribute)
EcoDash is a simple way to show your users how much your server consumes.
It's intended as a medium of transparency, that gives your users an idea about the consumption of your machine. It's not meant to be 100% accurate.
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index c7d6982..7833d6c 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -3,12 +3,9 @@ pipeline {
agent any
environment {
- USER='user'
- PASSWORD='password'
DOCKER_REGISTRY='git.massivebox.net'
BUILDER_NAME='mbuilder'
SERVICE='ecodash/ecodash'
- TAG='latest'
}
stages {
@@ -16,14 +13,15 @@ pipeline {
stage('Run linter and build') {
agent { docker { image 'golang' } }
steps {
- git url: 'https://git.massivebox.net/ecodash/ecodash'
- //sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
+ checkout scm
+ sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
sh 'go mod tidy'
- //sh 'golangci-lint run'
+ sh 'golangci-lint run'
sh 'env GOOS=linux GOARCH=amd64 go build -o app src/main/main.go'
stash includes: 'app', name: 'ecodash-x86'
sh 'env GOOS=linux GOARCH=arm go build -o app src/main/main.go'
stash includes: 'app', name: 'ecodash-arm'
+ stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
stash includes: 'templates/**', name: 'templates'
}
}
@@ -31,10 +29,10 @@ pipeline {
stage('Build x86 container') {
steps {
- sh 'curl -L -o Dockerfile https://pasty.nikko.cf/UYU39i/raw'
+ unstash 'dockerfile'
unstash 'ecodash-x86'
unstash 'templates'
- sh 'docker build -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
+ sh 'docker build -t ecodash .'
}
}
@@ -54,10 +52,23 @@ pipeline {
stage('Build arm container') {
steps {
- sh 'curl -L -o Dockerfile https://pasty.nikko.cf/UYU39i/raw'
+ unstash 'dockerfile'
unstash 'ecodash-arm'
unstash 'templates'
- sh 'docker buildx build --platform linux/arm64 -t $DOCKER_REGISTRY/$SERVICE:$TAG .'
+ sh 'docker buildx build --platform linux/arm64 -t ecodash .'
+ }
+ }
+
+ stage('Publish container on tag latest') {
+ when { branch 'master' }
+ steps {
+ withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
+ sh 'docker login -u $USER -p $PASSWORD $DOCKER_REGISTRY'
+ }
+ sh """
+ docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:$TAG
+ docker push $DOCKER_REGISTRY/$SERVICE:$TAG
+ """
}
}
@@ -74,3 +85,4 @@ pipeline {
}
}
+
From 394091d885af53edb1067d53961a40799c6f02c1 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 21 Jul 2023 18:10:35 +0200
Subject: [PATCH 08/26] Fix pipeline
---
jenkins/Jenkinsfile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index 7833d6c..b58cdb1 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -32,7 +32,7 @@ pipeline {
unstash 'dockerfile'
unstash 'ecodash-x86'
unstash 'templates'
- sh 'docker build -t ecodash .'
+ sh 'cp jenkins/Dockerfile ./Dockerfile; docker build -t ecodash .'
}
}
@@ -55,7 +55,7 @@ pipeline {
unstash 'dockerfile'
unstash 'ecodash-arm'
unstash 'templates'
- sh 'docker buildx build --platform linux/arm64 -t ecodash .'
+ sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/arm64 -t ecodash .'
}
}
From d0f8950c3cc4cd018229d06ce9b029e0ba7a6381 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 21 Jul 2023 18:30:25 +0200
Subject: [PATCH 09/26] Add jenkins'Dockerfile whoops I forgot
---
jenkins/Dockerfile | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile
index e69de29..1cfaa85 100644
--- a/jenkins/Dockerfile
+++ b/jenkins/Dockerfile
@@ -0,0 +1,7 @@
+FROM debian:latest
+
+WORKDIR /app
+COPY app app
+COPY templates templates
+
+CMD ["./app"]
From 97994ab47abc45a3af4fa9b5fb52cb4e3f690c69 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 21 Jul 2023 18:46:31 +0200
Subject: [PATCH 10/26] Minor inconvenience
---
jenkins/Jenkinsfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index b58cdb1..a2e64e7 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -63,7 +63,7 @@ pipeline {
when { branch 'master' }
steps {
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
- sh 'docker login -u $USER -p $PASSWORD $DOCKER_REGISTRY'
+ sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
}
sh """
docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:$TAG
From 6bfe31de5696092424a3242eb7c4e852f4e9973f Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Fri, 21 Jul 2023 18:59:59 +0200
Subject: [PATCH 11/26] Whoops
---
jenkins/Jenkinsfile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index a2e64e7..e94582b 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -66,8 +66,8 @@ pipeline {
sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
}
sh """
- docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:$TAG
- docker push $DOCKER_REGISTRY/$SERVICE:$TAG
+ docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:latest
+ docker push $DOCKER_REGISTRY/$SERVICE:latest
"""
}
}
From c650a1fae1b2c8f114af55aad03d3ffe34072c63 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 10:24:01 +0200
Subject: [PATCH 12/26] Fix multi-arch container build
---
jenkins/Dockerfile | 5 ++++-
jenkins/Jenkinsfile | 34 +++++++++++++++++-----------------
2 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile
index 1cfaa85..96d5a1d 100644
--- a/jenkins/Dockerfile
+++ b/jenkins/Dockerfile
@@ -1,7 +1,10 @@
FROM debian:latest
WORKDIR /app
-COPY app app
+COPY ecodash_arm ecodash_arm
+COPY ecodash_x86 ecodash_x86
COPY templates templates
+RUN if [ "$(uname -m)" = "aarch64" ]; then mv ecodash_arm app; rm ecodash_x86; else mv ecodash_x86 app; rm ecodash_arm fi
+
CMD ["./app"]
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index e94582b..d97746e 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -17,25 +17,15 @@ pipeline {
sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
sh 'go mod tidy'
sh 'golangci-lint run'
- sh 'env GOOS=linux GOARCH=amd64 go build -o app src/main/main.go'
- stash includes: 'app', name: 'ecodash-x86'
- sh 'env GOOS=linux GOARCH=arm go build -o app src/main/main.go'
- stash includes: 'app', name: 'ecodash-arm'
+ sh 'env GOOS=linux GOARCH=amd64 go build -o ecodash_x86 src/main/main.go'
+ stash includes: 'ecodash_x86', name: 'ecodash_x86'
+ sh 'env GOOS=linux GOARCH=arm go build -o ecodash_arm src/main/main.go'
+ stash includes: 'ecodash_arm', name: 'ecodash_arm'
stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
stash includes: 'templates/**', name: 'templates'
}
}
-
- stage('Build x86 container') {
- steps {
- unstash 'dockerfile'
- unstash 'ecodash-x86'
- unstash 'templates'
- sh 'cp jenkins/Dockerfile ./Dockerfile; docker build -t ecodash .'
- }
- }
-
stage('Prepare buildx') {
steps {
sh """
@@ -50,12 +40,22 @@ pipeline {
}
}
- stage('Build arm container') {
+ stage('Build multi-arch container') {
steps {
unstash 'dockerfile'
- unstash 'ecodash-arm'
+ unstash 'ecodash_x86'
+ unstash 'ecodash_arm'
unstash 'templates'
- sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/arm64 -t ecodash .'
+ sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/amd64,linux/arm64 -t ecodash .'
+ }
+ }
+
+ stage('Publish built files') {
+ steps {
+ sh 'mv ecodash_x86 ecodash'
+ archiveArtifacts artifacts: ['templates/**', 'ecodash'] name: 'ecodash-x86'
+ sh 'mv ecodash_arm ecodash'
+ archiveArtifacts artifacts: ['templates/**', 'ecodash'] name: 'ecodash-arm'
}
}
From fa28b77c5214236ed514d759bb7f7036cee0cd11 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 10:26:14 +0200
Subject: [PATCH 13/26] Add missing commas
---
jenkins/Jenkinsfile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index d97746e..85dc69f 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -53,9 +53,9 @@ pipeline {
stage('Publish built files') {
steps {
sh 'mv ecodash_x86 ecodash'
- archiveArtifacts artifacts: ['templates/**', 'ecodash'] name: 'ecodash-x86'
+ archiveArtifacts artifacts: ['templates/**', 'ecodash'], name: 'ecodash-x86'
sh 'mv ecodash_arm ecodash'
- archiveArtifacts artifacts: ['templates/**', 'ecodash'] name: 'ecodash-arm'
+ archiveArtifacts artifacts: ['templates/**', 'ecodash'], name: 'ecodash-arm'
}
}
From ad89006cc47213f610be76611673cc965c674b33 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 10:34:21 +0200
Subject: [PATCH 14/26] Fix published artifacts
---
jenkins/Jenkinsfile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index 85dc69f..955f4e7 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -52,10 +52,10 @@ pipeline {
stage('Publish built files') {
steps {
- sh 'mv ecodash_x86 ecodash'
- archiveArtifacts artifacts: ['templates/**', 'ecodash'], name: 'ecodash-x86'
- sh 'mv ecodash_arm ecodash'
- archiveArtifacts artifacts: ['templates/**', 'ecodash'], name: 'ecodash-arm'
+ sh 'mv ecodash_x86 ecodash; zip -r ecodash-x86.zip templates ecodash'
+ archiveArtifacts artifacts: "ecodash-x86.zip"
+ sh 'mv ecodash_arm ecodash; zip -r ecodash-arm.zip templates ecodash'
+ archiveArtifacts artifacts: "ecodash-arm.zip"
}
}
From 8db3f56ca45d831f751f2f322e07bbf3144763c8 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 11:14:54 +0200
Subject: [PATCH 15/26] Hopefully fix docker complaining about nonsense
---
jenkins/Jenkinsfile | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index 955f4e7..1874a41 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -29,11 +29,7 @@ pipeline {
stage('Prepare buildx') {
steps {
sh """
- docker run --privileged --rm tonistiigi/binfmt --install all
-
- docker context create $BUILDER_NAME
- docker context use $BUILDER_NAME
- docker buildx create $BUILDER_NAME
+ docker buildx create --name $BUILDER_NAME
docker buildx use $BUILDER_NAME
docker buildx inspect --bootstrap
"""
@@ -77,10 +73,7 @@ pipeline {
post {
always {
// cleanup
- sh """
- docker context rm -f $BUILDER_NAME
- docker buildx use default
- """
+ sh 'docker buildx rm $BUILDER_NAME'
}
}
From 07b9571ffa285dbbed7f2d98d9aa8332648b19a0 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 11:34:01 +0200
Subject: [PATCH 16/26] Fix
---
jenkins/Dockerfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile
index 96d5a1d..82c8879 100644
--- a/jenkins/Dockerfile
+++ b/jenkins/Dockerfile
@@ -5,6 +5,6 @@ COPY ecodash_arm ecodash_arm
COPY ecodash_x86 ecodash_x86
COPY templates templates
-RUN if [ "$(uname -m)" = "aarch64" ]; then mv ecodash_arm app; rm ecodash_x86; else mv ecodash_x86 app; rm ecodash_arm fi
+RUN if [ "$(uname -m)" = "aarch64" ]; then mv ecodash_arm app; rm ecodash_x86; else mv ecodash_x86 app; rm ecodash_arm; fi
CMD ["./app"]
From 153b507a69c3d3708d464a53494f99058f9c29ca Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 12:27:56 +0200
Subject: [PATCH 17/26] Load image into docker
---
jenkins/Jenkinsfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index 1874a41..5c2ee18 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -42,7 +42,7 @@ pipeline {
unstash 'ecodash_x86'
unstash 'ecodash_arm'
unstash 'templates'
- sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/amd64,linux/arm64 -t ecodash .'
+ sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/amd64,linux/arm64 --load -t ecodash .'
}
}
From d5d6aa4d087e3a272325cc7a18baa046a5add262 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 15:37:59 +0200
Subject: [PATCH 18/26] Work around docker's BS
---
jenkins/Jenkinsfile | 45 +++++++++++++++++++++++++--------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index 5c2ee18..f22a44b 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -26,23 +26,41 @@ pipeline {
}
}
- stage('Prepare buildx') {
+ stage('Prepare container build') {
steps {
sh """
docker buildx create --name $BUILDER_NAME
docker buildx use $BUILDER_NAME
docker buildx inspect --bootstrap
+ cp jenkins/Dockerfile ./Dockerfile
"""
- }
- }
-
- stage('Build multi-arch container') {
- steps {
+ withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
+ sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
+ }
unstash 'dockerfile'
unstash 'ecodash_x86'
unstash 'ecodash_arm'
unstash 'templates'
- sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/amd64,linux/arm64 --load -t ecodash .'
+ }
+ }
+
+ stage('Build and push container on push to master') {
+ when {
+ anyOf {
+ branch 'master'
+ buildingTag()
+ }
+ }
+ steps {
+ sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:latest .'
+ }
+ }
+
+ stage('Build and push container on tag') {
+ when { buildingTag() }
+ steps {
+ def formattedTag = env.TAG_NAME.replaceFirst(/^v/, '')
+ sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:$formattedTag .'
}
}
@@ -55,19 +73,6 @@ pipeline {
}
}
- stage('Publish container on tag latest') {
- when { branch 'master' }
- steps {
- withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
- sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
- }
- sh """
- docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:latest
- docker push $DOCKER_REGISTRY/$SERVICE:latest
- """
- }
- }
-
}
post {
From 75423645ff459e5d1d7861d539538cea22e08796 Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sat, 22 Jul 2023 15:40:00 +0200
Subject: [PATCH 19/26] Work around Jenkins'BS
---
jenkins/Jenkinsfile | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index f22a44b..0b94e58 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -59,8 +59,10 @@ pipeline {
stage('Build and push container on tag') {
when { buildingTag() }
steps {
- def formattedTag = env.TAG_NAME.replaceFirst(/^v/, '')
- sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:$formattedTag .'
+ script {
+ def formattedTag = env.TAG_NAME.replaceFirst(/^v/, '')
+ sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:$formattedTag .'
+ }
}
}
From 4bf1455ba49b2adc3b9aa9d549d88540571172ea Mon Sep 17 00:00:00 2001
From: MassiveBox
Date: Sun, 29 Oct 2023 18:32:35 +0100
Subject: [PATCH 20/26] Remove need for restart on settings change
---
BUILD.md | 6 ++----
README.md | 2 +-
jenkins/Jenkinsfile | 3 ++-
src/ecodash/config.go | 16 +++++++--------
src/ecodash/http.go | 9 +++++----
src/main/main.go | 36 ++++++++++------------------------
templates/default/restart.html | 6 ------
7 files changed, 28 insertions(+), 50 deletions(-)
delete mode 100644 templates/default/restart.html
diff --git a/BUILD.md b/BUILD.md
index b9d6e3f..260e9c9 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -12,7 +12,7 @@ If you really have to build it yourself, we recommend you Docker over binaries.
1. Download the Go Compiler from https://go.dev/dl/ or from your repository's package manager (it's usually called `go` or `golang`)
2. Download the Git SCM from https://git-scm.com/download/linux or from your package manager (it's always called `git`)
3. Download `golangci-lint` from https://golangci-lint.run/
-4. Clone the repository by running `git clone https://gitea.massivebox.net/ecodash/ecodash.git ` inside a command prompt
+4. Clone the repository by running `git clone https://git.massivebox.net/ecodash/ecodash.git ` inside a command prompt
5. Switch to the project directory with `cd ecodash`
6. Run `golangci-lint run` to lint all project files
7. Build with `go build src/main/main.go -o ecodash`. This will generate an executable, `ecodash`, in the same directory.
@@ -22,9 +22,7 @@ If you really have to build it yourself, we recommend you Docker over binaries.
1. Install the latest release of the Go Compiler for Windows from https://go.dev/dl/
2. Install the Git SCM from https://git-scm.com/download/win. The "Standalone installer" is recommended. All the default settings will work fine.
3. Download `golangci-lint` from https://golangci-lint.run/
-4. Clone the repository by running `git clone https://gitea.massivebox.net/ecodash/ecodash.git ` inside a command prompt
+4. Clone the repository by running `git clone https://git.massivebox.net/ecodash/ecodash.git ` inside a command prompt
5. Switch to the project directory with `cd ecodash`
6. Run `golangci-lint run` to lint all project files
7. Build with `go build src/main/main.go -o ecodash`. This will generate an executable, `ecodash.exe`, in the same directory.
-
-## Docker
\ No newline at end of file
diff --git a/README.md b/README.md
index 0469ba7..ea9e6c6 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# 🌿 EcoDash
-[](https://woodpecker.massivebox.net/ecodash/ecohttpsdash) [](https://ecodash.xyz) [](https://ecodash.xyz/contribute)
+[](https://jenkins.massivebox.net/job/ecodash/) [](https://ecodash.xyz) [](https://ecodash.xyz/contribute)
EcoDash is a simple way to show your users how much your server consumes.
It's intended as a medium of transparency, that gives your users an idea about the consumption of your machine. It's not meant to be 100% accurate.
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
index 0b94e58..dac4bc1 100644
--- a/jenkins/Jenkinsfile
+++ b/jenkins/Jenkinsfile
@@ -66,7 +66,8 @@ pipeline {
}
}
- stage('Publish built files') {
+ stage('Publish build artifacts on tag') {
+ when { buildingTag() }
steps {
sh 'mv ecodash_x86 ecodash; zip -r ecodash-x86.zip templates ecodash'
archiveArtifacts artifacts: "ecodash-x86.zip"
diff --git a/src/ecodash/config.go b/src/ecodash/config.go
index 91b7541..2856159 100644
--- a/src/ecodash/config.go
+++ b/src/ecodash/config.go
@@ -61,10 +61,10 @@ func formatURL(url string) (string, error) {
return url, nil
}
-func LoadConfig() (config *Config, isFirstRun bool, err error) {
+func LoadConfig() (config *Config, err error) {
db, err := sql.Open("sqlite", "./database.db")
if err != nil {
- return &Config{}, false, err
+ return &Config{}, err
}
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS "cache" (
@@ -74,7 +74,7 @@ func LoadConfig() (config *Config, isFirstRun bool, err error) {
PRIMARY KEY("time")
);`)
if err != nil {
- return &Config{}, false, err
+ return &Config{}, err
}
defaultConfig := &Config{}
@@ -95,24 +95,24 @@ func LoadConfig() (config *Config, isFirstRun bool, err error) {
if err != nil {
// if the data file doesn't exist, we consider it a first run
if os.IsNotExist(err) {
- return defaultConfig, true, nil
+ return defaultConfig, nil
}
- return &Config{}, false, err
+ return &Config{}, err
}
// if the data file is empty, we consider it as a first run
if len(data) == 0 {
- return defaultConfig, true, nil
+ return defaultConfig, nil
}
conf := &Config{}
err = json.Unmarshal(data, &conf)
if err != nil {
- return &Config{}, false, err
+ return &Config{}, err
}
conf.db = db
- return conf, false, nil
+ return conf, nil
}
func (config *Config) IsAuthorized(c *fiber.Ctx) bool {
diff --git a/src/ecodash/http.go b/src/ecodash/http.go
index 7fbd1b3..bd17c71 100644
--- a/src/ecodash/http.go
+++ b/src/ecodash/http.go
@@ -53,9 +53,9 @@ func (config *Config) AdminEndpoint(c *fiber.Ctx) error {
})
}
return config.RenderAdminPanel(c, Warning{
- Header: "Restart needed",
- Body: "In order to apply changes, please restart EcoDash. " +
- "If you're running via Docker, click here to restart automatically.",
+ Header: "Settings applied",
+ Body: "Your settings have been tested and applied successfully. " +
+ "You can continue using EcoDash on the Home.",
IsSuccess: true,
})
}
@@ -117,7 +117,7 @@ func (config *Config) saveAdminForm(c *fiber.Ctx) error {
return err
}
- form := &Config{
+ form := Config{
HomeAssistant: HomeAssistant{ /*BaseURL to be filled later*/ APIKey: c.FormValue("api_key"), InstallationDate: dayStart(parsedTime)},
Sensors: Sensors{PolledSmartEnergySummation: c.FormValue("polled_smart_energy_summation"), FossilPercentage: c.FormValue("fossil_percentage")},
Administrator: Administrator{Username: c.FormValue("username") /*PasswordHash to be filled later*/},
@@ -151,6 +151,7 @@ func (config *Config) saveAdminForm(c *fiber.Ctx) error {
return err
}
+ *config = form
return os.WriteFile("config.json", js, 0o600)
}
diff --git a/src/main/main.go b/src/main/main.go
index 4fcba7a..4b4c4aa 100644
--- a/src/main/main.go
+++ b/src/main/main.go
@@ -1,33 +1,28 @@
package main
import (
- "log"
- "net/http"
- "os"
- "time"
-
"git.massivebox.net/ecodash/ecodash/src/ecodash"
"git.massivebox.net/ecodash/ecodash/src/tools"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html"
"github.com/robfig/cron/v3"
+ "log"
+ "os"
)
func main() {
- config, isFirstRun, err := ecodash.LoadConfig()
+ config, err := ecodash.LoadConfig()
if err != nil {
log.Fatal(err)
}
- if !isFirstRun {
- cr := cron.New()
- _, err = cr.AddFunc("@hourly", config.UpdateHistory)
- if err != nil {
- log.Fatal(err)
- }
- cr.Start()
- config.UpdateHistory()
+ cr := cron.New()
+ _, err = cr.AddFunc("@hourly", config.UpdateHistory)
+ if err != nil {
+ log.Fatal(err)
}
+ cr.Start()
+ config.UpdateHistory()
engine := html.New("./templates/"+config.Dashboard.Theme, ".html")
engine.AddFunc("divide", tools.TemplateDivide)
@@ -40,7 +35,7 @@ func main() {
app.Static("/assets", "./templates/"+config.Dashboard.Theme+"/assets")
app.Get("/", func(c *fiber.Ctx) error {
- if isFirstRun {
+ if config.Administrator.Username == "" || config.Administrator.PasswordHash == "" {
c.Cookie(&fiber.Cookie{Name: "admin_username", Value: ""})
c.Cookie(&fiber.Cookie{Name: "admin_password_hash", Value: tools.Hash("")})
return config.RenderAdminPanel(c)
@@ -54,17 +49,6 @@ func main() {
app.All("/admin", config.AdminEndpoint)
- app.Get("/restart", func(c *fiber.Ctx) error {
- if config.IsAuthorized(c) {
- go func() {
- time.Sleep(time.Second)
- os.Exit(1)
- }()
- return c.Render("restart", config.TemplateDefaultsMap(), "base")
- }
- return c.Redirect("./", http.StatusTemporaryRedirect)
- })
-
port := os.Getenv("PORT")
if port == "" {
port = "80"
diff --git a/templates/default/restart.html b/templates/default/restart.html
deleted file mode 100644
index 2a9ca60..0000000
--- a/templates/default/restart.html
+++ /dev/null
@@ -1,6 +0,0 @@
-
Restarting...
-
- You should be able to continue using EcoDash soon by clicking here.
- If you get an error like "Address Unreachable", make sure you've allowed your container to restart automatically.
- Check the error logs if the error persists.
-