Skip to content

Commit

Permalink
feat: updated to current state of extension development
Browse files Browse the repository at this point in the history
- liveness/readiness probes
- helm-chart
- updated dependencies
- linting / auditing in ci
  • Loading branch information
ReuDa committed Apr 20, 2023
1 parent 66687c2 commit 6f2c65e
Show file tree
Hide file tree
Showing 25 changed files with 810 additions and 164 deletions.
153 changes: 138 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,49 @@ on:
- 'main'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
audit:
name: Audit
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-go@v4
with:
go-version: '^1.20.0'

- name: Audit
run: |
go mod download
make audit
- name: Check Sonar Token
id: check-sonar
shell: bash
run: |
if [ "${{ secrets.SONAR_TOKEN }}" != '' ]; then
echo "available=true" >> $GITHUB_OUTPUT;
else
echo "available=false" >> $GITHUB_OUTPUT;
fi
- name: SonarCloud Scan
if: ${{ steps.check-sonar.outputs.available == 'true' }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build-images:
name: Build Docker Images
needs:
- audit
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -23,44 +62,128 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

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

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

- uses: actions/setup-go@v3
with:
go-version: '^1.18.0'

- name: Execute go tests
run: |
go mod download
go test ./...
- name: Log in to the container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: steadybit/extension-prometheus
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: ./
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-args: |
NAME=${{ env.IMAGE_NAME }}
NAME=${{ github.repository }}
VERSION=${{ steps.meta.outputs.version }}
REVISION=${{ github.sha }}
test-helm-charts:
name: "Test Helm Charts"
runs-on: ubuntu-latest
needs:
- build-images
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.9.0

- name: Add dependency chart repos
run: |
helm repo add steadybit https://steadybit.github.io/helm-charts
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Add unit testing plugin
run: |
helm plugin install https://github.com/quintush/helm-unittest
- name: Run unit tests
run: make charttesting

- name: Set up chart-testing
uses: helm/[email protected]

- name: Run chart-testing (lint)
run: ct lint --config chartTesting.yaml

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --config chartTesting.yaml)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Create kind cluster
uses: helm/[email protected]
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
run: ct install --config chartTesting.yaml


release-helm-chart:
name: "Release Helm Chart"
runs-on: ubuntu-latest
needs:
- test-helm-charts
if: github.ref == 'refs/heads/main'

permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.8.1

- name: Add dependency chart repos
run: |
helm repo add steadybit https://steadybit.github.io/helm-charts
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: charts
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/extension-prometheus
extension-prometheus.iml
/coverage.out
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##
## Build
##
FROM golang:1.18-alpine AS build
FROM golang:1.20-alpine AS build

ARG NAME
ARG VERSION
Expand All @@ -22,7 +22,7 @@ RUN go build \
-X 'github.com/steadybit/extension-kit/extbuild.ExtensionName=${NAME}' \
-X 'github.com/steadybit/extension-kit/extbuild.Version=${VERSION}' \
-X 'github.com/steadybit/extension-kit/extbuild.Revision=${REVISION}'" \
-o /extension-prometheus
-o ./extension

##
## Runtime
Expand All @@ -38,8 +38,9 @@ USER $USERNAME

WORKDIR /

COPY --from=build /extension-prometheus /extension-prometheus
COPY --from=build /app/extension /extension

EXPOSE 8084
EXPOSE 8087
EXPOSE 8088

ENTRYPOINT ["/extension-prometheus"]
ENTRYPOINT ["/extension"]
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ==================================================================================== #
# HELPERS
# ==================================================================================== #

## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'


# ==================================================================================== #
# QUALITY CONTROL
# ==================================================================================== #

## tidy: format code and tidy modfile
.PHONY: tidy
tidy:
go fmt ./...
go mod tidy -v

## audit: run quality control checks
.PHONY: audit
audit:
go vet ./...
go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000,-ST1003 ./...
go test -race -vet=off -coverprofile=coverage.out ./...
go mod verify

## charttesting: Run Helm chart unit tests
.PHONY: charttesting
charttesting:
for dir in charts/steadybit-extension-*; do \
echo "Unit Testing $$dir"; \
helm unittest $$dir; \
done

## chartlint: Lint charts
.PHONY: chartlint
chartlint:
ct lint --config chartTesting.yaml

# ==================================================================================== #
# BUILD
# ==================================================================================== #

## build: build the extension
.PHONY: build
build:
go mod verify
go build -o=./extension

## run: run the extension
.PHONY: run
run: tidy build
./extension

## container: build the container image
.PHONY: container
container:
docker build -t extension-prometheus:latest .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A [Steadybit](https://www.steadybit.com/) check implementation to gather Prometh

## Deployment

We recommend that you deploy the extension with our [official Helm chart](https://github.com/steadybit/helm-charts/tree/main/charts/steadybit-extension-prometheus).
We recommend that you deploy the extension with our [official Helm chart](https://github.com/steadybit/extension-prometheus/tree/main/charts/steadybit-extension-prometheus).

## Agent Configuration

Expand Down
8 changes: 8 additions & 0 deletions chartTesting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://github.com/helm/chart-testing#configuration
remote: origin
target-branch: main
chart-dirs:
- charts
chart-repos:
- steadybit=https://steadybit.github.io/helm-charts
helm-extra-args: --timeout 600s
24 changes: 24 additions & 0 deletions charts/steadybit-extension-prometheus/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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/
tests/
6 changes: 6 additions & 0 deletions charts/steadybit-extension-prometheus/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: extensionlib
repository: https://steadybit.github.io/helm-charts
version: 1.1.0
digest: sha256:50f7816a312812729400e1ead5cfe1a89de8aabcc66ff2cc6eac262d0952912b
generated: "2023-04-20T15:56:47.192588+02:00"
25 changes: 25 additions & 0 deletions charts/steadybit-extension-prometheus/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v2
name: steadybit-extension-prometheus
description: Steadybit Prometheus extension Helm chart for Kubernetes.
version: 1.4.3
appVersion: latest
home: https://www.steadybit.com/
icon: https://steadybit-website-assets.s3.amazonaws.com/logo-symbol-transparent.png
maintainers:
- email: [email protected]
name: bripkens
sources:
- https://github.com/steadybit/extension-prometheus
annotations:
artifacthub.io/images: |
- name: logo
image: https://steadybit-website-assets.s3.amazonaws.com/logo-symbol-transparent.png
artifacthub.io/links: |-
- name: Steadybit website
url: https://www.steadybit.com
- name: Steadybit reliability hub
url: https://hub.steadybit.com
dependencies:
- name: extensionlib
version: 1.1.0
repository: https://steadybit.github.io/helm-charts
1 change: 1 addition & 0 deletions charts/steadybit-extension-prometheus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For documentation, please refer to the repository's [main documentation](../../README.md).
Binary file not shown.
Loading

0 comments on commit 6f2c65e

Please sign in to comment.