#!/bin/sh -e
# This script will setup docker to push all newly created container logs to https://int.loki.grid.tf
# NOTE: existing containers will need to be recreated to send their logs to Loki

### Install docker plugin
docker plugin install grafana/loki-docker-driver:2.9.2 --alias loki --grant-all-permissions

### Edit docker daemon config file
cat << EOF > /etc/docker/daemon.json
{
    "debug" : true,
    "log-driver": "loki",
    "log-opts": {
        "loki-url": "https://int.loki.grid.tf/loki/api/v1/push",
        "loki-batch-size": "400",
        "loki-retries": "2",
        "loki-max-backoff": "800ms",
        "loki-timeout": "1s",
        "keep-file": "true"
    }
}
EOF

### Restart docker
systemctl restart docker
echo "Don't forget to recreate all containers that should send their logs to Loki! This config does not apply to existing containers"