apiVersion: v1
kind: ConfigMap
metadata:
  name: gocd-init-configmap
data:
  addon_config.sh: |-
    #!bin/bash

    SERVICE_ACCOUNT_PATH=/var/run/secrets/kubernetes.io/serviceaccount
    KUBE_TOKEN=$(<${SERVICE_ACCOUNT_PATH}/token)

    tee /godata/config/postgresqldb.properties >/dev/null <<EOF
    db.host=postgresdb-postgresql
    db.port=5432
    db.name=cruise
    db.user=postgres
    db.password=postgres
    EOF

    curl -L -o '/godata/addons/go-postgresql.jar' --fail -H 'Accept: binary/octet-stream' --user $EXTENSION_USERNAME:$EXTENSION_PASSWORD \
    'https://extensions.gocd.org/addons/postgres/versions/latest/download?eula_accepted=true' &> /godata/addons/addon_config.log

    md5sum /godata/addons/go-postgresql.jar

    md5sum /godata/addons/go-postgresql.jar

    curl -L -o '/godata/plugins/external/gocd-analytics-plugin.jar' --fail -H 'Accept: binary/octet-stream' --user $EXTENSION_USERNAME:$EXTENSION_PASSWORD \
    'https://extensions.gocd.org/addons/analytics/versions/latest/download?eula_accepted=true' &> /godata/addons/addon_config.log

    md5sum /godata/plugins/external/gocd-analytics-plugin.jar

    ls -altr /godata/addons/

    rm -rf /godata/newrelic
    mkdir -p /godata/newrelic

    curl -L -o '/godata/newrelic/newrelic-agent.jar' --fail 'http://central.maven.org/maven2/com/newrelic/agent/java/newrelic-agent/4.7.0/newrelic-agent-4.7.0.jar'

    curl -L -o '/godata/newrelic/newrelic-api.jar' --fail 'http://central.maven.org/maven2/com/newrelic/agent/java/newrelic-api/4.7.0/newrelic-api-4.7.0.jar'

    cp /godata/resources/newrelic.yml /godata/newrelic/newrelic.yml
