From 0aef2ea3d6a7a76a643fdf7ab46a34177ec71f5e Mon Sep 17 00:00:00 2001 From: jency92 Date: Wed, 3 Jan 2024 14:56:04 +0530 Subject: [PATCH 01/10] added helm chart --- charts/.helmignore | 23 +++++ charts/Chart.yaml | 24 +++++ charts/templates/NOTES.txt | 22 +++++ charts/templates/_helpers.tpl | 62 +++++++++++++ charts/templates/deployment.yaml | 72 +++++++++++++++ charts/templates/hpa.yaml | 32 +++++++ charts/templates/ingress.yaml | 61 +++++++++++++ charts/templates/service.yaml | 15 ++++ charts/templates/serviceaccount.yaml | 13 +++ charts/templates/tests/test-connection.yaml | 15 ++++ charts/values.yaml | 98 +++++++++++++++++++++ 11 files changed, 437 insertions(+) create mode 100644 charts/.helmignore create mode 100644 charts/Chart.yaml create mode 100644 charts/templates/NOTES.txt create mode 100644 charts/templates/_helpers.tpl create mode 100644 charts/templates/deployment.yaml create mode 100644 charts/templates/hpa.yaml create mode 100644 charts/templates/ingress.yaml create mode 100644 charts/templates/service.yaml create mode 100644 charts/templates/serviceaccount.yaml create mode 100644 charts/templates/tests/test-connection.yaml create mode 100644 charts/values.yaml diff --git a/charts/.helmignore b/charts/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/.helmignore @@ -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/ diff --git a/charts/Chart.yaml b/charts/Chart.yaml new file mode 100644 index 0000000..14f969e --- /dev/null +++ b/charts/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: scsctl +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/charts/templates/NOTES.txt b/charts/templates/NOTES.txt new file mode 100644 index 0000000..4081898 --- /dev/null +++ b/charts/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "scsctl.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "scsctl.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "scsctl.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "scsctl.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl new file mode 100644 index 0000000..86d08bf --- /dev/null +++ b/charts/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "scsctl.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 "scsctl.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 "scsctl.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "scsctl.labels" -}} +helm.sh/chart: {{ include "scsctl.chart" . }} +{{ include "scsctl.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "scsctl.selectorLabels" -}} +app.kubernetes.io/name: {{ include "scsctl.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "scsctl.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "scsctl.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml new file mode 100644 index 0000000..5225c81 --- /dev/null +++ b/charts/templates/deployment.yaml @@ -0,0 +1,72 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "scsctl.fullname" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "scsctl.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "scsctl.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "scsctl.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/templates/hpa.yaml b/charts/templates/hpa.yaml new file mode 100644 index 0000000..155c1df --- /dev/null +++ b/charts/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "scsctl.fullname" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "scsctl.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/templates/ingress.yaml b/charts/templates/ingress.yaml new file mode 100644 index 0000000..25d5ffa --- /dev/null +++ b/charts/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "scsctl.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/templates/service.yaml b/charts/templates/service.yaml new file mode 100644 index 0000000..b7bbaac --- /dev/null +++ b/charts/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "scsctl.fullname" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "scsctl.selectorLabels" . | nindent 4 }} diff --git a/charts/templates/serviceaccount.yaml b/charts/templates/serviceaccount.yaml new file mode 100644 index 0000000..049bdb4 --- /dev/null +++ b/charts/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "scsctl.serviceAccountName" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/templates/tests/test-connection.yaml b/charts/templates/tests/test-connection.yaml new file mode 100644 index 0000000..fdfbb94 --- /dev/null +++ b/charts/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "scsctl.fullname" . }}-test-connection" + labels: + {{- include "scsctl.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "scsctl.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/values.yaml b/charts/values.yaml new file mode 100644 index 0000000..eabd6d0 --- /dev/null +++ b/charts/values.yaml @@ -0,0 +1,98 @@ +# Default values for scsctl. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: python:3.10-slim@sha256 + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "latest" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} From 59c48a1b12fdeb1cb143a0427f439dcabd5a74cf Mon Sep 17 00:00:00 2001 From: jency92 Date: Wed, 3 Jan 2024 15:06:26 +0530 Subject: [PATCH 02/10] added helm release --- .github/workflows/helm_release.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/helm_release.yml diff --git a/.github/workflows/helm_release.yml b/.github/workflows/helm_release.yml new file mode 100644 index 0000000..597ddaf --- /dev/null +++ b/.github/workflows/helm_release.yml @@ -0,0 +1,30 @@ +name: Helm Chart publish + +on: + push: + paths: + - 'charts/**' + branches: + - main +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@@gmail.com" + + - name: Add Helm repos + run: | + helm repo add tools https://kube-tarian.github.io/helmrepo-supporting-tools + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.1.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" From 9f5ee3266d87b2a04968f8979799d4e6d8960b57 Mon Sep 17 00:00:00 2001 From: jency92 Date: Wed, 3 Jan 2024 15:11:50 +0530 Subject: [PATCH 03/10] updated helm relaese --- .github/workflows/helm_release.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/helm_release.yml b/.github/workflows/helm_release.yml index 597ddaf..d612cd6 100644 --- a/.github/workflows/helm_release.yml +++ b/.github/workflows/helm_release.yml @@ -20,10 +20,6 @@ jobs: git config user.name "$GITHUB_ACTOR" git config user.email "$GITHUB_ACTOR@@gmail.com" - - name: Add Helm repos - run: | - helm repo add tools https://kube-tarian.github.io/helmrepo-supporting-tools - - name: Run chart-releaser uses: helm/chart-releaser-action@v1.1.0 env: From 6ec4de5eaf37ad1382507767d588e143993c20a5 Mon Sep 17 00:00:00 2001 From: jency92 Date: Tue, 9 Jan 2024 17:04:27 +0530 Subject: [PATCH 04/10] container release --- .github/workflows/container-pr.yml | 48 ++++++++++++++ .github/workflows/container-release.yml | 58 +++++++++++++++++ .github/workflows/container.yml | 83 +++++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 .github/workflows/container-pr.yml create mode 100644 .github/workflows/container-release.yml create mode 100644 .github/workflows/container.yml diff --git a/.github/workflows/container-pr.yml b/.github/workflows/container-pr.yml new file mode 100644 index 0000000..5c61e53 --- /dev/null +++ b/.github/workflows/container-pr.yml @@ -0,0 +1,48 @@ +name: Container Agent Docker Image CI + +on: + pull_request: + branches: + - 'main' + +jobs: + build: + runs-on: ubuntu-latest + env: + REGISTRY: ghcr.io + GH_URL: https://github.com + steps: + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - uses: docker/setup-buildx-action@v1 + name: Set up Docker Buildx + + - + name: Login to ghcr registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + + - + name: Build and push on PR + uses: docker/build-push-action@v4 + if: github.event_name == 'pull_request' + with: + context: . + file: ./dockerfiles/agent/container/Dockerfile + push: true + tags: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:pr-${{ github.event.pull_request.number }} + build-args: | + "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" + diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.yml new file mode 100644 index 0000000..c907d29 --- /dev/null +++ b/.github/workflows/container-release.yml @@ -0,0 +1,58 @@ +name: container-agent-release +on: + push: + tags: + - "v*.*.*" +jobs: + push_to_registry: + name: Build and push Docker image github container registry. + runs-on: ubuntu-20.04 + permissions: + packages: write + id-token: write + contents: read + actions: read + security-events: write + env: + REGISTRY: ghcr.io + GH_URL: https://github.com + steps: + - name: Set environment variable + run: | + echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV + - name: Test environment variable + run: echo ${{ env.RELEASE_VERSION }} + - name: Check out GitHub repo + uses: actions/checkout@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build image and push to GitHub Container Registry + uses: docker/build-push-action@v4 + with: + push: true + context: ./ + file: ./dockerfiles/agent/container/Dockerfile + tags: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ env.RELEASE_VERSION }} + - name: Install cosign + uses: sigstore/cosign-installer@main + - name: Sign the images + run: | + cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ env.RELEASE_VERSION }} + env: + COSIGN_EXPERIMENTAL: 1 + - name: Verify the pushed tags + run: cosign verify ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ env.RELEASE_VERSION }} --certificate-identity ${{ env.GH_URL }}/${{ github.repository }}/.github/workflows/agent-container-release.yml@refs/tags/${{ env.RELEASE_VERSION }} --certificate-oidc-issuer https://token.actions.githubusercontent.com + env: + COSIGN_EXPERIMENTAL: 1 + - name: Run Trivy in GitHub SBOM mode and submit results to Dependency Graph + uses: aquasecurity/trivy-action@master + with: + scan-type: 'fs' + format: 'github' + output: 'dependency-results.sbom.json' + image-ref: '.' + github-pat: ${{ secrets.GITHUB_TOKEN }} # or ${{ secrets.github_pat_name }} if you're using a PAT diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 0000000..cf023c6 --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,83 @@ +name: Container Agent Docker Image CI + +on: + push: + paths-ignore: + - '**.md' + - 'charts/**' + branches: + - 'main' + +jobs: + + build: + + runs-on: ubuntu-latest + permissions: + packages: write + id-token: write + contents: read + actions: read + security-events: write + env: + REGISTRY: ghcr.io + GH_URL: https://github.com + steps: + - name: Checkout GitHub Action + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker metadata + id: metadata + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }} + flavor: | + latest=true + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build image and push to GitHub Container Registry + uses: docker/build-push-action@v4 + with: + context: . + file: ./dockerfiles/agent/container/Dockerfile + tags: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ github.run_id }} + labels: ${{ steps.metadata.outputs.labels }} + + push: true + + - name: Install cosign + uses: sigstore/cosign-installer@main + + - name: Sign the images + run: | + cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ github.run_id }} + env: + COSIGN_EXPERIMENTAL: 1 + + - name: Verify the pushed tags + run: cosign verify ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ github.run_id }} --certificate-identity ${{ env.GH_URL }}/${{ github.repository }}/.github/workflows/agent-container.yml@refs/heads/main --certificate-oidc-issuer https://token.actions.githubusercontent.com + env: + COSIGN_EXPERIMENTAL: 1 + + - name: Run Trivy in GitHub SBOM mode and submit results to Dependency Graph + uses: aquasecurity/trivy-action@master + with: + scan-type: 'fs' + format: 'github' + output: 'dependency-results.sbom.json' + image-ref: '.' + github-pat: ${{ secrets.GITHUB_TOKEN }} From 784389e3c4d86580c6b8ea53f64ee0afa2de87f8 Mon Sep 17 00:00:00 2001 From: jency92 Date: Tue, 9 Jan 2024 17:08:20 +0530 Subject: [PATCH 05/10] change dir structure --- charts/scsctl/Chart.yaml | 24 +++++ charts/scsctl/templates/NOTES.txt | 22 +++++ charts/scsctl/templates/_helpers.tpl | 62 ++++++++++++ charts/scsctl/templates/deployment.yaml | 72 ++++++++++++++ charts/scsctl/templates/hpa.yaml | 32 ++++++ charts/scsctl/templates/ingress.yaml | 61 ++++++++++++ charts/scsctl/templates/service.yaml | 15 +++ charts/scsctl/templates/serviceaccount.yaml | 13 +++ .../templates/tests/test-connection.yaml | 15 +++ charts/scsctl/values.yaml | 98 +++++++++++++++++++ 10 files changed, 414 insertions(+) create mode 100644 charts/scsctl/Chart.yaml create mode 100644 charts/scsctl/templates/NOTES.txt create mode 100644 charts/scsctl/templates/_helpers.tpl create mode 100644 charts/scsctl/templates/deployment.yaml create mode 100644 charts/scsctl/templates/hpa.yaml create mode 100644 charts/scsctl/templates/ingress.yaml create mode 100644 charts/scsctl/templates/service.yaml create mode 100644 charts/scsctl/templates/serviceaccount.yaml create mode 100644 charts/scsctl/templates/tests/test-connection.yaml create mode 100644 charts/scsctl/values.yaml diff --git a/charts/scsctl/Chart.yaml b/charts/scsctl/Chart.yaml new file mode 100644 index 0000000..14f969e --- /dev/null +++ b/charts/scsctl/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: scsctl +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/charts/scsctl/templates/NOTES.txt b/charts/scsctl/templates/NOTES.txt new file mode 100644 index 0000000..4081898 --- /dev/null +++ b/charts/scsctl/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "scsctl.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "scsctl.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "scsctl.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "scsctl.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/scsctl/templates/_helpers.tpl b/charts/scsctl/templates/_helpers.tpl new file mode 100644 index 0000000..86d08bf --- /dev/null +++ b/charts/scsctl/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "scsctl.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 "scsctl.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 "scsctl.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "scsctl.labels" -}} +helm.sh/chart: {{ include "scsctl.chart" . }} +{{ include "scsctl.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "scsctl.selectorLabels" -}} +app.kubernetes.io/name: {{ include "scsctl.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "scsctl.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "scsctl.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/scsctl/templates/deployment.yaml b/charts/scsctl/templates/deployment.yaml new file mode 100644 index 0000000..5225c81 --- /dev/null +++ b/charts/scsctl/templates/deployment.yaml @@ -0,0 +1,72 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "scsctl.fullname" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "scsctl.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "scsctl.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "scsctl.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/scsctl/templates/hpa.yaml b/charts/scsctl/templates/hpa.yaml new file mode 100644 index 0000000..155c1df --- /dev/null +++ b/charts/scsctl/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "scsctl.fullname" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "scsctl.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/scsctl/templates/ingress.yaml b/charts/scsctl/templates/ingress.yaml new file mode 100644 index 0000000..25d5ffa --- /dev/null +++ b/charts/scsctl/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "scsctl.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/scsctl/templates/service.yaml b/charts/scsctl/templates/service.yaml new file mode 100644 index 0000000..b7bbaac --- /dev/null +++ b/charts/scsctl/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "scsctl.fullname" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "scsctl.selectorLabels" . | nindent 4 }} diff --git a/charts/scsctl/templates/serviceaccount.yaml b/charts/scsctl/templates/serviceaccount.yaml new file mode 100644 index 0000000..049bdb4 --- /dev/null +++ b/charts/scsctl/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "scsctl.serviceAccountName" . }} + labels: + {{- include "scsctl.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/scsctl/templates/tests/test-connection.yaml b/charts/scsctl/templates/tests/test-connection.yaml new file mode 100644 index 0000000..fdfbb94 --- /dev/null +++ b/charts/scsctl/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "scsctl.fullname" . }}-test-connection" + labels: + {{- include "scsctl.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "scsctl.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/scsctl/values.yaml b/charts/scsctl/values.yaml new file mode 100644 index 0000000..eabd6d0 --- /dev/null +++ b/charts/scsctl/values.yaml @@ -0,0 +1,98 @@ +# Default values for scsctl. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: python:3.10-slim@sha256 + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "latest" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} From 52e3fb234f2cbe68b8057e0f7c5f5602b0898129 Mon Sep 17 00:00:00 2001 From: jency92 Date: Tue, 9 Jan 2024 17:12:42 +0530 Subject: [PATCH 06/10] updated dir structre --- charts/Chart.yaml | 24 ----- charts/templates/NOTES.txt | 22 ----- charts/templates/_helpers.tpl | 62 ------------- charts/templates/deployment.yaml | 72 --------------- charts/templates/hpa.yaml | 32 ------- charts/templates/ingress.yaml | 61 ------------- charts/templates/service.yaml | 15 ---- charts/templates/serviceaccount.yaml | 13 --- charts/templates/tests/test-connection.yaml | 15 ---- charts/values.yaml | 98 --------------------- 10 files changed, 414 deletions(-) delete mode 100644 charts/Chart.yaml delete mode 100644 charts/templates/NOTES.txt delete mode 100644 charts/templates/_helpers.tpl delete mode 100644 charts/templates/deployment.yaml delete mode 100644 charts/templates/hpa.yaml delete mode 100644 charts/templates/ingress.yaml delete mode 100644 charts/templates/service.yaml delete mode 100644 charts/templates/serviceaccount.yaml delete mode 100644 charts/templates/tests/test-connection.yaml delete mode 100644 charts/values.yaml diff --git a/charts/Chart.yaml b/charts/Chart.yaml deleted file mode 100644 index 14f969e..0000000 --- a/charts/Chart.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v2 -name: scsctl -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. Versions are not expected to -# follow Semantic Versioning. They should reflect the version the application is using. -# It is recommended to use it with quotes. -appVersion: "1.16.0" diff --git a/charts/templates/NOTES.txt b/charts/templates/NOTES.txt deleted file mode 100644 index 4081898..0000000 --- a/charts/templates/NOTES.txt +++ /dev/null @@ -1,22 +0,0 @@ -1. Get the application URL by running these commands: -{{- if .Values.ingress.enabled }} -{{- range $host := .Values.ingress.hosts }} - {{- range .paths }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} - {{- end }} -{{- end }} -{{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "scsctl.fullname" . }}) - export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") - echo http://$NODE_IP:$NODE_PORT -{{- else if contains "LoadBalancer" .Values.service.type }} - NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "scsctl.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "scsctl.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} -{{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "scsctl.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") - echo "Visit http://127.0.0.1:8080 to use your application" - kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT -{{- end }} diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl deleted file mode 100644 index 86d08bf..0000000 --- a/charts/templates/_helpers.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "scsctl.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 "scsctl.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 "scsctl.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "scsctl.labels" -}} -helm.sh/chart: {{ include "scsctl.chart" . }} -{{ include "scsctl.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "scsctl.selectorLabels" -}} -app.kubernetes.io/name: {{ include "scsctl.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "scsctl.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "scsctl.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml deleted file mode 100644 index 5225c81..0000000 --- a/charts/templates/deployment.yaml +++ /dev/null @@ -1,72 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "scsctl.fullname" . }} - labels: - {{- include "scsctl.labels" . | nindent 4 }} -spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.replicaCount }} - {{- end }} - selector: - matchLabels: - {{- include "scsctl.selectorLabels" . | nindent 6 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "scsctl.labels" . | nindent 8 }} - {{- with .Values.podLabels }} - {{- toYaml . | nindent 8 }} - {{- end }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - serviceAccountName: {{ include "scsctl.serviceAccountName" . }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - livenessProbe: - httpGet: - path: / - port: http - readinessProbe: - httpGet: - path: / - port: http - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.volumeMounts }} - volumeMounts: - {{- toYaml . | nindent 12 }} - {{- end }} - {{- with .Values.volumes }} - volumes: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/charts/templates/hpa.yaml b/charts/templates/hpa.yaml deleted file mode 100644 index 155c1df..0000000 --- a/charts/templates/hpa.yaml +++ /dev/null @@ -1,32 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - name: {{ include "scsctl.fullname" . }} - labels: - {{- include "scsctl.labels" . | nindent 4 }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ include "scsctl.fullname" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: - {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- end }} - {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory - target: - type: Utilization - averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- end }} -{{- end }} diff --git a/charts/templates/ingress.yaml b/charts/templates/ingress.yaml deleted file mode 100644 index 25d5ffa..0000000 --- a/charts/templates/ingress.yaml +++ /dev/null @@ -1,61 +0,0 @@ -{{- if .Values.ingress.enabled -}} -{{- $fullName := include "scsctl.fullname" . -}} -{{- $svcPort := .Values.service.port -}} -{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} - {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} - {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} - {{- end }} -{{- end }} -{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1 -{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else -}} -apiVersion: extensions/v1beta1 -{{- end }} -kind: Ingress -metadata: - name: {{ $fullName }} - labels: - {{- include "scsctl.labels" . | nindent 4 }} - {{- with .Values.ingress.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} - ingressClassName: {{ .Values.ingress.className }} - {{- end }} - {{- if .Values.ingress.tls }} - tls: - {{- range .Values.ingress.tls }} - - hosts: - {{- range .hosts }} - - {{ . | quote }} - {{- end }} - secretName: {{ .secretName }} - {{- end }} - {{- end }} - rules: - {{- range .Values.ingress.hosts }} - - host: {{ .host | quote }} - http: - paths: - {{- range .paths }} - - path: {{ .path }} - {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} - pathType: {{ .pathType }} - {{- end }} - backend: - {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} - service: - name: {{ $fullName }} - port: - number: {{ $svcPort }} - {{- else }} - serviceName: {{ $fullName }} - servicePort: {{ $svcPort }} - {{- end }} - {{- end }} - {{- end }} -{{- end }} diff --git a/charts/templates/service.yaml b/charts/templates/service.yaml deleted file mode 100644 index b7bbaac..0000000 --- a/charts/templates/service.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "scsctl.fullname" . }} - labels: - {{- include "scsctl.labels" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "scsctl.selectorLabels" . | nindent 4 }} diff --git a/charts/templates/serviceaccount.yaml b/charts/templates/serviceaccount.yaml deleted file mode 100644 index 049bdb4..0000000 --- a/charts/templates/serviceaccount.yaml +++ /dev/null @@ -1,13 +0,0 @@ -{{- if .Values.serviceAccount.create -}} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "scsctl.serviceAccountName" . }} - labels: - {{- include "scsctl.labels" . | nindent 4 }} - {{- with .Values.serviceAccount.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -automountServiceAccountToken: {{ .Values.serviceAccount.automount }} -{{- end }} diff --git a/charts/templates/tests/test-connection.yaml b/charts/templates/tests/test-connection.yaml deleted file mode 100644 index fdfbb94..0000000 --- a/charts/templates/tests/test-connection.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ include "scsctl.fullname" . }}-test-connection" - labels: - {{- include "scsctl.labels" . | nindent 4 }} - annotations: - "helm.sh/hook": test -spec: - containers: - - name: wget - image: busybox - command: ['wget'] - args: ['{{ include "scsctl.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never diff --git a/charts/values.yaml b/charts/values.yaml deleted file mode 100644 index eabd6d0..0000000 --- a/charts/values.yaml +++ /dev/null @@ -1,98 +0,0 @@ -# Default values for scsctl. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: - repository: python:3.10-slim@sha256 - pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "latest" - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # Automatically mount a ServiceAccount's API credentials? - automount: true - # Annotations to add to the service account - annotations: {} - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: "" - -podAnnotations: {} -podLabels: {} - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 80 - -ingress: - enabled: false - className: "" - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: - - path: / - pathType: ImplementationSpecific - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - # limits: - # cpu: 100m - # memory: 128Mi - # requests: - # cpu: 100m - # memory: 128Mi - -autoscaling: - enabled: false - minReplicas: 1 - maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 - -# Additional volumes on the output Deployment definition. -volumes: [] -# - name: foo -# secret: -# secretName: mysecret -# optional: false - -# Additional volumeMounts on the output Deployment definition. -volumeMounts: [] -# - name: foo -# mountPath: "/etc/foo" -# readOnly: true - -nodeSelector: {} - -tolerations: [] - -affinity: {} From ed14f73eab4851fd5dfa19f3a3909e5075b5257b Mon Sep 17 00:00:00 2001 From: jency92 Date: Wed, 10 Jan 2024 02:03:34 +0530 Subject: [PATCH 07/10] modified container image --- .github/workflows/container-pr.yml | 6 +++--- .github/workflows/container-release.yml | 10 +++++----- .github/workflows/container.yml | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/container-pr.yml b/.github/workflows/container-pr.yml index 5c61e53..9537235 100644 --- a/.github/workflows/container-pr.yml +++ b/.github/workflows/container-pr.yml @@ -1,4 +1,4 @@ -name: Container Agent Docker Image CI +name: Container Docker Image CI on: pull_request: @@ -40,9 +40,9 @@ jobs: if: github.event_name == 'pull_request' with: context: . - file: ./dockerfiles/agent/container/Dockerfile + file: ./Dockerfile push: true - tags: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:pr-${{ github.event.pull_request.number }} + tags: ${{ env.REGISTRY }}/${{ github.repository }}${{ github.event.pull_request.number }} build-args: | "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.yml index c907d29..16d3f14 100644 --- a/.github/workflows/container-release.yml +++ b/.github/workflows/container-release.yml @@ -1,4 +1,4 @@ -name: container-agent-release +name: container-release on: push: tags: @@ -35,17 +35,17 @@ jobs: with: push: true context: ./ - file: ./dockerfiles/agent/container/Dockerfile - tags: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ env.RELEASE_VERSION }} + file: ./Dockerfile + tags: ${{ env.REGISTRY }}/${{ github.repository }}:${{ env.RELEASE_VERSION }} - name: Install cosign uses: sigstore/cosign-installer@main - name: Sign the images run: | - cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ env.RELEASE_VERSION }} + cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}/container-release:${{ env.RELEASE_VERSION }} env: COSIGN_EXPERIMENTAL: 1 - name: Verify the pushed tags - run: cosign verify ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ env.RELEASE_VERSION }} --certificate-identity ${{ env.GH_URL }}/${{ github.repository }}/.github/workflows/agent-container-release.yml@refs/tags/${{ env.RELEASE_VERSION }} --certificate-oidc-issuer https://token.actions.githubusercontent.com + run: cosign verify ${{ env.REGISTRY }}/${{ github.repository }}:${{ env.RELEASE_VERSION }} --certificate-identity ${{ env.GH_URL }}/${{ github.repository }}/.github/workflows/container-release.yml@refs/tags/${{ env.RELEASE_VERSION }} --certificate-oidc-issuer https://token.actions.githubusercontent.com env: COSIGN_EXPERIMENTAL: 1 - name: Run Trivy in GitHub SBOM mode and submit results to Dependency Graph diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index cf023c6..5faedbe 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -34,7 +34,7 @@ jobs: id: metadata uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent + images: ${{ env.REGISTRY }}/${{ github.repository }} tags: | type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} @@ -53,8 +53,8 @@ jobs: uses: docker/build-push-action@v4 with: context: . - file: ./dockerfiles/agent/container/Dockerfile - tags: ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ github.run_id }} + file: ./Dockerfile + tags: ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.run_id }} labels: ${{ steps.metadata.outputs.labels }} push: true @@ -64,12 +64,12 @@ jobs: - name: Sign the images run: | - cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ github.run_id }} + cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.run_id }} env: COSIGN_EXPERIMENTAL: 1 - name: Verify the pushed tags - run: cosign verify ${{ env.REGISTRY }}/${{ github.repository }}/container-agent:${{ github.run_id }} --certificate-identity ${{ env.GH_URL }}/${{ github.repository }}/.github/workflows/agent-container.yml@refs/heads/main --certificate-oidc-issuer https://token.actions.githubusercontent.com + run: cosign verify ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.run_id }} --certificate-identity ${{ env.GH_URL }}/${{ github.repository }}/.github/workflows/container.yml@refs/heads/main --certificate-oidc-issuer https://token.actions.githubusercontent.com env: COSIGN_EXPERIMENTAL: 1 From e22bf6cf3f00d71ca841b3324b022a05bac27401 Mon Sep 17 00:00:00 2001 From: jency92 Date: Wed, 10 Jan 2024 02:11:43 +0530 Subject: [PATCH 08/10] fix: modified image path --- .github/workflows/container-release.yml | 2 +- .github/workflows/container.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.yml index 16d3f14..3d0bf6a 100644 --- a/.github/workflows/container-release.yml +++ b/.github/workflows/container-release.yml @@ -41,7 +41,7 @@ jobs: uses: sigstore/cosign-installer@main - name: Sign the images run: | - cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}/container-release:${{ env.RELEASE_VERSION }} + cosign sign -y ${{ env.REGISTRY }}/${{ github.repository }}:${{ env.RELEASE_VERSION }} env: COSIGN_EXPERIMENTAL: 1 - name: Verify the pushed tags diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 5faedbe..ea81684 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -1,4 +1,4 @@ -name: Container Agent Docker Image CI +name: Container Docker Image CI on: push: From 974956d8f68557c2df7c3b0db1d7f741b1111291 Mon Sep 17 00:00:00 2001 From: jebjohns <111633983+jebjohns@users.noreply.github.com> Date: Wed, 10 Jan 2024 02:14:29 +0530 Subject: [PATCH 09/10] Update container-pr.yml Signed-off-by: jebjohns <111633983+jebjohns@users.noreply.github.com> --- .github/workflows/container-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-pr.yml b/.github/workflows/container-pr.yml index 9537235..fd8bb81 100644 --- a/.github/workflows/container-pr.yml +++ b/.github/workflows/container-pr.yml @@ -1,4 +1,4 @@ -name: Container Docker Image CI +name: scsctl Container image build for PR on: pull_request: From 9e5ee34054481bdcc3d04c3916b8c304ece7f17e Mon Sep 17 00:00:00 2001 From: jebjohns <111633983+jebjohns@users.noreply.github.com> Date: Wed, 10 Jan 2024 02:15:08 +0530 Subject: [PATCH 10/10] Update container-release.yml Signed-off-by: jebjohns <111633983+jebjohns@users.noreply.github.com> --- .github/workflows/container-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.yml index 3d0bf6a..4eeb6fa 100644 --- a/.github/workflows/container-release.yml +++ b/.github/workflows/container-release.yml @@ -1,4 +1,4 @@ -name: container-release +name: scsctl container image release on: push: tags: