#!/bin/bash

services=$1
IFS=","

COMPOSE_FILES=${COMPOSE_FILES:-'-f docker-compose.yml'}

for value in $services; do
    repo=${value%:*}


    case $repo in
        contiamo-ui)
            service='ui'
        ;;
        idp)
            service='auth'
        ;;
        datastore-manager)
            service='datastore'
        ;;
        pgql-server)
            service='graphql'
        ;;
        demo-signup)
            service='demo'
        ;;
        *)
            service=$repo
        ;;
    esac

    pr=${value#*:}
    svc=$(echo "$service" | tr "[:lower:]" "[:upper:]" | tr '-' '_')

    echo "Pull image for $service PR $pr"
    docker pull "eu.gcr.io/dev-and-test-env/${repo}-preview:pr-${pr}" #1> /dev/null 2>&1
    export "${svc}_IMAGE=eu.gcr.io/dev-and-test-env/${repo}-preview:pr-${pr}"
done;

echo "$COMPOSE_FILES up -d --force-recreate" | xargs docker-compose
