# Flux HelmRelease consuming the OCIRepository declared in ocirepository.yaml.
#
# For releases pulling a chart from a classic Helm repo (HTTP) instead of OCI, replace
# spec.chart.spec.sourceRef with a HelmRepository reference and add a HelmRepository resource:
#
#   apiVersion: source.toolkit.fluxcd.io/v1
#   kind: HelmRepository
#   metadata:
#     name: my-repo
#     namespace: flux-system
#   spec:
#     interval: 10m
#     url: https://example.com/charts
#
# Apply with:
#   kubectl apply -f flux/helmrelease.yaml
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: init-containers
  namespace: init-containers
spec:
  interval: 5m
  releaseName: init-containers
  chartRef:
    kind: OCIRepository
    name: universal-helm-chart
    namespace: flux-system
  install:
    createNamespace: true
  values:
    deployments:
      web:
        enabled: true
        replicaCount: 1
        image:
          repository: nginx
          tag: "1.27"
          pullPolicy: IfNotPresent
        service:
          enabled: true
          type: ClusterIP
          port: 80
          targetPort: 80
        resources:
          requests:
            cpu: 50m
            memory: 64Mi
          limits:
            memory: 128Mi
        initContainers:
          01-wait-for-db:
            image:
              repository: busybox
              tag: "1.36"
              pullPolicy: IfNotPresent
            command: |
              until nc -z postgres.example.svc 5432; do
                echo "waiting for postgres..."
                sleep 2
              done
          02-migrate:
            image:
              repository: myrepo/migrations
              tag: v1.2.3
            command:
              - /bin/migrate
              - --database=$(DATABASE_URL)
              - --source=file:///etc/migrations
            envSecrets:
              - db-credentials
