kind: pipeline
type: docker
name: DAFLPipeline

trigger:
  event:
    - push

steps:
# build CONTAINER for app-build on cirrusci IMAGE
- name: app-build
  image: cirrusci/flutter:stable
  commands:
    - flutter doctor
    - cd ./Sources/dafl_project_flutter/
    - flutter build apk

# build CONTAINER for sonar on cirrusci IMAGE
- name: code-analysis
  image: cirrusci/flutter:stable
  environment:
    SONAR_TOKEN:
      from_secret: sonar_token
  settings:
    sources: ./Sources/dafl_project_flutter
  commands:
    - export SONAR_SCANNER_VERSION=4.7.0.2747
    - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
    - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
    - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
    - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
    - export SONAR_SCANNER_OPTS="-server"
    - sonar-scanner -D sonar.projectKey=DAFLMusic -D sonar.sources=. -D sonar.host.url=https://codefirst.iut.uca.fr/sonar
  depends_on: [ app-build ]

- name: web-server
  image: plugins/docker
  settings:
    dockerfile: ./Sources/api_redirect/Dockerfile
    context: Sources/api_redirect/
    registry: hub.codefirst.iut.uca.fr
    repo: hub.codefirst.iut.uca.fr/felix.mielcarek/dafl_music
    username:
      from_secret: secret-registry-username
    password:
      from_secret: secret-registry-password

- name: deploy-container
  image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
  environment:
    IMAGENAME: hub.codefirst.iut.uca.fr/felix.mielcarek/dafl_music:latest
    CONTAINERNAME: apiredirect
    COMMAND: create
    OVERWRITE: true
  depends_on: [ web-server ]
