#!/bin/bash
# Usage: ./customize.sh dev|qa|prod

ENV=$1
VALUES_FILE="env/$ENV/values.env"
YAML_FILE="kubernetes/infrastructure.yaml"

if [ ! -f "$VALUES_FILE" ]; then
  echo "File $VALUES_FILE non trovato."
  exit 1
fi

if [ ! -f "$YAML_FILE" ]; then
  echo "File $YAML_FILE non trovato."
  exit 1
fi

while IFS='=' read -r key value; do
  sed -i "s|<$key>|$value|g" "$YAML_FILE"
done < "$VALUES_FILE"

echo "Sostituzione completata per ambiente $ENV."





#!/bin/bash

# Carica variabili dal file properties.env
source properties.env

# Controlla che le variabili siano impostate
if [ -z "$REGISTRY_URL" ] || [ -z "$REGISTRY_USER" ] || [ -z "$REGISTRY_PASS" ]; then
  echo "REGISTRY_URL, REGISTRY_USER o REGISTRY_PASS non impostate in properties.env"
  exit 1
fi

REPO_NAME=$(basename "$PWD")
COMMIT_SHA=$(git rev-parse --short HEAD)

# Login al registry
echo "$REGISTRY_PASS" | docker login "$REGISTRY_URL" -u "$REGISTRY_USER" --password-stdin

for dir in containers/*/; do
  CONTAINER_NAME=$(basename "$dir")
  DOCKERFILE="$dir/dockerfile"
  IMAGE_TAG="${REGISTRY_URL}/${REPO_NAME}/${CONTAINER_NAME}:${COMMIT_SHA}"
  if [ -f "$DOCKERFILE" ]; then
    docker build -t "$IMAGE_TAG" -f "$DOCKERFILE" "$dir"
    docker push "$IMAGE_TAG"
    echo "Build e push completate: $IMAGE_TAG"
  else
    echo "Dockerfile non trovato in $dir"
  fi
done



#!/bin/bash
# Effettua il deploy del file infrastructure.yaml in Kubernetes

YAML_FILE="kubernetes/infrastructure.yaml"

if [ ! -f "$YAML_FILE" ]; then
  echo "File $YAML_FILE non trovato."
  exit 1
fi

kubectl apply -f "$YAML_FILE"
echo "Deploy completato."