Skip to content
Merged
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
90 changes: 90 additions & 0 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build and Release Auth Chart

on:
push:
branches:
- main
workflow_dispatch:

env:
IMAGE_NAME: auth
REGISTRY: ghcr.io
OCI_REPO: ghcr.io/abstractize
PROJECT_NAME: todo

jobs:
docker-build:
runs-on: ubuntu-latest
permissions:
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set lowercase env vars
id: set_env
run: |
USERNAME=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')
REPO_NAME=$(echo "${{ github.repository }}" | cut -d/ -f2 | tr '[:upper:]' '[:lower:]')
echo "USERNAME=$USERNAME" >> $GITHUB_ENV
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
echo "USERNAME=$USERNAME" >> $GITHUB_OUTPUT
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_OUTPUT

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

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: ./Dockerfile
push: true
build-args: |
GITHUB_USERNAME=${{ github.repository_owner }}
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
tags: |
${{ env.OCI_REPO }}/docker-images/${{ env.PROJECT_NAME }}/${{ env.IMAGE_NAME }}:latest
${{ env.OCI_REPO }}/docker-images/${{ env.PROJECT_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}

helm-release:
runs-on: ubuntu-latest
needs: docker-build
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Update Chart.yaml version and appVersion
run: |
sudo apt-get update && sudo apt-get install -y yq
VERSION="0.1.${GITHUB_RUN_NUMBER}"
yq -y -i ".appVersion = \"${GITHUB_SHA}\" | .version = \"$VERSION\"" .helm/Chart.yaml

- name: Lint Helm chart
run: helm lint .helm

- name: Package Helm chart
run: helm package .helm --destination .helm-dist

- name: Push Helm chart to GHCR (OCI)
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin
CHART_FILE=$(ls .helm-dist/*.tgz)
helm push $CHART_FILE oci://${{ env.OCI_REPO }}/helm-charts/${{ env.PROJECT_NAME }}
51 changes: 51 additions & 0 deletions .github/workflows/pr-validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PR Validation

on:
pull_request:
branches:
- main

jobs:
helm-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Helm lint
run: helm lint .helm

docker-build-test:
permissions:
contents: read
packages: write

runs-on: ubuntu-latest
needs: helm-lint
steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Build Docker image with secret
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: false
load: true
build-args: |
GITHUB_USERNAME=${{ github.repository_owner }}
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
tags: test-image:pr-${{ github.event.pull_request.number }}

- name: Run container test
run: docker run --rm --entrypoint sleep test-image:pr-${{ github.event.pull_request.number }} 5
23 changes: 23 additions & 0 deletions .helm/.helmignore
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/
7 changes: 7 additions & 0 deletions .helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: auth-service
description: Helm chart for the Auth Service of the TODO app
type: application
version: 0.1.0
appVersion: "latest"
icon: https://raw.githubusercontent.com/Abstractize/todo.auth/main/.helm/icons/auth.svg
7 changes: 7 additions & 0 deletions .helm/icons/auth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions .helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "auth-service.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 "auth-service.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 "auth-service.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "auth-service.labels" -}}
helm.sh/chart: {{ include "auth-service.chart" . }}
{{ include "auth-service.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "auth-service.selectorLabels" -}}
app.kubernetes.io/name: {{ include "auth-service.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "auth-service.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "auth-service.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
30 changes: 30 additions & 0 deletions .helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "auth-service.fullname" . }}
labels:
app: {{ include "auth-service.name" . }}
chart: {{ include "auth-service.chart" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ include "auth-service.name" . }}
template:
metadata:
labels:
app: {{ include "auth-service.name" . }}
spec:
containers:
- name: {{ include "auth-service.name" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.port }}
envFrom:
- configMapRef:
name: {{ .Values.configMapName }}
- secretRef:
name: {{ .Values.secretName }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
20 changes: 20 additions & 0 deletions .helm/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if .Values.hpa.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "auth-service.fullname" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "auth-service.fullname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
{{- end }}
15 changes: 15 additions & 0 deletions .helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "auth-service.fullname" . }}
labels:
app: {{ include "auth-service.name" . }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.port }}
protocol: TCP
name: http
selector:
app: {{ include "auth-service.name" . }}
16 changes: 16 additions & 0 deletions .helm/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "auth-service.fullname" . }}-test-connection"
labels:
app: {{ include "auth-service.name" . }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
containers:
- name: wget
image: busybox:1.36
command: ['wget']
args: ['-qO-', 'http://{{ include "auth-service.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
27 changes: 27 additions & 0 deletions .helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
replicaCount: 1

image:
repository: ghcr.io/abstractize/docker-images/todo/auth
tag: latest
pullPolicy: IfNotPresent

service:
type: ClusterIP
port: 8080

resources: {}

hpa:
enabled: true
minReplicas: 1
maxReplicas: 3
targetCPUUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}

configMapName: infra-config
secretName: infra-secrets
Loading