Skip to content

Commit e4c5dbb

Browse files
authored
Merge pull request #2 from snapp-incubator/cd-cd-pipeline
added ci/cd pipeline
2 parents 9c5e4f5 + 33ca324 commit e4c5dbb

File tree

19 files changed

+504
-35
lines changed

19 files changed

+504
-35
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
- package-ecosystem: "gomod" # See documentation for possible values
13+
directory: "/" # Location of package manifests
14+
schedule:
15+
interval: "weekly"

.github/workflows/ci.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
name: ci
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
pull_request:
8+
branches:
9+
- "**"
10+
jobs:
11+
lint:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version-file: "go.mod"
19+
- name: golangci-lint
20+
uses: golangci/golangci-lint-action@v8
21+
with:
22+
version: latest
23+
24+
test:
25+
name: test
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/setup-go@v5
30+
with:
31+
go-version-file: "go.mod"
32+
- run: go test -v ./... -covermode=atomic -coverprofile=coverage.out
33+
- uses: codecov/[email protected]
34+
with:
35+
files: coverage.out
36+
token: ${{ secrets.CODECOV_TOKEN }}
37+
slug: snapp-incubator/nats-helper
38+
39+
build-push:
40+
name: Build & Push
41+
runs-on: ubuntu-latest
42+
needs:
43+
- lint
44+
- test
45+
env:
46+
REGISTRY: ghcr.io
47+
USERNAME: ${{ github.repository_owner }}
48+
REPOSITORY: ${{ github.event.repository.name }}
49+
steps:
50+
- name: Checks out our project source code
51+
uses: actions/checkout@v4
52+
53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v3
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
- uses: docker/login-action@v3
60+
with:
61+
registry: ${{ env.REGISTRY }}
62+
username: ${{ env.USERNAME }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- uses: docker/metadata-action@v5
66+
id: meta
67+
with:
68+
images: ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.REPOSITORY }}
69+
tags: |
70+
type=ref,event=branch
71+
type=ref,event=pr
72+
type=semver,pattern={{version}}
73+
type=semver,pattern={{major}}.{{minor}}
74+
75+
- uses: docker/build-push-action@v6
76+
with:
77+
file: "Dockerfile"
78+
context: .
79+
platforms: linux/amd64
80+
push: true
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/helm.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
name: helm
3+
on:
4+
- push
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: checkout
11+
uses: actions/checkout@v4
12+
13+
- name: set up helm
14+
uses: azure/setup-helm@v4
15+
with:
16+
version: v3.13.0
17+
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.13
21+
22+
- name: set up chart-testing
23+
uses: helm/[email protected]
24+
25+
- name: run chart-testing (lint)
26+
run: ct lint --all
27+
28+
release:
29+
runs-on: ubuntu-latest
30+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
31+
steps:
32+
- name: checkout
33+
uses: actions/checkout@v4
34+
35+
- name: set up helm
36+
uses: azure/setup-helm@v4
37+
with:
38+
version: v3.13.0
39+
40+
- name: login to github container registry using helm
41+
run: |
42+
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io --username ${{ github.repository_owner }} --password-stdin
43+
44+
- name: package nats-helper helm chart
45+
run: |
46+
version=${{ github.ref_name }}
47+
helm package --version "${version##v}" --app-version "${version}" ./charts/nats-helper
48+
49+
- name: publish nats-helper chart to github container registry
50+
run: |
51+
version=${{ github.ref_name }}
52+
helm push "nats-helper-${version##v}".tgz oci://ghcr.io/snapp-incubator/nats-helper-chart

.github/workflows/release.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: goreleaser
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
jobs:
8+
docker:
9+
name: docker
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: docker/setup-qemu-action@v3
14+
- uses: docker/setup-buildx-action@v3
15+
- uses: docker/login-action@v3
16+
with:
17+
registry: ghcr.io
18+
username: ${{ github.repository_owner }}
19+
password: ${{ secrets.GITHUB_TOKEN }}
20+
- uses: docker/metadata-action@v5
21+
id: meta
22+
with:
23+
images: ghcr.io/${{ github.repository }}
24+
tags: |
25+
type=ref,event=branch
26+
type=ref,event=pr
27+
type=semver,pattern={{version}}
28+
type=semver,pattern={{major}}.{{minor}}
29+
- uses: docker/build-push-action@v6
30+
with:
31+
file: "Dockerfile"
32+
context: .
33+
platforms: linux/amd64
34+
push: true
35+
tags: ${{ steps.meta.outputs.tags }}
36+
labels: ${{ steps.meta.outputs.labels }}
37+
38+
goreleaser:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
- name: Run GoReleaser
48+
uses: goreleaser/goreleaser-action@v6
49+
with:
50+
distribution: goreleaser
51+
version: "~> v1"
52+
args: release --clean
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Start from the latest golang base image
2+
FROM golang:1.24-alpine3.21 AS builder
3+
4+
# Set the Current Working Directory inside the container
5+
WORKDIR /app
6+
7+
# Copy go mod and sum files
8+
COPY go.mod go.sum ./
9+
10+
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
11+
RUN go mod download
12+
13+
# Copy the source from the current directory to the Working Directory inside the container
14+
COPY . .
15+
16+
# Build the Go app
17+
RUN go build -o /nats-helper
18+
19+
FROM alpine:3.20
20+
21+
WORKDIR /app/
22+
23+
COPY --from=builder /nats-helper .
24+
25+
ENTRYPOINT ["./nats-helper"]
26+
CMD [ "--config=./config.yaml" ]

charts/nats-helper/Chart.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v2
2+
name: nats-helper
3+
description: A Helm chart for deploying the nats-helper service
4+
version: 0.1.0
5+
appVersion: "1.0.0"
6+
keywords:
7+
- nats
8+
- exporter
9+
- monitoring
10+
home: https://github.com/snapp-incubator/nats-helper
11+
maintainers:
12+
- name: sinamna
13+
url: https://github.com/sinamna

charts/nats-helper/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# nats-helper Helm Chart
2+
3+
A Helm chart for deploying the nats-helper service to Kubernetes.
4+
5+
## Introduction
6+
7+
This chart bootstraps a nats-helper deployment on a Kubernetes cluster using the Helm package manager.
8+
9+
## Prerequisites
10+
- Kubernetes 1.16+
11+
- Helm 3+
12+
13+
## Installing the Chart
14+
15+
Add the repository and install:
16+
17+
```sh
18+
helm install my-nats-helper ./charts/nats-helper
19+
```
20+
21+
## Uninstalling the Chart
22+
23+
```sh
24+
helm uninstall my-nats-helper
25+
```
26+
27+
## Configuration
28+
29+
The following table lists the configurable parameters of the nats-helper chart and their default values.
30+
31+
| Parameter | Description | Default |
32+
|--------------------------|---------------------------------------------|---------------------|
33+
| `replicaCount` | Number of replicas | `1` |
34+
| `image.repository` | Image repository | `snappincubator/nats-helper` |
35+
| `image.tag` | Image tag | `latest` |
36+
| `image.pullPolicy` | Image pull policy | `IfNotPresent` |
37+
| `service.type` | Kubernetes service type | `ClusterIP` |
38+
| `service.port` | Service port | `8080` |
39+
| `env` | Environment variables for the container | `[]` |
40+
41+
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.
42+
43+
## Example
44+
45+
```sh
46+
helm install my-nats-helper ./charts/nats-helper \
47+
--set env[0].name=NATS_URL --set env[0].value=nats://nats:4222
48+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Thank you for installing **nats-helper**!
2+
3+
Your release is named: {{ .Release.Name }}
4+
5+
To check the status of your deployment:
6+
kubectl get pods -l app.kubernetes.io/instance={{ .Release.Name }}
7+
8+
To access the service, run:
9+
kubectl port-forward svc/{{ include "nats-helper.fullname" . }} 8080:8080
10+
11+
Then access it via http://localhost:8080
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "nats-helper.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
6+
{{- end -}}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
*/}}
11+
{{- define "nats-helper.fullname" -}}
12+
{{- if .Values.fullnameOverride -}}
13+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
14+
{{- else -}}
15+
{{- $name := default .Chart.Name .Values.nameOverride -}}
16+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
17+
{{- end -}}
18+
{{- end -}}
19+
20+
{{/*
21+
Common labels
22+
*/}}
23+
{{- define "nats-helper.labels" -}}
24+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
25+
app.kubernetes.io/name: {{ include "nats-helper.name" . }}
26+
app.kubernetes.io/instance: {{ .Release.Name }}
27+
app.kubernetes.io/version: {{ .Chart.AppVersion }}
28+
app.kubernetes.io/managed-by: {{ .Release.Service }}
29+
{{- end -}}
30+
31+
{{/*
32+
Selector labels
33+
*/}}
34+
{{- define "nats-helper.selectorLabels" -}}
35+
app.kubernetes.io/name: {{ include "nats-helper.name" . }}
36+
app.kubernetes.io/instance: {{ .Release.Name }}
37+
{{- end -}}
38+
39+
{{/*
40+
Service account name
41+
*/}}
42+
{{- define "nats-helper.serviceAccountName" -}}
43+
{{- if .Values.serviceAccount.create -}}
44+
{{- if .Values.serviceAccount.name -}}
45+
{{- .Values.serviceAccount.name -}}
46+
{{- else -}}
47+
{{- include "nats-helper.fullname" . -}}
48+
{{- end -}}
49+
{{- else -}}
50+
{{- .Values.serviceAccount.name -}}
51+
{{- end -}}
52+
{{- end -}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "nats-helper.fullname" . }}-config
5+
labels:
6+
{{- include "nats-helper.labels" . | nindent 4 }}
7+
data:
8+
config.yaml: |-
9+
{{ .Values.config | indent 4 }}

0 commit comments

Comments
 (0)