Current section
Files
Jump to
Current section
Files
priv/templates/runtime-environment-wrap.eex
#!/bin/sh
# Get runtime environment from cloud-init metadata, set environment vars,
# then launch script
#
# https://cloudinit.readthedocs.io/en/latest/topics/network-config.html#network-configuration-outputs
set -e
CLOUD_NAME=$(jq -r '.v1.cloud_name' < /run/cloud-init/instance-data.json)
if [ "$CLOUD_NAME" = "digitalocean" ]; then
IP_ADDR=$(jq -r '.ds.meta_data.interfaces.public[0].anchor_ipv4.ip_address' < /run/cloud-init/instance-data.json)
export DEFAULT_IPV4="$IP_ADDR"
export CLOUD_NAME
exec $*
elif [ "$CLOUD_NAME" = "aws" ]; then
IP_ADDR=$(jq -r '.ds.meta_data."local-ipv4"' < /run/cloud-init/instance-data.json)
# IP_ADDR=$(jq -r '.ds.meta_data."public-ipv4"' < /run/cloud-init/instance-data.json)
AWS_REGION=$(jq -r '.v1.region' < /run/cloud-init/instance-data.json)
export DEFAULT_IPV4="$IP_ADDR"
export AWS_REGION="$AWS_REGION"
export CLOUD_NAME
exec $*
else
echo "Unsupported cloud: $CLOUD_NAME"
exit 1
fi