Skip to content

Commit

Permalink
chore: init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Oct 22, 2024
0 parents commit d9238c8
Show file tree
Hide file tree
Showing 30 changed files with 2,817 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Pull-Request Testing
on:
pull_request:
workflow_dispatch:

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build docker image
run: docker build .

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61.0
107 changes: 107 additions & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
on:
push:
branches:
- main
- release

permissions:
contents: write
pull-requests: write
packages: write

name: Release

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
version: ${{steps.release.outputs.version }}
release_created: ${{steps.release.outputs.release_created }}

steps:
- uses: actions/checkout@v4
- uses: googleapis/release-please-action@v4
id: release
with:
target-branch: 'release'

release-container:
runs-on: ubuntu-latest
needs: release-please
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
TAG: ${{ needs.release-please.outputs.version }}
steps:
- uses: actions/checkout@v4

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

- name: Log in to the 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
if: ${{needs.release-please.outputs.release_created == 'true'}}
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
platforms: |
linux/amd64
linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Extract metadata (tags, labels) for Docker
id: meta
if: ${{ needs.release-please.outputs.release_created != 'true' }}
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest-{{date 'YYYYMMDDHHmmss'}}-{{sha}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
if: ${{ needs.release-please.outputs.release_created != 'true' }}
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: |
linux/amd64
linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

release-helm:
runs-on: ubuntu-latest
needs: release-please
if: ${{needs.release-please.outputs.release_created == 'true'}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # important parameter

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v4
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
15 changes: 15 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
run:
timeout: 30m

linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- zerologlint

issues:
max-same-issues: 0
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "1.9.1"
}
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM --platform=$BUILDPLATFORM golang:1.23-alpine3.20 AS builder
# Define target arch variables so we can use them while crosscompiling, will be set automatically
ARG TARGETARCH
ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=${TARGETARCH}

WORKDIR /go/src/

# get dependencies
COPY go.mod go.sum ./
RUN go mod download

# copy code
COPY . .

# Build project
RUN go build -ldflags "-s -w" -a -installsuffix cgo -o /radix-ingress-default-backend

# Final stage, ref https://github.com/GoogleContainerTools/distroless/blob/main/base/README.md for distroless
FROM gcr.io/distroless/static
COPY www /www
COPY mime.types /etc/
COPY --from=builder /radix-ingress-default-backend /radix-ingress-default-backend

EXPOSE 8000
USER 1000
ENTRYPOINT ["/radix-ingress-default-backend"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Radix Ingress Defailt Backend

Responds with the default backend based on namespace header

## How we work

Commits to the main branch must follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) and uses Release Please to create new versions.

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
22 changes: 22 additions & 0 deletions charts/radix-ingress-deafult-backend/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
15 changes: 15 additions & 0 deletions charts/radix-ingress-deafult-backend/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: ingress-deafult-backend
icon: https://radix.equinor.com/images/logos/logo.svg
description: Simple Prometheus Proxy to expose a simple metric
version: 1.9.1
appVersion: 1.9.1
kubeVersion: '>=1.24.0'
keywords:
- radix
home: radix.equinor.com
sources:
- https://github.com/equinor/ingress-deafult-backend
maintainers:
- name: Omnia Radix
email: [email protected]
58 changes: 58 additions & 0 deletions charts/radix-ingress-deafult-backend/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "prometheus-proxy.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 "prometheus-proxy.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 "prometheus-proxy.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "prometheus-proxy.serviceAccountName" -}}
{{- default (include "prometheus-proxy.fullname" .) .Values.serviceAccount.name }}
{{- end }}
66 changes: 66 additions & 0 deletions charts/radix-ingress-deafult-backend/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "prometheus-proxy.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "prometheus-proxy.labels" . | nindent 4 }}
{{- with .Values.deploymentAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "prometheus-proxy.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "prometheus-proxy.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
supplementalGroups:
- 1000
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ default .Chart.Version .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 8000
name: http
env:
- name: LOG_PRETTY
value: {{ .Values.logPretty | quote }}
- name: LOG_LEVEL
value: {{ .Values.logLevel | quote }}
- name: PROMETHEUS
value: {{ .Values.prometheusUrl | quote }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
securityContext:
privileged: false
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
Loading

0 comments on commit d9238c8

Please sign in to comment.