# This file creates our 2 docker containers 
kind: pipeline
name: Dockers_Builder


# Creation of the DB docker
steps:  
  # database container deployment
  - name: deploy-container-mysql-test
    image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
    environment:
        IMAGENAME: mysql:8.0
        CONTAINERNAME: mysql
        COMMAND: create
        # OVERWRITE: true
        PRIVATE: true
        CODEFIRST_CLIENTDRONE_ENV_MARIADB_ROOT_PASSWORD:    
          from_secret: MYSQL_ROOT_PASSWORD
        CODEFIRST_CLIENTDRONE_ENV_MARIADB_DATABASE:
          from_secret: MYSQL_DATABASE
        CODEFIRST_CLIENTDRONE_ENV_MARIADB_USER:
          from_secret: MYSQL_USER_TOM
        CODEFIRST_CLIENTDRONE_ENV_MARIADB_PASSWORD:
          from_secret: MYSQL_PASSWORD_TOM
        ADMINS: thomas.chazot2, mathilde.jean3,lilian.breton, lucie.bedouret, alban.guilhot


# docker image build
  - name: container-api
    image: plugins/docker
    settings:
      dockerfile: ./api-rest/Dockerfile
      context: .
      registry: hub.codefirst.iut.uca.fr
      repo: hub.codefirst.iut.uca.fr/thomas.chazot2/bobparty/api-rest
      username:
        from_secret: SECRET_REGISTRY_USERNAME_TOM
      password:
        from_secret: SECRET_REGISTRY_PASSWORD_TOM


#container deployment
  - name: deploy-api-containers
    image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
    environment:
        IMAGENAME: hub.codefirst.iut.uca.fr/thomas.chazot2/bobparty/api-rest:latest
        CONTAINERNAME: api-bobParty
        COMMAND: create
        OVERWRITE: true
        CODEFIRST_CLIENTDRONE_ENV_DB_SERVER:
          from_secret: db_server
        CODEFIRST_CLIENTDRONE_ENV_DB_USER:
          from_secret: MYSQL_USER_TOM
        CODEFIRST_CLIENTDRONE_ENV_DB_PASSWORD:
          from_secret: MYSQL_PASSWORD_TOM
        CODEFIRST_CLIENTDRONE_ENV_DB_DATABASE:
          from_secret: MYSQL_DATABASE
    depends_on: 
        - container-api


# docker image build
  - name: docker-build-and-push
    image: plugins/docker
    settings:
      dockerfile: Dockerfile
      context: .
      registry: hub.codefirst.iut.uca.fr
      repo: hub.codefirst.iut.uca.fr/thomas.chazot2/bobparty
      username:
        from_secret: SECRET_REGISTRY_USERNAME_TOM
      password:
        from_secret: SECRET_REGISTRY_PASSWORD_TOM

#container deployment
  - name: deploy-bob_party-container
    image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
    environment:
        IMAGENAME: hub.codefirst.iut.uca.fr/thomas.chazot2/bobparty:latest
        CONTAINERNAME: bob_party_container
        COMMAND: create
        #OVERWRITE: true