-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf5cd36
commit 1adda14
Showing
21 changed files
with
1,349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: main | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- '**' | ||
|
||
env: | ||
GIT_SHA: ${{ github.sha }} | ||
GIT_REF: ${{ github.ref }} | ||
CONTAINER_NAME: shelly2prometheus | ||
CHART_NAME: shelly2prometheus | ||
CHART_GIT_BRANCH: master | ||
CHART_REPOSITORY: szymonrychu/charts | ||
BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | ||
BOT_EMAIL: "[email protected]" | ||
BOT_USERNAME: "szymonrychu" | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
CONTAINER_REGISTRY: szymonrychu | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Parse versions in commit and setup debs | ||
run: | | ||
export LATEST_REPO_TAG=$(git tag -l --sort=-v:refname "[0-9]*" | head -n1) | ||
if [ -z "${LATEST_REPO_TAG}" ]; then | ||
export LATEST_REPO_TAG="0.0.1" | ||
fi | ||
export SHORT_SHA=$(echo ${GIT_SHA:0:7}) | ||
export APP_VERSION=${LATEST_REPO_TAG}-${SHORT_SHA} | ||
export CHART_VERSION=${LATEST_REPO_TAG}-$(git show -s --format=%ct HEAD)-${SHORT_SHA} | ||
export CONTAINER_VERSION=${GIT_SHA:0:7} | ||
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV | ||
echo "CHART_VERSION=${CHART_VERSION}" >> $GITHUB_ENV | ||
echo "CONTAINER_VERSION=${CONTAINER_VERSION}" >> $GITHUB_ENV | ||
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV | ||
echo "LATEST_REPO_TAG=${LATEST_REPO_TAG}" >> $GITHUB_ENV | ||
sudo wget https://github.com/mikefarah/yq/releases/download/3.4.0/yq_linux_amd64 -O /usr/bin/yq | ||
sudo chmod +x /usr/bin/yq | ||
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash | ||
- name: Update metadata files | ||
run: | | ||
set -e | ||
cd chart | ||
yq w -i ${CHART_NAME}/Chart.yaml version ${CHART_VERSION} | ||
yq w -i ${CHART_NAME}/Chart.yaml appVersion ${CONTAINER_VERSION} | ||
- name: Build, tag, and push panel image to DockerHub | ||
run: | | ||
set -e | ||
echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin | ||
docker build -t ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${CONTAINER_VERSION} . | ||
docker push ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${CONTAINER_VERSION} | ||
- name: Package and push helm chart | ||
run: | | ||
set -e | ||
cd chart | ||
CHART_PWD=$(pwd) | ||
helm dep update ${CHART_NAME} | ||
helm package -u ${CHART_NAME} | ||
git clone https://x-access-token:${BOT_TOKEN}@github.com/${CHART_REPOSITORY}.git /tmp/repo | ||
cd /tmp/repo | ||
git checkout ${CHART_GIT_BRANCH} | ||
mv ${CHART_PWD}/${CHART_NAME}-${CHART_VERSION}.tgz ./ | ||
helm repo index . | ||
git config --global user.email "${BOT_EMAIL}" | ||
git config --global user.name "${BOT_USERNAME}" | ||
git add -A | ||
git commit -m "Add ${CHART_NAME} ${CHART_VERSION}" | ||
git push origin ${CHART_GIT_BRANCH} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- '[0-9]+.[0-9]+.[0-9]+' | ||
|
||
env: | ||
GIT_SHA: ${{ github.sha }} | ||
GIT_REF: ${{ github.ref }} | ||
CONTAINER_NAME: shelly2prometheus | ||
CHART_NAME: shelly2prometheus | ||
CHART_GIT_BRANCH: master | ||
CHART_REPOSITORY: szymonrychu/charts | ||
BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | ||
BOT_EMAIL: "[email protected]" | ||
BOT_USERNAME: "szymonrychu" | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
CONTAINER_REGISTRY: szymonrychu | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Parse versions in commit and setup debs | ||
run: | | ||
export LATEST_REPO_TAG=$(git tag -l --sort=-v:refname "[0-9]*" | head -n1) | ||
export SHORT_SHA=$(echo ${GIT_SHA:0:7}) | ||
echo "APP_VERSION=${LATEST_REPO_TAG}" >> $GITHUB_ENV | ||
echo "CHART_VERSION=${LATEST_REPO_TAG}" >> $GITHUB_ENV | ||
echo "CONTAINER_VERSION=${LATEST_REPO_TAG}" >> $GITHUB_ENV | ||
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV | ||
echo "LATEST_REPO_TAG=${LATEST_REPO_TAG}" >> $GITHUB_ENV | ||
echo $SHORT_SHA | ||
echo $LATEST_REPO_TAG | ||
sudo wget https://github.com/mikefarah/yq/releases/download/3.4.0/yq_linux_amd64 -O /usr/bin/yq | ||
sudo chmod +x /usr/bin/yq | ||
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash | ||
- name: Update metadata files | ||
run: | | ||
set -e | ||
cd chart | ||
yq w -i ${CHART_NAME}/Chart.yaml version ${CHART_VERSION} | ||
yq w -i ${CHART_NAME}/Chart.yaml appVersion ${CONTAINER_VERSION} | ||
- name: Build, tag, and push panel image to Amazon ECR | ||
run: | | ||
set -e | ||
echo "${DOCKERHUB_PASSWORD}" | docker login -u ${DOCKERHUB_USERNAME} --password-stdin | ||
docker pull ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${GIT_SHA:0:7} | ||
docker tag ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${GIT_SHA:0:7} ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${LATEST_REPO_TAG} | ||
docker push ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${LATEST_REPO_TAG} | ||
docker tag ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${GIT_SHA:0:7} ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:latest | ||
docker push ${CONTAINER_REGISTRY}/${CONTAINER_NAME}:${LATEST_REPO_TAG} | ||
- name: Package and push helm chart | ||
run: | | ||
set -e | ||
cd chart | ||
CHART_PWD=$(pwd) | ||
helm dep update ${CHART_NAME} | ||
helm package -u ${CHART_NAME} | ||
git clone https://x-access-token:${BOT_TOKEN}@github.com/${CHART_REPOSITORY}.git /tmp/repo | ||
cd /tmp/repo | ||
git checkout ${CHART_GIT_BRANCH} | ||
mv ${CHART_PWD}/${CHART_NAME}-${CHART_VERSION}.tgz ./ | ||
helm repo index . | ||
git config --global user.email "${BOT_EMAIL}" | ||
git config --global user.name "${BOT_USERNAME}" | ||
git add -A | ||
git commit -m "Release ${CHART_NAME} ${CHART_VERSION}" | ||
git push origin ${CHART_GIT_BRANCH} | ||
- name: Create GH Release | ||
uses: notlmn/release-with-changelog@v3 | ||
with: | ||
token: ${{ secrets.BOT_TOKEN }} | ||
template: '{commits}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/shelly2prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM golang:alpine as build | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy go mod and sum files | ||
COPY go.mod go.sum ./ | ||
|
||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
# Build the application | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/main | ||
|
||
FROM scratch | ||
|
||
COPY --from=build /go/bin/main /go/bin/main | ||
# Expose port 9000 to the outside world | ||
EXPOSE 8090 | ||
|
||
# Command to run the executable | ||
ENTRYPOINT ["/go/bin/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: v2 | ||
name: shelly2prometheus | ||
description: A Helm chart for Kubernetes | ||
|
||
# A chart can be either an 'application' or a 'library' chart. | ||
# | ||
# Application charts are a collection of templates that can be packaged into versioned archives | ||
# to be deployed. | ||
# | ||
# Library charts provide useful utilities or functions for the chart developer. They're included as | ||
# a dependency of application charts to inject those utilities and functions into the rendering | ||
# pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
type: application | ||
|
||
# This is the chart version. This version number should be incremented each time you make changes | ||
# to the chart and its templates, including the app version. | ||
# Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
version: 0.0.1 | ||
|
||
# This is the version number of the application being deployed. This version number should be | ||
# incremented each time you make changes to the application. Versions are not expected to | ||
# follow Semantic Versioning. They should reflect the version the application is using. | ||
# It is recommended to use it with quotes. | ||
appVersion: "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "shelly2prometheus.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "shelly2prometheus.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "shelly2prometheus.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "shelly2prometheus.labels" -}} | ||
helm.sh/chart: {{ include "shelly2prometheus.chart" . }} | ||
{{ include "shelly2prometheus.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "shelly2prometheus.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "shelly2prometheus.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "shelly2prometheus.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "shelly2prometheus.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "shelly2prometheus.fullname" . }} | ||
labels: | ||
{{- include "shelly2prometheus.labels" . | nindent 4 }} | ||
data: | ||
shellyUrl: {{ .Values.shellyUrl | quote }} | ||
metricsPrefix: {{ .Values.metrics.prefix | quote }} | ||
metricsPort: {{ .Values.metrics.port | quote }} | ||
metricsEndpoint: {{ .Values.metrics.endpoint | quote }} |
Oops, something went wrong.