Skip to content

Commit

Permalink
cyberchef: add initial chart (#47)
Browse files Browse the repository at this point in the history
* cyberchef: add initial chart

* remove infro

* fix typo

* add check if exists in main branch

* add check if exists in main branch

* add helm package

* add debug

* add debug

* add debug

* add debug

* add debug

* replace help with helm

* help

* help

* help

* now it should work

* now it should work

* add helm login

* add permissions

* add emptydir

* add port 80

* add port 80

* add run as user

* add run as user

* add run privilleged

* add image build

* add push on branch build

* add push on branch build

* fix output

* fix output

* remove deprecated output

* remove deprecated output

* add echo

* fix output steps

* use new image

* use new image

* use correct temp dir for unpriviliged image

* update image location
  • Loading branch information
FlorisFeddema authored Aug 8, 2024
1 parent f2ebc7d commit aae4123
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Charts
name: Build Helm Charts

on:
pull_request:
Expand Down Expand Up @@ -29,6 +29,10 @@ jobs:
runs-on: ubuntu-latest
needs: create-matrix

permissions:
contents: read
packages: write

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -66,6 +70,12 @@ jobs:

- name: Check for chart version change
run: |
if git cat-file -e origin/main:charts/${{ matrix.chart }}/Chart.yaml >/dev/null; then
echo "Chart exists in main branch"
else
echo "Chart does not exist in main branch"
exit 0
fi
old_version=$(git show origin/main:charts/${{ matrix.chart }}/Chart.yaml | yq eval ".version")
new_version=$(yq eval ".version" charts/${{ matrix.chart }}/Chart.yaml)
if [ "$old_version" == "$new_version" ]; then
Expand All @@ -76,6 +86,6 @@ jobs:
- name: Push chart to GHCR
run: |
version=$(yq eval ".version" charts/${{ matrix.chart }}/Chart.yaml)
yq e -i '.version = "env(version)-${{ github.base_ref }}.${{ github.run_id }}"' charts/${{ matrix.chart }}/Chart.yaml
echo "Pushing chart ${{ matrix.chart }} with version $version-${{ github.head_ref }}.${GITHUB_SHA::7}"
helm push "${{ matrix.chart }}" "oci://ghcr.io/${{ github.repository }}"
helm package charts/${{ matrix.chart }} --version "$version-${{ github.head_ref }}.${GITHUB_SHA::7}"
helm push "${{ matrix.chart }}-$version-${{ github.head_ref }}.${GITHUB_SHA::7}.tgz" "oci://ghcr.io/${{ github.repository }}"
100 changes: 100 additions & 0 deletions .github/workflows/image-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Build Images

on:
push:
paths:
- 'images/**'
pull_request:
paths:
- 'images/**'

jobs:
create-matrix:
runs-on: ubuntu-latest

outputs:
images: ${{ steps.images.outputs.images }}

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

- name: Create changed images matrix
id: images
run: |
images=$(git diff --merge-base origin/main --name-only | grep ^images/ | cut -d/ -f2 | uniq | sort | jq -R -s -c 'split("\n")[:-1]')
echo "images=${images}"
echo "images=${images}" >> "$GITHUB_OUTPUT"
build-images:
runs-on: ubuntu-latest
needs: create-matrix

permissions:
contents: read
packages: write

strategy:
fail-fast: false
matrix:
imageName: ${{ fromJSON(needs.create-matrix.outputs.images) }}

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

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get short SHA
id: sha
run: |
sha=$(echo "${GITHUB_SHA::7}")
echo "SHA=$sha"
echo "SHA=$sha" >> "$GITHUB_OUTPUT"
- name: Get version from Dockerfile
id: version
run: |
version=$(head -n 1 images/${{ matrix.imageName }}/Dockerfile | awk -F: '{print $NF}' | awk '{print $1}')
echo "VERSION=$version"
echo "VERSION=$version" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v6
if: github.ref == 'refs/heads/main'
with:
context: 'images/${{ matrix.imageName }}'
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.imageName }}:latest
ghcr.io/${{ github.repository_owner }}/${{ matrix.imageName }}:${{ steps.version.outputs.VERSION }}
push: true

- name: Build and push
uses: docker/build-push-action@v6
if: github.ref != 'refs/heads/main'
with:
context: 'images/${{ matrix.imageName }}'
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.imageName }}:${{ steps.version.outputs.VERSION }}-${{ github.head_ref }}.${{ steps.sha.outputs.SHA }}
push: true
23 changes: 23 additions & 0 deletions charts/cyberchef/.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/
3 changes: 3 additions & 0 deletions charts/cyberchef/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v2
name: cyberchef
version: 1.0.0
16 changes: 16 additions & 0 deletions charts/cyberchef/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Cyberchef

## How to use

Add repository by running:

```bash
helm repo add k8s-at-our-home https://k8s-at-our-homes.github.io/helm-charts/
helm install cyberchef k8s-at-our-home/cyberchef
```

Or get the chart from ghcr.io:

```bash
helm install cyberchef oci://ghcr.io/k8s-at-our-homes/helm-charts/cyberchef
```
31 changes: 31 additions & 0 deletions charts/cyberchef/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- define "common.name" -}}
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "common.fullname" -}}
{{- if contains .Chart.Name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{- define "chartName" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "common.selectorLabels" -}}
app.kubernetes.io/name: {{ template "common.name" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/part-of: "cyberchef"
{{- end -}}

{{- define "common.labels" -}}
app.kubernetes.io/name: {{ template "common.name" . }}
helm.sh/chart: {{ include "chartName" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Values.image.tag | quote }}
app.kubernetes.io/part-of: "cyberchef"
{{- end -}}
32 changes: 32 additions & 0 deletions charts/cyberchef/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "common.fullname" . }}
labels: {{- include "common.labels" . | nindent 4 }}
spec:
revisionHistoryLimit: 0
replicas: {{ .Values.replicas }}
selector:
matchLabels: {{- include "common.selectorLabels" . | nindent 6 }}
template:
metadata:
labels: {{- include "common.selectorLabels" . | nindent 8 }}
spec:
nodeSelector: {{ .Values.nodeSelector | toYaml | nindent 8 }}
securityContext: {{ toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: core
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 8080
protocol: TCP
resources: {{ toYaml .Values.resources | nindent 12 }}
securityContext: {{ toYaml .Values.securityContext | nindent 12 }}
volumeMounts:
- mountPath: /tmp/
name: cache
volumes:
- name: cache
emptyDir: {}
28 changes: 28 additions & 0 deletions charts/cyberchef/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{ if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ template "common.fullname" . }}
annotations: {{ toYaml .Values.ingress.annotations | nindent 4 }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
ingressClassName: {{ .Values.ingress.class }}
rules:
- host: {{ .Values.ingress.domain }}
http:
paths:
- backend:
service:
name: {{ template "common.fullname" . }}
port:
number: 8080
path: /
pathType: Prefix
{{- if .Values.ingress.tls.enabled }}
tls:
- hosts:
- {{ .Values.ingress.domain }}
secretName: {{ .Values.ingress.tls.secretName }}
{{- end }}
{{ end }}
15 changes: 15 additions & 0 deletions charts/cyberchef/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "common.fullname" . }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- name: http
targetPort: 8080
port: 8080
protocol: TCP
selector:
{{- include "common.selectorLabels" . | nindent 4 }}
38 changes: 38 additions & 0 deletions charts/cyberchef/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
replicas: 1

nodeSelector: {}

resources: {}
# requests:
# memory: 512Mi
# cpu: 100m
# limits:
# memory: 2048Mi

podSecurityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
runAsNonRoot: true

securityContext:
capabilities:
drop: [ "ALL" ]
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
privileged: false

image:
registry: ghcr.io
repository: k8s-at-our-homes/cyberchef
tag: 10.18.9
pullPolicy: IfNotPresent

ingress:
enabled: true
domain: cyberchef.example.com
class:
annotations: {}
tls:
enabled: true
secretName:
4 changes: 4 additions & 0 deletions images/cyberchef/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ghcr.io/gchq/cyberchef:10.18.9 AS build
FROM nginxinc/nginx-unprivileged:1.27.0-alpine3.19 AS run

COPY --from=build /usr/share/nginx/html /usr/share/nginx/html

0 comments on commit aae4123

Please sign in to comment.