#!/bin/bash ## Init is run on host ## For now it is run every time the script is launched, but ## it should be launched only once after build. ## Accessible variables are: ## - SERVICE_NAME Name of current service ## - DOCKER_BASE_IMAGE Base image from which this service might be built if any ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service set -e server="$(options-get server)" || exit 1 secret="$(options-get secret)" || exit 1 name="$(options-get name)" || true capacity="$(options-get capacity)" || true name=${name:-"$(hostname)/$SERVICE_NAME"} capacity=${capacity:-2} service_def=$(get_compose_service_def "$SERVICE_NAME") || exit 1 labels_def=$(e "$service_def" | shyaml get-value options.labels) || true [ "$labels_def" == None ] && labels_def="" if [ "$labels_def" ]; then labels="" while read-0 label value; do var+="$label:$value," done < <(printf "%s" "$labels_def" | shyaml key-values-0) labels="${var::-1}" fi init-config-add "\ $MASTER_BASE_SERVICE_NAME: environment: DRONE_RPC_SERVER: $server DRONE_RPC_SECRET: $secret DRONE_RUNNER_NAME: $name DRONE_RUNNER_CAPACITY: $capacity $([ "$labels" ] && echo "DRONE_RUNNER_LABELS: '$labels'") volumes: - /var/run/docker.sock:/var/run/docker.sock "