From 33d402c3c03b2acc3793f4ae0851de665921869e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Carranza=20V=C3=A9lez?= Date: Wed, 14 Oct 2015 16:53:33 -0300 Subject: [PATCH 1/2] Default PubNub and Mixpanel keys are now passed at build time --- CHANGELOG.md | 2 ++ Makefile | 7 +++++++ automation/jenkins_build.sh | 18 ++++++++++++++++-- src/config.coffee | 6 +++--- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd95ea6..f6ba1684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Remove default Pubnub and Mixpanel keys as they are now passed at build time [Pablo] + # v1.1.0 * Switch back to using arch-based node images [Pablo] diff --git a/Makefile b/Makefile index 500b580c..d166ed3b 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 PUBNUB_PUBLISH_KEY $(PUBNUB_PUBLISH_KEY)" >> Dockerfile + echo "ENV PUBNUB_SUBSCRIBE_KEY $(PUBNUB_SUBSCRIBE_KEY)" >> Dockerfile + echo "ENV 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..b05ac889 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -13,9 +13,9 @@ module.exports = config = 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: process.env.PUBNUB_SUBSCRIBE_KEY ? '' + publish_key: process.env.PUBNUB_PUBLISH_KEY ? '' + mixpanelToken: process.env.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' From 4bcba5adf6101ab8ace761cad7d02c6384de326f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Carranza=20V=C3=A9lez?= Date: Wed, 14 Oct 2015 18:50:26 -0300 Subject: [PATCH 2/2] Refactor to use a different name for the env vars (otherwise resin-vars overrides it with a null value) --- CHANGELOG.md | 2 +- Makefile | 6 +++--- src/config.coffee | 12 +++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6ba1684..387816e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -* Remove default Pubnub and Mixpanel keys as they are now passed at build time [Pablo] +* Use buildtime env vars as the default Pubnub and Mixpanel keys [Pablo] # v1.1.0 diff --git a/Makefile b/Makefile index d166ed3b..a7a19d58 100644 --- a/Makefile +++ b/Makefile @@ -58,9 +58,9 @@ stop-supervisor: supervisor: gosuper cp Dockerfile.$(ARCH) Dockerfile echo "ENV VERSION "`jq -r .version package.json` >> Dockerfile - echo "ENV PUBNUB_PUBLISH_KEY $(PUBNUB_PUBLISH_KEY)" >> Dockerfile - echo "ENV PUBNUB_SUBSCRIBE_KEY $(PUBNUB_SUBSCRIBE_KEY)" >> Dockerfile - echo "ENV MIXPANEL_TOKEN $(MIXPANEL_TOKEN)" >> 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/src/config.coffee b/src/config.coffee index b05ac889..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 ? '' - publish_key: process.env.PUBNUB_PUBLISH_KEY ? '' - mixpanelToken: process.env.MIXPANEL_TOKEN ? '' + 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'