Add multi-mode HTML, Docker, Helm chart, and deploy script
All checks were successful
Build and Deploy / build (push) Successful in 46s

- Add shop-mode.html and project-mode.html for separate calculation
modes - Refactor index.html as a landing page for mode selection - Add
Dockerfile with optimized nginx config and healthcheck - Add
.dockerignore for cleaner Docker builds - Add deploy.sh for
Helm/Kubernetes deployment automation - Add helm-chart/ with
values.yaml, Chart.yaml, templates, and documentation - Update README.md
with full instructions, features, and CI/CD examples
This commit is contained in:
d.viti
2025-10-13 23:25:33 +02:00
parent 68d1c91456
commit 23ec5d5f32
14 changed files with 4021 additions and 1553 deletions

26
helm-chart/.helmignore Normal file
View File

@@ -0,0 +1,26 @@
# 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/
# Custom
README.md
.helmignore

26
helm-chart/Chart.yaml Normal file
View File

@@ -0,0 +1,26 @@
apiVersion: v2
name: calcolatore-prezzi-software
description: A Helm chart for Calcolatore Prezzi Software application
type: application
version: 1.0.0
appVersion: "1.0.0"
# Dependency on base-helm common chart
dependencies:
- name: base-helm
version: "*"
repository: "https://git.commandware.com/GitOps/base-helm.git"
alias: common
maintainers:
- name: Your Name
email: your-email@example.com
keywords:
- calculator
- pricing
- software
- static-website
sources:
- https://github.com/your-repo/calcolatore-prezzi-software

300
helm-chart/README.md Normal file
View File

@@ -0,0 +1,300 @@
# Calcolatore Prezzi Software - Helm Chart
Questo è un Helm chart semplificato per il deploy del Calcolatore Prezzi Software che utilizza il [base-helm](https://git.commandware.com/GitOps/base-helm.git) come chart comune.
## Prerequisiti
- Kubernetes 1.19+
- Helm 3.0+
- Nginx Ingress Controller (opzionale, per l'ingress)
- Cert-manager (opzionale, per i certificati SSL)
## Installazione
### 1. Aggiornare le dipendenze
Prima di installare il chart, è necessario aggiornare le dipendenze per scaricare il base-helm:
```bash
cd helm-chart
helm dependency update
```
### 2. Installazione base
```bash
helm install calcolatore-prezzi ./helm-chart
```
### 3. Installazione con valori personalizzati
```bash
helm install calcolatore-prezzi ./helm-chart -f custom-values.yaml
```
### 4. Installazione con file HTML personalizzati
Per iniettare i tuoi file HTML durante l'installazione:
```bash
helm install calcolatore-prezzi ./helm-chart \
--set-file configMaps.html-content.data.index\.html=./index.html \
--set-file configMaps.html-content.data.shop-mode\.html=./shop-mode.html
```
### 5. Installazione in un namespace specifico
```bash
kubectl create namespace calcolatore
helm install calcolatore-prezzi ./helm-chart -n calcolatore
```
## Configurazione
I seguenti parametri possono essere configurati nel file `values.yaml`:
### Parametri Applicazione
| Parametro | Descrizione | Default |
|-----------|-------------|---------|
| `replicaCount` | Numero di repliche del pod | `2` |
| `image.repository` | Repository dell'immagine Docker | `nginx` |
| `image.tag` | Tag dell'immagine Docker | `alpine` |
| `image.pullPolicy` | Policy di pull dell'immagine | `IfNotPresent` |
### Parametri Service
| Parametro | Descrizione | Default |
|-----------|-------------|---------|
| `service.type` | Tipo di service Kubernetes | `ClusterIP` |
| `service.port` | Porta del service | `80` |
| `service.targetPort` | Porta target del container | `80` |
### Parametri Ingress
| Parametro | Descrizione | Default |
|-----------|-------------|---------|
| `ingress.enabled` | Abilita l'ingress | `true` |
| `ingress.className` | Classe dell'ingress controller | `nginx` |
| `ingress.hosts[0].host` | Hostname per l'ingress | `calcolatore.example.com` |
| `ingress.tls[0].secretName` | Nome del secret TLS | `calcolatore-tls` |
### Parametri Risorse
| Parametro | Descrizione | Default |
|-----------|-------------|---------|
| `resources.limits.cpu` | Limite CPU | `200m` |
| `resources.limits.memory` | Limite memoria | `256Mi` |
| `resources.requests.cpu` | Request CPU | `100m` |
| `resources.requests.memory` | Request memoria | `128Mi` |
### Parametri Autoscaling
| Parametro | Descrizione | Default |
|-----------|-------------|---------|
| `autoscaling.enabled` | Abilita l'HPA | `false` |
| `autoscaling.minReplicas` | Numero minimo di repliche | `2` |
| `autoscaling.maxReplicas` | Numero massimo di repliche | `5` |
| `autoscaling.targetCPUUtilizationPercentage` | Target CPU per scaling | `80` |
## Esempi di Configurazione
### values-production.yaml
```yaml
replicaCount: 3
image:
repository: your-registry.io/calcolatore-prezzi
tag: "1.0.0"
pullPolicy: Always
ingress:
enabled: true
className: "nginx"
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/rate-limit: "100"
hosts:
- host: calcolatore.yourdomain.com
paths:
- path: /
pathType: Prefix
tls:
- secretName: calcolatore-prod-tls
hosts:
- calcolatore.yourdomain.com
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 250m
memory: 256Mi
autoscaling:
enabled: true
minReplicas: 3
maxReplicas: 10
targetCPUUtilizationPercentage: 70
podDisruptionBudget:
enabled: true
minAvailable: 2
```
### values-development.yaml
```yaml
replicaCount: 1
image:
repository: nginx
tag: "alpine"
pullPolicy: IfNotPresent
ingress:
enabled: true
className: "nginx"
hosts:
- host: calcolatore.dev.local
paths:
- path: /
pathType: Prefix
tls: []
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
autoscaling:
enabled: false
```
## Aggiornamento
Per aggiornare il deployment:
```bash
helm upgrade calcolatore-prezzi ./helm-chart
```
Con file HTML aggiornati:
```bash
helm upgrade calcolatore-prezzi ./helm-chart \
--set-file configMaps.html-content.data.index\.html=./index.html \
--set-file configMaps.html-content.data.shop-mode\.html=./shop-mode.html
```
## Disinstallazione
```bash
helm uninstall calcolatore-prezzi
```
## Testing
Per testare il chart senza installarlo:
```bash
# Dry run
helm install calcolatore-prezzi ./helm-chart --dry-run --debug
# Template rendering
helm template calcolatore-prezzi ./helm-chart
# Lint
helm lint ./helm-chart
```
## Deploy con CI/CD
### GitLab CI Example
```yaml
deploy:
stage: deploy
image: alpine/helm:latest
script:
- helm dependency update ./helm-chart
- helm upgrade --install calcolatore-prezzi ./helm-chart
--namespace production
--create-namespace
--set image.tag=$CI_COMMIT_SHA
--set-file configMaps.html-content.data.index\.html=./index.html
--set-file configMaps.html-content.data.shop-mode\.html=./shop-mode.html
only:
- main
```
### GitHub Actions Example
```yaml
name: Deploy to Kubernetes
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: '3.9.0'
- name: Deploy
run: |
helm dependency update ./helm-chart
helm upgrade --install calcolatore-prezzi ./helm-chart \
--namespace production \
--create-namespace \
--set-file configMaps.html-content.data.index\.html=./index.html \
--set-file configMaps.html-content.data.shop-mode\.html=./shop-mode.html
```
## Troubleshooting
### Verificare lo stato del deployment
```bash
kubectl get pods -l app.kubernetes.io/name=calcolatore-prezzi
kubectl describe pod <pod-name>
kubectl logs <pod-name>
```
### Verificare la configurazione
```bash
helm get values calcolatore-prezzi
helm get manifest calcolatore-prezzi
```
### Verificare l'ingress
```bash
kubectl get ingress
kubectl describe ingress calcolatore-prezzi
```
## Note
- Questo chart usa il base-helm come dipendenza per standardizzare le risorse Kubernetes
- I file HTML vengono iniettati tramite ConfigMap
- Per ambienti di produzione, considera l'uso di un registry Docker privato e immagini custom
- Assicurati di configurare correttamente i certificati SSL per la produzione
## Supporto
Per problemi o domande, apri una issue nel repository del progetto.

View File

@@ -0,0 +1,27 @@
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 "common.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 "common.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.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 "common.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 }}
2. The Calcolatore Prezzi Software application has been deployed!
- Main menu: /index.html
- Project mode: /project-mode.html
- Shop mode: /shop-mode.html

View File

@@ -0,0 +1,60 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "calcolatore.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
*/}}
{{- define "calcolatore.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 "calcolatore.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "calcolatore.labels" -}}
helm.sh/chart: {{ include "calcolatore.chart" . }}
{{ include "calcolatore.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "calcolatore.selectorLabels" -}}
app.kubernetes.io/name: {{ include "calcolatore.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "calcolatore.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "calcolatore.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,53 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "calcolatore.fullname" . }}-html-content
labels:
{{- include "calcolatore.labels" . | nindent 4 }}
data:
# Note: In a real deployment, you would use a CI/CD pipeline to inject these files
# or mount them from a separate volume. This is just a simple example.
# You can also use --set-file flag with helm to inject files:
# helm install myapp ./helm-chart \
# --set-file configMaps.html-content.data.index\.html=./index.html \
# --set-file configMaps.html-content.data.project-mode\.html=./project-mode.html \
# --set-file configMaps.html-content.data.shop-mode\.html=./shop-mode.html
index.html: |
<!-- Menu/Landing page - Content will be injected during deployment -->
<!DOCTYPE html>
<html>
<head>
<title>Calcolatore Prezzi - Selezione Modalità</title>
<meta http-equiv="refresh" content="0; url=https://example.com/">
</head>
<body>
<p>Loading...</p>
</body>
</html>
project-mode.html: |
<!-- Project mode - Content will be injected during deployment -->
<!DOCTYPE html>
<html>
<head>
<title>Calcolatore Prezzi - Modalità Progetto</title>
<meta http-equiv="refresh" content="0; url=https://example.com/project-mode.html">
</head>
<body>
<p>Loading...</p>
</body>
</html>
shop-mode.html: |
<!-- Shop mode - Content will be injected during deployment -->
<!DOCTYPE html>
<html>
<head>
<title>Calcolatore Prezzi - Modalità Negozio</title>
<meta http-equiv="refresh" content="0; url=https://example.com/shop-mode.html">
</head>
<body>
<p>Loading...</p>
</body>
</html>

187
helm-chart/values.yaml Normal file
View File

@@ -0,0 +1,187 @@
# Default values for calcolatore-prezzi-software
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
# Use base-helm common chart for standard configurations
common:
# Name override
nameOverride: ""
fullnameOverride: "calcolatore-prezzi"
# Application configuration
replicaCount: 2
image:
repository: nginx
pullPolicy: IfNotPresent
tag: "alpine"
imagePullSecrets: []
serviceAccount:
create: true
annotations: {}
name: ""
podAnnotations: {}
podSecurityContext:
fsGroup: 2000
runAsNonRoot: true
runAsUser: 1000
securityContext:
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
service:
type: ClusterIP
port: 80
targetPort: 80
annotations: {}
ingress:
enabled: true
className: "nginx"
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
hosts:
- host: calcolatore.example.com
paths:
- path: /
pathType: Prefix
tls:
- secretName: calcolatore-tls
hosts:
- calcolatore.example.com
resources:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 100m
memory: 128Mi
autoscaling:
enabled: false
minReplicas: 2
maxReplicas: 5
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
nodeSelector: {}
tolerations: []
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- calcolatore-prezzi
topologyKey: kubernetes.io/hostname
# Liveness and Readiness probes
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
successThreshold: 1
failureThreshold: 3
# Volume mounts for static files
volumeMounts:
- name: html-content
mountPath: /usr/share/nginx/html
readOnly: true
- name: nginx-cache
mountPath: /var/cache/nginx
- name: nginx-run
mountPath: /var/run
volumes:
- name: html-content
configMap:
name: calcolatore-html-content
- name: nginx-cache
emptyDir: {}
- name: nginx-run
emptyDir: {}
# ConfigMap for HTML files
configMaps:
html-content:
data:
# The HTML files will be injected here
# In production, you would use a CI/CD pipeline to update these
index.html: |
<!-- Your index.html content will be here -->
shop-mode.html: |
<!-- Your shop-mode.html content will be here -->
# Environment variables
env: []
# - name: ENVIRONMENT
# value: "production"
# Additional labels
labels: {}
# Pod Disruption Budget
podDisruptionBudget:
enabled: true
minAvailable: 1
# Network Policy
networkPolicy:
enabled: false
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: ingress-nginx
ports:
- protocol: TCP
port: 80
egress:
- to:
- namespaceSelector: {}
ports:
- protocol: TCP
port: 53
- protocol: UDP
port: 53
# Monitoring
monitoring:
enabled: false
serviceMonitor:
enabled: false
interval: 30s
path: /metrics