stages:
  - build
  - deploy

build:
  stage: build
  
  when: manual 

  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
 
  script:

#  # Build Backend
#   
#    - echo "Building Backend"
#    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
#    - /kaniko/executor --context $CI_PROJECT_DIR/conduit-backend --dockerfile $CI_PROJECT_DIR/conduit-backend/Dockerfile --destination $CI_REGISTRY_IMAGE:backend
  
  # Build Frontend

    - echo "Building Frontend"
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR/conduit-front --dockerfile $CI_PROJECT_DIR/conduit-front/Dockerfile --destination $CI_REGISTRY_IMAGE:front

deploy:

#    tags:
#      - example

    stage: deploy

    when: manual

    script: echo "Deploying Backend"
    image: bitnami/kubectl:latest
    script:
         - kubectl apply -f $CI_PROJECT_DIR/conduit-backend/backend-service.yaml
         - kubectl apply -f $CI_PROJECT_DIR/conduit-backend/backend-deployment.yaml
         - kubectl -n default rollout restart deployment backend   


    script: echo "Deploying Frontend"
    image: bitnami/kubectl:latest
    script:
         - kubectl apply -f $CI_PROJECT_DIR/conduit-front/front-service.yaml
         - kubectl apply -f $CI_PROJECT_DIR/conduit-front/front-deployment.yaml
         - kubectl -n default rollout restart deployment front 
