Last active
February 12, 2021 03:17
-
-
Save pjz/255d6db6fb82dd50917c to your computer and use it in GitHub Desktop.
An idempotent start script for huginn under docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## these need to be set | |
# initial account credentials | |
SEED_USER=admin | |
SEED_PASS=password | |
# required for new users to be able to sign up ; default to something random | |
INVITATION_CODE=`dd if=/dev/urandom bs=1024 count=1 | md5sum -` | |
# password you want to use for your mysql database | |
DB_PASS=huginn_mysql_password | |
# local host:port or just port to bind to | |
BIND_TO=127.0.0.1:3000 | |
# shouldn't need to change below here | |
HUGIN_DBENV="-e DATABASE_NAME=huginn_development -e DATABASE_USERNAME=root -e DATABASE_PASSWORD=$DB_PASS -e INVITATION_CODE=$INVITATION_CODE" | |
HUGIN_SEEDENV="-e SEED_USERNAME=$SEED_USER -e SEED_PASSWORD=$SEED_PASS" | |
container_exists() { | |
`docker inspect -f=x $1 >/dev/null 2>&1` | |
} | |
container_running() { | |
[ `docker inspect --format '{{ .State.Running }}' $1` = "true" ] | |
} | |
if ! container_exists huginn-mysql ; then | |
APP_SECRET=${APP_SECRET:-$(docker run --rm andrewcurioso/huginn rake secret)} | |
HUGIN_APPENV="-e APP_SECRET_TOKEN=$APP_SECRET" | |
# create mysql server | |
docker run --name huginn-mysql -e MYSQL_ROOT_PASSWORD=$DB_PASS -d mysql | |
# create database | |
docker run --rm --link huginn-mysql:db $HUGIN_DBENV $HUGIN_APPENV $HUGIN_SEEDENV andrewcurioso/huginn rake db:create db:migrate db:seed | |
elif ! container_running huginn-mysql ; then | |
docker start huginn-mysql | |
else | |
echo "huginn-mysql already running." | |
fi | |
if ! container_exists huginn ; then | |
# this can be slow | |
APP_SECRET=${APP_SECRET:-$(docker run --rm andrewcurioso/huginn rake secret)} | |
HUGIN_APPENV="-e APP_SECRET_TOKEN=$APP_SECRET" | |
docker run --name huginn --link huginn-mysql:db $HUGIN_DBENV $HUGIN_APPENV -p ${BIND_TO}:3000 -d andrewcurioso/huginn | |
elif ! container_running huginn ; then | |
docker start huginn | |
else | |
echo "huginn already running." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment