Use the endpoint settings from config.json

This commit is contained in:
Pagan Gazzard 2015-09-07 22:51:00 +03:00 committed by Pablo Carranza Vélez
parent fdf4f50691
commit 7b02c067ac
5 changed files with 71 additions and 19 deletions

View File

@ -16,6 +16,6 @@ RUN apt-get update && apt-get install jq \
COPY config/openvpn/ /etc/openvpn/
COPY config/services/ /etc/systemd/system/
COPY vpn-init /usr/src/app/
COPY resin-vars vpn-init /usr/src/app/
RUN systemctl enable resin-supervisor-dind

View File

@ -1,12 +1,4 @@
API_ENDPOINT=https://api.resinstaging.io
CONFIG_PATH=/usr/src/app/config/config.json
REGISTRY_ENDPOINT=registry.resinstaging.io
PUBNUB_SUBSCRIBE_KEY=sub-c-bananas
PUBNUB_PUBLISH_KEY=pub-c-bananas
MIXPANEL_TOKEN=bananasbananas
LISTEN_PORT=48484
RESIN_SUPERVISOR_SECRET=bananas
VPN_ENDPOINT=vpn.resinstaging.io
SUPERVISOR_IMAGE=
LED_FILE=/dev/null
RESIN_SUPERVISOR_SECRET=bananas
SUPERVISOR_IMAGE=

View File

@ -11,7 +11,8 @@ ExecStartPre=/usr/bin/docker pull ${SUPERVISOR_IMAGE}
ExecStartPre=-/usr/bin/docker kill resin_supervisor
ExecStartPre=-/usr/bin/docker rm resin_supervisor
ExecStartPre=-/bin/touch /etc/resolv.conf
ExecStart=/usr/bin/docker run --rm --privileged --name resin_supervisor \
ExecStart=/bin/bash -c 'source /usr/src/app/resin-vars && \
/usr/bin/docker run --rm --privileged --name resin_supervisor \
--net=host \
-v /var/run/docker.sock:/run/docker.sock \
-v "${CONFIG_PATH}:/boot/config.json" \
@ -20,16 +21,16 @@ ExecStart=/usr/bin/docker run --rm --privileged --name resin_supervisor \
-v /var/log/supervisor-log:/var/log \
-v /:/mnt/root \
-v /etc/resolv.conf:/etc/resolv.conf:rw \
-e "API_ENDPOINT=${API_ENDPOINT}" \
-e "REGISTRY_ENDPOINT=${REGISTRY_ENDPOINT}" \
-e "PUBNUB_SUBSCRIBE_KEY=${PUBNUB_SUBSCRIBE_KEY}" \
-e "PUBNUB_PUBLISH_KEY=${PUBNUB_PUBLISH_KEY}" \
-e "MIXPANEL_TOKEN=${MIXPANEL_TOKEN}" \
-e "API_ENDPOINT=$API_ENDPOINT" \
-e "REGISTRY_ENDPOINT=$REGISTRY_ENDPOINT" \
-e "PUBNUB_SUBSCRIBE_KEY=$PUBNUB_SUBSCRIBE_KEY" \
-e "PUBNUB_PUBLISH_KEY=$PUBNUB_PUBLISH_KEY" \
-e "MIXPANEL_TOKEN=$MIXPANEL_TOKEN" \
-e "LED_FILE=${LED_FILE}" \
-e "LISTEN_PORT=${LISTEN_PORT}" \
-e "LISTEN_PORT=$LISTEN_PORT" \
-e "SUPERVISOR_IMAGE=${SUPERVISOR_IMAGE}" \
-e "RESIN_SUPERVISOR_SECRET=${RESIN_SUPERVISOR_SECRET}" \
${SUPERVISOR_IMAGE}
${SUPERVISOR_IMAGE}'
TimeoutStartSec=0
Restart=always

58
tools/dind/resin-vars Normal file
View File

@ -0,0 +1,58 @@
#!/bin/bash
help () {
cat << EOF
Script for setting resin shell environment
resin-vars [options]
Options:
-h, --help
Display this help and exit.
-c, --config-path CONFIG_PATH
Use a non default config.json file.
Default: /mnt/conf/config.json
EOF
}
# Parse arguments
while [[ $# > 0 ]]; do
key=$1
case $key in
-h|--help)
help
exit 0
;;
-c|--config-path)
CONFIG_PATH=$2
shift
;;
*)
echo "[WARNING] $0 : Argument '$1' unknown. Ignoring."
;;
esac
shift
done
# Default values
if [ -z "$CONFIG_PATH" ]; then
CONFIG_PATH=/mnt/conf/config.json
fi
# If config.json provides redefinitions for our vars let us rewrite their
# runtime value
if [ -f $CONFIG_PATH ]
then
API_ENDPOINT=$(jq --raw-output ".apiEndpoint" $CONFIG_PATH)
LISTEN_PORT=$(jq --raw-output ".listenPort" $CONFIG_PATH)
MIXPANEL_TOKEN=$(jq --raw-output ".mixpanelToken" $CONFIG_PATH)
PUBNUB_PUBLISH_KEY=$(jq --raw-output ".pubnubPublishKey" $CONFIG_PATH)
PUBNUB_SUBSCRIBE_KEY=$(jq --raw-output ".pubnubSubscribeKey" $CONFIG_PATH)
REGISTRY_ENDPOINT=$(jq --raw-output ".registryEndpoint" $CONFIG_PATH)
VPN_ENDPOINT=$(jq --raw-output ".vpnEndpoint" $CONFIG_PATH)
if [ -z "$API_ENDPOINT" -o -z "$LISTEN_PORT" -o -z "$MIXPANEL_TOKEN" -o -z "$PUBNUB_PUBLISH_KEY" -o -z "$PUBNUB_SUBSCRIBE_KEY" -o -z "$REGISTRY_ENDPOINT" -o -z "$VPN_ENDPOINT" ]; then
echo "[WARNING] $0 : Couldn't read some variables from $CONFIG_PATH"
fi
else
echo "[WARNING] $0 : '$CONFIG_PATH' not found."
fi

View File

@ -1,4 +1,5 @@
#!/bin/bash
source /usr/src/app/resin-vars
sed --expression="s/#{VPN_ENDPOINT}/${VPN_ENDPOINT}/" /etc/openvpn/client.conf.tmpl > /etc/openvpn/client.conf
while true; do