diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd95ea6..387816e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Use buildtime env vars as the default Pubnub and Mixpanel keys [Pablo] + # v1.1.0 * Switch back to using arch-based node images [Pablo] diff --git a/Makefile b/Makefile index 500b580c..a7a19d58 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,10 @@ all: supervisor IMAGE = "resin/$(ARCH)-supervisor:$(SUPERVISOR_VERSION)" SUPERVISOR_IMAGE=$(DEPLOY_REGISTRY)$(IMAGE) +PUBNUB_SUBSCRIBE_KEY = sub-c-bananas +PUBNUB_PUBLISH_KEY = pub-c-bananas +MIXPANEL_TOKEN = bananasbananas + ifeq ($(ARCH),rpi) GOARCH = arm endif @@ -54,6 +58,9 @@ stop-supervisor: supervisor: gosuper cp Dockerfile.$(ARCH) Dockerfile echo "ENV VERSION "`jq -r .version package.json` >> Dockerfile + echo "ENV DEFAULT_PUBNUB_PUBLISH_KEY $(PUBNUB_PUBLISH_KEY)" >> Dockerfile + echo "ENV DEFAULT_PUBNUB_SUBSCRIBE_KEY $(PUBNUB_SUBSCRIBE_KEY)" >> Dockerfile + echo "ENV DEFAULT_MIXPANEL_TOKEN $(MIXPANEL_TOKEN)" >> Dockerfile docker build --no-cache=$(DISABLE_CACHE) -t $(IMAGE) . -rm Dockerfile diff --git a/automation/jenkins_build.sh b/automation/jenkins_build.sh index 4a4cd0c3..41b1ab81 100755 --- a/automation/jenkins_build.sh +++ b/automation/jenkins_build.sh @@ -12,5 +12,19 @@ docker pull resin/${ARCH}-supervisor:${ESCAPED_BRANCH_NAME} || docker pull resin make SUPERVISOR_VERSION=${VERSION} JOB_NAME=${JOB_NAME} test-gosuper # Build the images -make SUPERVISOR_VERSION=${ESCAPED_BRANCH_NAME} ARCH=${ARCH} JOB_NAME=${JOB_NAME} DEPLOY_REGISTRY= deploy -make SUPERVISOR_VERSION=${VERSION} ARCH=${ARCH} JOB_NAME=${JOB_NAME} DEPLOY_REGISTRY= deploy +make SUPERVISOR_VERSION=${ESCAPED_BRANCH_NAME} \ + ARCH=${ARCH} \ + JOB_NAME=${JOB_NAME} \ + DEPLOY_REGISTRY= \ + PUBNUB_SUBSCRIBE_KEY=${PUBNUB_SUBSCRIBE_KEY} \ + PUBNUB_PUBLISH_KEY=${PUBNUB_PUBLISH_KEY} \ + MIXPANEL_TOKEN=${MIXPANEL_TOKEN} \ + deploy +make SUPERVISOR_VERSION=${VERSION} \ + ARCH=${ARCH} \ + JOB_NAME=${JOB_NAME} \ + DEPLOY_REGISTRY= \ + PUBNUB_SUBSCRIBE_KEY=${PUBNUB_SUBSCRIBE_KEY} \ + PUBNUB_PUBLISH_KEY=${PUBNUB_PUBLISH_KEY} \ + MIXPANEL_TOKEN=${MIXPANEL_TOKEN} \ + deploy diff --git a/src/config.coffee b/src/config.coffee index aa2189aa..34d4f5d0 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -7,15 +7,21 @@ checkInt = (s) -> return return i +checkValidKey = (s) -> + # Make sure `s` exists and is not an empty string, or 'null'. + if !s? or s == 'null' or s == '' + return + return s + module.exports = config = apiEndpoint: process.env.API_ENDPOINT ? 'https://api.resin.io' listenPort: process.env.LISTEN_PORT ? 80 gosuperAddress: "http://unix:#{process.env.GOSUPER_SOCKET}:" registryEndpoint: process.env.REGISTRY_ENDPOINT ? 'registry.resin.io' pubnub: - subscribe_key: process.env.PUBNUB_SUBSCRIBE_KEY ? 'sub-c-bananas' - publish_key: process.env.PUBNUB_PUBLISH_KEY ? 'pub-c-bananas' - mixpanelToken: process.env.MIXPANEL_TOKEN ? 'bananasbananas' + subscribe_key: checkValidKey(process.env.PUBNUB_SUBSCRIBE_KEY) ? process.env.DEFAULT_PUBNUB_SUBSCRIBE_KEY + publish_key: checkValidKey(process.env.PUBNUB_PUBLISH_KEY) ? process.env.DEFAULT_PUBNUB_PUBLISH_KEY + mixpanelToken: checkValidKey(process.env.MIXPANEL_TOKEN) ? process.env.DEFAULT_MIXPANEL_TOKEN dockerSocket: process.env.DOCKER_SOCKET ? '/run/docker.sock' supervisorImage: process.env.SUPERVISOR_IMAGE ? 'resin/rpi-supervisor' configMountPoint: process.env.CONFIG_MOUNT_POINT ? '/mnt/mmcblk0p1/config.json'