#!/bin/bash

set -e -u

export PIPELINE_NAME=test-pipeline

inputs=$PWD

source concourse/ci/tasks/scripts/docker-helpers.sh

start_docker

[ -d dev-image ] && docker load -i dev-image/image.tar
[ -d concourse-image ] && docker load -i concourse-image/image.tar
[ -d postgres-image ] && docker load -i postgres-image/image.tar

cd concourse

# generate keys for the cluster
./ci/tasks/scripts/generate-keys

# start with latest release and set up
docker-compose \
  -f docker-compose.yml \
  -f ci/overrides/docker-compose.ci.yml \
  -f ci/overrides/docker-compose.no-build.yml \
  -f ci/overrides/docker-compose.latest.yml \
  up --no-build -d

./ci/tasks/scripts/create-upgrade-downgrade-pipeline

# upgrade and verify
docker-compose \
  -f docker-compose.yml \
  -f ci/overrides/docker-compose.ci.yml \
  -f ci/overrides/docker-compose.no-build.yml \
  up --no-build -d

./ci/tasks/scripts/verify-upgrade-downgrade-pipeline

# run smoke tests
cd web/wats
stty columns 80 # for better yarn output
yarn install
yarn test -v --color test/smoke.js
