stages:
  - purge
  - e2e-test

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 8
    - 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
