fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.7 KiB

  1. #!/bin/bash
  2. ## Init is run on host
  3. ## For now it is run every time the script is launched, but
  4. ## it should be launched only once after build.
  5. ## Accessible variables are:
  6. ## - SERVICE_NAME Name of current service
  7. ## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
  8. ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
  9. ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
  10. . lib/common
  11. set -e
  12. if [ -e "$HOST_CONFIG_FILE" ]; then
  13. echo > "$HOST_CONFIG_FILE"
  14. else
  15. mkdir -p "$(dirname "$HOST_CONFIG_FILE")"
  16. touch "$HOST_CONFIG_FILE"
  17. fi
  18. init-config-add "
  19. $SERVICE_NAME:
  20. volumes:
  21. - $HOST_CONFIG_FILE:$CONFIG_FILE
  22. "
  23. ##
  24. ## Merge compose options
  25. ##
  26. service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1
  27. options=$(e "$service_def" | shyaml -y get-value "options") || true
  28. if [ "$options" ]; then
  29. while read-0 key value; do
  30. case "$key" in
  31. users)
  32. user_conf=$(make_users_config "$value") || exit 1
  33. e "$user_conf" | ini_merge
  34. ;;
  35. acl)
  36. yaml_key_val_str "$key" "$value" | ini_merge
  37. ;;
  38. *)
  39. err "Unknown key '$key' in options."
  40. exit 1
  41. ;;
  42. esac
  43. done < <(e "$options" | shyaml key-values-0)
  44. fi
  45. ## XXXvlab: ports should be not repeated (is repeated in charm metadata, or docker image)
  46. ini_merge <<EOF
  47. server:
  48. addr: ":5001"
  49. EOF
  50. ini_merge <<EOF
  51. token:
  52. issuer: "Acme auth server"
  53. expiration: 900
  54. EOF
  55. ## Can be modified by web-proxy relation
  56. echo "http://$SERVICE_NAME:5001" > "$SERVICE_CONFIGSTORE/etc/docker-auth/realm"