#!/bin/bash

set -e

. lib/common

DOMAIN=$(relation-get domain) || exit 1

## These are mainly to setup the correct web-hook
if [ "$MASTER_BASE_SERVICE_NAME" == "$DOMAIN" ]; then
    ## This is because the IP will be the docker container version
    PROTO="http"
else
    URL="$(relation-get url)" || exit 1
    PROTO="${URL%%://*}"
fi

config-add "\
services:
  $MASTER_BASE_SERVICE_NAME:
    environment:
      DRONE_SERVER_HOST: $DOMAIN
      DRONE_SERVER_PROTO: $PROTO
"