apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-soccerdeployment                                                                                # changed
  labels:
    app: my-mysql-soccerdeployment                                                                            # changed
spec:
  # A single mysql instance
  replicas: 1
  selector:
    matchLabels:
      app: mysoccer-mysql                                                                                     # changed
  template:
    metadata:
      labels:
        app: mysoccer-mysql                                                                                   # changed
    spec:
      # Use the init container to download data to the location where the mysql container expects it
      initContainers:
        - name: init-container-data-downloader
          image: curlimages/curl
          args:
            - "-o"
            - "/tmp/data/init.sql" # we are saving downloaded file as init.sql in /tmp/data directory
            - "https://raw.githubusercontent.com/Lyceoth/DataEngineeringProject/master/Database/01_SoccerDBMySQL_CREATE.SQL"          ######################## to be changed
          volumeMounts:
            - name: data-volume
              mountPath: /tmp/data
      # The actual mysql database
      containers:
        - name: mysoccer-mysql                                                                            # changed
          image: mysql
          # Set required environment variables to initialize the container
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "mysecretpw"
            - name: MYSQL_DATABASE
              value: "SOCCERSTAT"                                                                           # changed
          # Mount the volume that has been populated by the init container
          volumeMounts:
            - name: data-volume
              mountPath: /docker-entrypoint-initdb.d/
          ports:
            - containerPort: 3306
            - containerPort: 33060
          livenessProbe:
            tcpSocket:
              port: 33060
            initialDelaySeconds: 300 # to avoid restarts while initializing the database
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: 33060
            initialDelaySeconds: 5
            periodSeconds: 10
      #          resources:
      #            requests:
      #              cpu: 1
      #              memory: "200M"
      #            limits:
      #              cpu: 1
      #              memory: "200M"
      # Define an empty volume to be shared by the init and mysql container
      volumes:
        - name: data-volume
          emptyDir: {}