diff --git a/.github/workflows/lab4.yml b/.github/workflows/lab4.yml new file mode 100644 index 0000000..5160a94 --- /dev/null +++ b/.github/workflows/lab4.yml @@ -0,0 +1,18 @@ +name: Lab 4 - Helm Chart Grading + +on: [push] + +jobs: + helm-check: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Helm + uses: azure/setup-helm@v4.2.0 + + - name: Run Lab 4 Tests + run: | + chmod +x ./tests/lab4_test.sh + ./tests/lab4_test.sh \ No newline at end of file diff --git a/charts/ecommerce-app/Chart.yaml b/charts/ecommerce-app/Chart.yaml new file mode 100644 index 0000000..e3e99ea --- /dev/null +++ b/charts/ecommerce-app/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: ecommerce-app +description: Helm chart for ServiceStation project +type: application +version: 0.1.0 +appVersion: "1.0.0" \ No newline at end of file diff --git a/charts/ecommerce-app/templates/configmap.yaml b/charts/ecommerce-app/templates/configmap.yaml new file mode 100644 index 0000000..a0dfb61 --- /dev/null +++ b/charts/ecommerce-app/templates/configmap.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: app-config +data: + DB_USER: {{ .Values.postgres.dbUser | quote }} + DB_HOST: "db-service" + DB_PORT: "5432" + DB_NAME: {{ .Values.postgres.dbName | quote }} + DATABASE_URL: "postgresql://{{ .Values.postgres.dbUser }}:{{ .Values.secrets.dbPassword }}@db-service:5432/{{ .Values.postgres.dbName }}?schema=public" + PORT: "8080" + JWT_EXPIRE: "1d" + GOOGLE_CALLBACK_URL: "http://localhost:8080/api/auth/google/callback" + CLIENT_URL: "http://localhost:80" \ No newline at end of file diff --git a/charts/ecommerce-app/templates/deployment.yaml b/charts/ecommerce-app/templates/deployment.yaml new file mode 100644 index 0000000..2b72efd --- /dev/null +++ b/charts/ecommerce-app/templates/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ecommerce-app +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: ecommerce-app + template: + metadata: + labels: + app: ecommerce-app + spec: + containers: + - name: ecommerce-app + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: 8080 + resources: + {{ toYaml .Values.resources | nindent 12 }} + envFrom: + - secretRef: + name: app-secret + - configMapRef: + name: app-config + livenessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 30 + readinessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 15 \ No newline at end of file diff --git a/charts/ecommerce-app/templates/postgres.yaml b/charts/ecommerce-app/templates/postgres.yaml new file mode 100644 index 0000000..349d4f6 --- /dev/null +++ b/charts/ecommerce-app/templates/postgres.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: {{ .Values.postgres.image }} + ports: + - containerPort: 5432 + env: + - name: POSTGRES_USER + value: {{ .Values.postgres.dbUser | quote }} + - name: POSTGRES_PASSWORD + value: {{ .Values.secrets.dbPassword | quote }} + - name: POSTGRES_DB + value: {{ .Values.postgres.dbName | quote }} +--- +apiVersion: v1 +kind: Service +metadata: + name: db-service +spec: + type: ClusterIP + selector: + app: postgres + ports: + - port: 5432 + targetPort: 5432 \ No newline at end of file diff --git a/charts/ecommerce-app/templates/secret.yaml b/charts/ecommerce-app/templates/secret.yaml new file mode 100644 index 0000000..c0888e9 --- /dev/null +++ b/charts/ecommerce-app/templates/secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: app-secret +type: Opaque +stringData: + DB_PASSWORD: {{ .Values.secrets.dbPassword | quote }} + JWT_SECRET: {{ .Values.secrets.jwtSecret | quote }} + GOOGLE_CLIENT_ID: {{ .Values.secrets.googleClientId | quote }} + GOOGLE_CLIENT_SECRET: {{ .Values.secrets.googleClientSecret | quote }} \ No newline at end of file diff --git a/charts/ecommerce-app/templates/service.yaml b/charts/ecommerce-app/templates/service.yaml new file mode 100644 index 0000000..682a226 --- /dev/null +++ b/charts/ecommerce-app/templates/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: ecommerce-service +spec: + type: ClusterIP + selector: + app: ecommerce-app + ports: + - port: 8080 + targetPort: 8080 \ No newline at end of file diff --git a/charts/ecommerce-app/values-prod.yaml b/charts/ecommerce-app/values-prod.yaml new file mode 100644 index 0000000..5f592bf --- /dev/null +++ b/charts/ecommerce-app/values-prod.yaml @@ -0,0 +1 @@ +replicaCount: 3 \ No newline at end of file diff --git a/charts/ecommerce-app/values.yaml b/charts/ecommerce-app/values.yaml new file mode 100644 index 0000000..6a1337b --- /dev/null +++ b/charts/ecommerce-app/values.yaml @@ -0,0 +1,25 @@ +replicaCount: 2 + +image: + repository: ghcr.io/jessfreak/ecommerce-app + tag: latest + pullPolicy: IfNotPresent + +resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + +postgres: + image: postgres:15-alpine + dbName: service_station + dbUser: postgres + +secrets: + dbPassword: "dummy-password" + jwtSecret: "dummy-secret" + googleClientId: "dummy-id" + googleClientSecret: "dummy-secret" \ No newline at end of file diff --git a/k8s/service.yaml b/k8s/service.yaml index aa37cef..682a226 100644 --- a/k8s/service.yaml +++ b/k8s/service.yaml @@ -5,7 +5,7 @@ metadata: spec: type: ClusterIP selector: - app: backend-deployment + app: ecommerce-app ports: - port: 8080 targetPort: 8080 \ No newline at end of file diff --git a/tests/lab4_test.sh b/tests/lab4_test.sh new file mode 100644 index 0000000..a2373f9 --- /dev/null +++ b/tests/lab4_test.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +echo "--- Starting Lab 4 Grading (Helm Check) ---" + +# 1. Валідація чарта +echo "Step 1: Running helm lint..." +helm lint ./charts/ecommerce-app + +# 2. Перевірка шаблонізації для Prod +echo "Step 2: Checking Production replica count..." +REPLICAS=$(helm template ecommerce ./charts/ecommerce-app -f ./charts/ecommerce-app/values-prod.yaml | grep 'replicas: 3' | xargs) +if [ "$REPLICAS" != "replicas: 3" ]; then + echo "❌ Error: values-prod.yaml should set replicas to 3." + exit 1 +fi + +# 3. Dry-run install +echo "Step 3: Testing Dry-run installation..." +helm install ecommerce ./charts/ecommerce-app --dry-run --debug + +echo "✅ SUCCESS: Lab 4 is passed!" \ No newline at end of file