apiVersion: v1
kind: Namespace
metadata:
  name: cavisson

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sqlserver
  namespace: cavisson
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sqlserver
  template:
    metadata:
      labels:
        app: sqlserver
    spec:
      volumes:
        - name: sqldata
          emptyDir: {}
      containers:
        - name: sqlserver
          image: mcr.microsoft.com/azure-sql-edge
          ports:
            - containerPort: 1433
          env:
            - name: SA_PASSWORD
              value: "@someThingComplicated1234"
            - name: ACCEPT_EULA
              value: "Y"
          volumeMounts:
            - name: sqldata
              mountPath: /var/opt/mssql

---
apiVersion: v1
kind: Service
metadata:
  name: sqlserver
  namespace: cavisson
spec:
  type: ClusterIP
  selector:
    app: sqlserver
  ports:
    - name: sql
      port: 1433
      targetPort: 1433

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: eshopwebmvc-alpine
  namespace: cavisson
spec:
  replicas: 1
  selector:
    matchLabels:
      app: eshopwebmvc-alpine
      language: dotnet
      matchLabel: dotnetApp
  template:
    metadata:
      labels:
        app: eshopwebmvc-alpine
        language: dotnet
        matchLabel: dotnetApp
    spec:
      volumes:
        - name: app-secrets
          emptyDir: {}
        - name: aspnet-https
          emptyDir: {}

      containers:
        - name: eshopwebmvc-alpine
          image: mydotnetacr.azurecr.io/eshopwebmvc-alpine:latest

          # Security
          securityContext:
            readOnlyRootFilesystem: true
            allowPrivilegeEscalation: false
            runAsNonRoot: true

          env:
            - name: ASPNETCORE_ENVIRONMENT
              value: "Docker"
            - name: ASPNETCORE_URLS
              value: "http://+:8080"
            - name: ConnectionStrings__CatalogConnection
              value: "Server=sqlserver,1433;User Id=sa;Password=@someThingComplicated1234;TrustServerCertificate=true;"
            - name: DOTNET_SYSTEM_GLOBALIZATION_INVARIANT
              value: "false"
            - name: DOTNET_CULTURE
              value: "en-US"

          ports:
            - containerPort: 8080

          volumeMounts:
            - name: app-secrets
              mountPath: /root/.microsoft/usersecrets
            - name: aspnet-https
              mountPath: /root/.aspnet/https

---
apiVersion: v1
kind: Service
metadata:
  name: eshopwebmvc-alpine
  namespace: cavisson
spec:
  type: LoadBalancer
  selector:
    app: eshopwebmvc-alpine
  ports:
    - name: http
      port: 5106
      targetPort: 8080

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: eshoppublicapi-alpine
  namespace: cavisson
spec:
  replicas: 1
  selector:
    matchLabels:
      app: eshoppublicapi-alpine
      language: dotnet
      matchLabel: dotnetApp
  template:
    metadata:
      labels:
        app: eshoppublicapi-alpine
        language: dotnet
        matchLabel: dotnetApp
    spec:
      volumes:
        - name: app-secrets
          emptyDir: {}
        - name: aspnet-https
          emptyDir: {}

      containers:
        - name: eshoppublicapi-alpine
          image: mydotnetacr.azurecr.io/eshoppublicapi-alpine:latest

          # Security
          securityContext:
            readOnlyRootFilesystem: true
            allowPrivilegeEscalation: false
            runAsNonRoot: true

          env:
            - name: ASPNETCORE_ENVIRONMENT
              value: "Docker"
            - name: ASPNETCORE_URLS
              value: "http://+:8080"
            - name: ConnectionStrings__IdentityConnection
              value: "Server=sqlserver,1433;User Id=sa;Password=@someThingComplicated1234;TrustServerCertificate=true;"

          ports:
            - containerPort: 8080

          volumeMounts:
            - name: app-secrets
              mountPath: /root/.microsoft/usersecrets
            - name: aspnet-https
              mountPath: /root/.aspnet/https
