Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cyberchef: add initial chart #47

Merged
merged 39 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b2b7095
cyberchef: add initial chart
FlorisFeddema Aug 7, 2024
683a310
remove infro
FlorisFeddema Aug 7, 2024
43074de
fix typo
FlorisFeddema Aug 7, 2024
4c8810a
Merge branch 'refs/heads/main' into cyberchef-initial-setuo
FlorisFeddema Aug 7, 2024
8cac35b
add check if exists in main branch
FlorisFeddema Aug 7, 2024
7fd1404
add check if exists in main branch
FlorisFeddema Aug 7, 2024
e0b0269
add helm package
FlorisFeddema Aug 7, 2024
42519b2
add debug
FlorisFeddema Aug 7, 2024
103d8bb
add debug
FlorisFeddema Aug 7, 2024
ca27ef3
add debug
FlorisFeddema Aug 7, 2024
60b73b3
add debug
FlorisFeddema Aug 7, 2024
7c68a81
add debug
FlorisFeddema Aug 7, 2024
98dcfa8
replace help with helm
FlorisFeddema Aug 7, 2024
df7f7f5
help
FlorisFeddema Aug 7, 2024
5e314b1
help
FlorisFeddema Aug 7, 2024
df00857
help
FlorisFeddema Aug 7, 2024
ac794c7
now it should work
FlorisFeddema Aug 7, 2024
1573c37
now it should work
FlorisFeddema Aug 7, 2024
420ac91
add helm login
FlorisFeddema Aug 7, 2024
150d4c0
add permissions
FlorisFeddema Aug 7, 2024
0671919
add emptydir
FlorisFeddema Aug 7, 2024
fb6d29d
add port 80
FlorisFeddema Aug 7, 2024
10e8458
add port 80
FlorisFeddema Aug 7, 2024
7ee3b49
add run as user
FlorisFeddema Aug 7, 2024
d6deffd
add run as user
FlorisFeddema Aug 7, 2024
5fdfe75
add run privilleged
FlorisFeddema Aug 7, 2024
e466cbe
add image build
FlorisFeddema Aug 8, 2024
6576473
add push on branch build
FlorisFeddema Aug 8, 2024
bac6697
add push on branch build
FlorisFeddema Aug 8, 2024
b7a7d94
fix output
FlorisFeddema Aug 8, 2024
9ad9aa8
fix output
FlorisFeddema Aug 8, 2024
f5c624e
remove deprecated output
FlorisFeddema Aug 8, 2024
d8f426d
remove deprecated output
FlorisFeddema Aug 8, 2024
9dd3294
add echo
FlorisFeddema Aug 8, 2024
c42588a
fix output steps
FlorisFeddema Aug 8, 2024
ab60263
use new image
FlorisFeddema Aug 8, 2024
0bac0a9
use new image
FlorisFeddema Aug 8, 2024
b844539
use correct temp dir for unpriviliged image
FlorisFeddema Aug 8, 2024
820efdf
update image location
FlorisFeddema Aug 8, 2024
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
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
FlorisFeddema marked this conversation as resolved.
Show resolved Hide resolved
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