init.sh.jinja 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {% macro init_script(values) -%}
  2. {#- Default API Address https://github.com/ipfs/kubo/blob/master/docs/config.md#addressesapi #}
  3. {%- set api_addresses = [
  4. "/ip4/0.0.0.0/tcp/%s"|format(values.network.api_port.port_number),
  5. "/ip6/::/tcp/%s"|format(values.network.api_port.port_number),
  6. ] %}
  7. {#- Default Gateway Address https://github.com/ipfs/kubo/blob/master/docs/config.md#addressesgateway #}
  8. {%- set gateway_addresses = [
  9. "/ip4/0.0.0.0/tcp/%s"|format(values.network.gateway_port.port_number),
  10. "/ip6/::/tcp/%s"|format(values.network.gateway_port.port_number),
  11. ] %}
  12. {#- Default Swarm Addresses https://github.com/ipfs/kubo/blob/master/docs/config.md#addressesswarm #}
  13. {%- set swarm_addresses = [
  14. "/ip4/0.0.0.0/tcp/%s"|format(values.network.swarm_port.port_number),
  15. "/ip6/::/tcp/%s"|format(values.network.swarm_port.port_number),
  16. "/ip4/0.0.0.0/udp/%s/quic"|format(values.network.swarm_port.port_number),
  17. "/ip4/0.0.0.0/udp/%s/quic-v1"|format(values.network.swarm_port.port_number),
  18. "/ip4/0.0.0.0/udp/%s/quic-v1/webtransport"|format(values.network.swarm_port.port_number),
  19. "/ip6/::/udp/%s/quic"|format(values.network.swarm_port.port_number),
  20. "/ip6/::/udp/%s/quic-v1"|format(values.network.swarm_port.port_number),
  21. "/ip6/::/udp/%s/quic-v1/webtransport"|format(values.network.swarm_port.port_number),
  22. ] %}
  23. {%- set allowed_origins = ["*"] %}
  24. {%- set allowed_methods = ["POST", "PUT"] %}
  25. #!/bin/sh
  26. set -e
  27. if [ ! -f {{ values.consts.data_path }}/config ]; then
  28. # Create the IPFS config file
  29. echo "Initializing IPFS"
  30. ipfs init
  31. fi
  32. # Configure the Addresses.API
  33. echo 'Configuring the Addresses.API to {{ api_addresses }}'
  34. ipfs config Addresses.API --json '{{ api_addresses | tojson }}'
  35. # Configure the Addresses.Gateway
  36. echo 'Configuring the Addresses.Gateway to {{ gateway_addresses }}'
  37. ipfs config Addresses.Gateway --json '{{ gateway_addresses | tojson }}'
  38. # Configure the Addresses.Swarm
  39. echo 'Configuring the Addresses.Swarm to {{ swarm_addresses | tojson }}'
  40. ipfs config Addresses.Swarm --json '{{ swarm_addresses | tojson }}'
  41. # Configure the API.HTTPHeaders.Access-Control-Allow-Origin
  42. echo 'Configuring the API.HTTPHeaders.Access-Control-Allow-Origin to {{ allowed_origins | tojson }}'
  43. ipfs config API.HTTPHeaders.Access-Control-Allow-Origin --json '{{ allowed_origins | tojson }}'
  44. # Configure the API.HTTPHeaders.Access-Control-Allow-Methods
  45. echo 'Configuring the API.HTTPHeaders.Access-Control-Allow-Methods to {{ allowed_methods | tojson }}'
  46. ipfs config API.HTTPHeaders.Access-Control-Allow-Methods --json '{{ allowed_methods | tojson }}'
  47. echo "Finished configuring IPFS"
  48. {%- endmacro %}