stages:
  - purge
  - e2e-test
  - rf-test
  - push-results

purge-old-containers:
  image:
    name: docker/compose:1.24.0
    entrypoint: ['/bin/sh', '-c']
  services:
    - docker:dind
  stage: purge
  tags: ['docker']
  only:
    - testing
  script:
    - docker-compose down
  allow_failure: true

e2e-testing:
  image:
    name: docker/compose:1.24.0
    entrypoint: ['/bin/sh', '-c']
  services:
    - docker:dind
  stage: e2e-test
  tags: ['compose']
  only:
    - testing
  script:
    - printf "SECRET=%s\n" "$SECRET" > .env
    - docker image prune -f
    - docker-compose build --no-cache
    - docker-compose up -d
  after_script:
    - sleep 3
    - echo "create database ehasa;" | docker exec -i postgis psql -U postgres
    - echo "create user ehasa;" | docker exec -i postgis psql -U postgres
    - echo "alter user ehasa with encrypted password 'salasana';" | docker exec -i postgis psql -U postgres
    - echo "grant all privileges on database ehasa to ehasa;" | docker exec -i postgis psql -U postgres
    - echo 'create extension "uuid-ossp";' | docker exec -i postgis psql -U postgres ehasa
  allow_failure: true

rf-test:
  image: gitlab.labranet.jamk.fi:4567/wimma-lab-2019/mysticons/devsecops/robot
  stage: rf-test
  tags: ['docker']
  only:
    - testing
  script:
    - export ROBOT_TESTS=./tests
    - export OUTPUT_DIR=./results
    - run.sh
  artifacts:
    when: always
    untracked: true
    expire_in: 24h

push-results:
  stage: push-results
  tags: ['shell']
  only:
    - testing
  when: always
  script:
    - docker cp ./results front:/usr/share/nginx/html
