docker-vernemq icon indicating copy to clipboard operation
docker-vernemq copied to clipboard

Added env API_KEY to add api key at runtime

Open dvdred opened this issue 4 years ago • 4 comments

Can be used in docker-compose.yml: ... environment: - API_KEY=MyApiKey

dvdred avatar Mar 04 '20 17:03 dvdred

@dvdred thanks... can you explain why this is needed? is it a backward compatible addition? (if yes, I'll merge this)

ioolkos avatar Mar 20 '20 13:03 ioolkos

hello, sorry for the delay! the change was useful to me because I am using vernemq on docker swarm and I need to set an api key at runtime taking it's value froma a docker env. I have not found any other way.

dvdred avatar Apr 01 '20 15:04 dvdred

I'm also looking for this feature. Right now my startup script has to wait for the nodes to be reachable. Then I can try to add the key using the vmq-admin command. I have trouble getting this to work flawlessly 100% of the time. Being able to set the key using a environment variable would be awesome!

JesseLabruyere avatar Jan 21 '21 16:01 JesseLabruyere

You can do it by creating your own image derived from vernemq and override some directive

COPY commands.sh /scripts/commands.sh
RUN ["chmod", "+x", "/scripts/commands.sh"]
ENTRYPOINT ["/scripts/commands.sh"]

then you can start VerneMQ and start a command for building a key

#!/bin/bash
echo "Starting Hub"
echo "##############################################"
echo "$API_KEY"
start_vernemq & 
/bin/sh -c "sleep 30 ; vmq-admin api-key add key=$API_KEY"
fg %1

$API_KEY is an env var. Just add it to your compose file.

Result in shell after 30 sec

root@a8396e7ef459:/node/app# vmq-admin api-key show
+----------------------------------+
| Key                              |
+----------------------------------+
| YOURAPIKEY |
+----------------------------------+
root@a8396e7ef459:/node/app# 

SebUndefined avatar May 09 '21 15:05 SebUndefined

Can this be added to standard env keys?

ashtonian avatar Nov 08 '22 22:11 ashtonian

Can this be added to standard env keys?

@Ashtonian could be done, yes. by adding a mapping to the vmq_server schema file. (and some additional handling at boot time to add the API key to a config table as well)


:point_right: Thank you for supporting VerneMQ: https://github.com/sponsors/vernemq :point_right: Using the binary VerneMQ packages commercially (.deb/.rpm/Docker) requires a paid subscription.

ioolkos avatar Nov 09 '22 17:11 ioolkos

Closing, as we merged https://github.com/vernemq/docker-vernemq/pull/369. Thank you again to everyone who helped out here!

ioolkos avatar Nov 06 '23 17:11 ioolkos