Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup an arangod container with initial data #22

Closed
m0ppers opened this issue Apr 11, 2016 · 4 comments
Closed

Startup an arangod container with initial data #22

m0ppers opened this issue Apr 11, 2016 · 4 comments

Comments

@m0ppers
Copy link
Contributor

m0ppers commented Apr 11, 2016

suggestion by @iamacup on the community channel

useful for application bootstrapping (initial data). import data from a mounted directory.

postgres is doing that:

https://github.com/docker-library/postgres/blob/8e867c8ba0fc8fd347e43ae53ddeba8e67242a53/9.5/docker-entrypoint.sh#L79

downside: more complexity in the dockerfile (while it could easily be implemented in a derived docker image)
upside: very convenient and very beginner friendly

needs discussion

#!/bin/bash
set -eo pipefail
​
DISABLE_AUTHENTICATION="true"
​
function rwfail {
  echo "We seem to not have proper rw access to $1. Please make sure that every mounted volume has full rw access for user arangodb ($(id arangodb))"
  exit 55
}
​
# if command starts with an option, prepend arangod
if [ "${1:0:1}" = '-' ]; then
  set -- arangod "$@"
fi
​
​
if [ "$1" = 'arangod' ]; then
  DATADIR=/var/lib/arangodb

        # ensure proper uid and gid (for example when volume is mounted from the outside)
        # do NOT chown or stuff like that. when using shared folders on the mac chown is VERY likely to fail due to docker => vm => host issues
        touch "$DATADIR"/_rwcheck_$HOSTNAME || rwfail $DATADIR
        rm "$DATADIR"/_rwcheck_"$HOSTNAME"
        touch /var/lib/arangodb-apps/_rwcheck_"$HOSTNAME" || rwfail /var/lib/arangodb-apps/
        rm /var/lib/arangodb-apps/_rwcheck_"$HOSTNAME"
  if [ ! -f "$DATADIR"/SERVER ]; then
    if [ -z "$ARANGO_ROOT_PASSWORD" -a -z "$ARANGO_NO_AUTH" -a -z "$ARANGO_RANDOM_ROOT_PASSWORD" ]; then
      echo >&2 'error: database is uninitialized and password option is not specified '
      echo >&2 '  You need to specify one of $ARANGO_ROOT_PASSWORD, $ARANGO_NO_AUTH and $ARANGO_RANDOM_ROOT_PASSWORD'
      exit 1
    fi

                echo "Initializing database...Hang on..."
                if [ ! -z "$ARANGO_RANDOM_ROOT_PASSWORD" ]; then
                  ARANGO_ROOT_PASSWORD=$(pwgen -s -1 16)
                  echo "==========================================="
                  echo "GENERATED ROOT PASSWORD: $ARANGO_ROOT_PASSWORD"
                  echo "==========================================="
                fi

                if [ ! -z "$ARANGO_ROOT_PASSWORD" ]; then
                  (
                    echo "require(\"org/arangodb/users\").replace(\"root\", \"$ARANGO_ROOT_PASSWORD\");"
                  ) |
                  /usr/sbin/arangod --console --log.tty "" &> /dev/null
                  DISABLE_AUTHENTICATION="false"
                fi
                # Initialize if not already done
                /usr/sbin/arangod --console --upgrade
  fi
fi
​
if [ "$1" == "arangod" ]; then
  # if we really want to start arangod and not bash or any other thing
  # prepend --disable-authentication as the FIRST argument
  # (so it is overridable via command line as well)
  shift
  set -- arangod --server.disable-authentication="$DISABLE_AUTHENTICATION" "$@"
fi
​
#this overrides the file here: https://github.com/arangodb/arangodb-docker/blob/official/jessie/2.8.7/docker-entrypoint.sh and is an exact copy apart from this block - Added to load initial data from /opt/arango-bare into the database
( { 
    function runner 
    { 
        echo "Checking to see if db is up..."; 

        STR="use strict; 
        use warnings; 
        use IO::Socket; 

        my \$socket = IO::Socket::INET->new( 
            PeerAddr => \"127.0.0.1:8529\", 
            PeerPort => \"http(8529)\", 
            Proto => \"tcp\") or print \"not ok\"; 
        print \"ok\""; 

        OUTVAR=$(/usr/bin/perl -e "$STR"); 

        if [ "$OUTVAR" == "ok" ]; then 
          echo "Database is up. Running startup scrips." && arangorestore --server.password $ARANGO_ROOT_PASSWORD --server.username 'root' --input-directory '/opt/arango-bare'; 
        else 
          sleep 2 && runner;
        fi 
    }; 

    runner; 
} )&
​
exec "$@"
@iamacup
Copy link

iamacup commented Apr 11, 2016

Hi - thanks for making this Mop. It will need a couple of tweeks to be production ready. I think at least:

  1. There needs to be a way of specifying all command line options for arangostore(https://docs.arangodb.com/HttpBulkImports/Arangorestore.html), either as part of the docker run command or elsewhere - at th moment this is all hard coded
  2. The script that tests for up-time needs to cope for different port numbers if the docker run command allows for setting a different listen port for the Arango instance
  3. This script always looks in /opt/arango-bare for the arangostore input - this should either be a variable for docker-run or some directory that team-arango standardise

I find this feature super-useful for getting going quickly with Postgres - i expect people would find it as useful when testing out Arango.

@m0ppers
Copy link
Contributor Author

m0ppers commented Jul 12, 2016

fixed since 3.0

@m0ppers m0ppers closed this as completed Jul 12, 2016
@webmobiles
Copy link

on a mac i have similar error, I've followed the installation guide on arangodb site:

docker run -p 8529:8529 arangodb/arangodb:3.1.24
Unable to find image 'arangodb/arangodb:3.1.24' locally
3.1.24: Pulling from arangodb/arangodb
5040bd298390: Pull complete 
5153f9ee24e2: Pull complete 
b050383580c3: Pull complete 
36b72103d51f: Pull complete 
883ee75e86be: Pull complete 
0855a96205ed: Pull complete 
Digest: sha256:d73badb54c0ccbcdb92e59ad340c7a2d5213a836c25c2820782697fdeb159b18
Status: Downloaded newer image for arangodb/arangodb:3.1.24
error: database is uninitialized and password option is not specified 
  You need to specify one of ARANGO_ROOT_PASSWORD, ARANGO_NO_AUTH and ARANGO_RANDOM_ROOT_PASSWORD

@GillesBodart
Copy link

On a debian 9 I've the same issue

docker run -p 8529:8529 arangodb/arangodb:3.1.24
Unable to find image 'arangodb/arangodb:3.1.24' locally
3.1.24: Pulling from arangodb/arangodb
5040bd298390: Pull complete
5153f9ee24e2: Pull complete
b050383580c3: Pull complete
36b72103d51f: Pull complete
883ee75e86be: Pull complete
0855a96205ed: Pull complete
Digest: sha256:d73badb54c0ccbcdb92e59ad340c7a2d5213a836c25c2820782697fdeb159b18
Status: Downloaded newer image for arangodb/arangodb:3.1.24
error: database is uninitialized and password option is not specified
You need to specify one of ARANGO_ROOT_PASSWORD, ARANGO_NO_AUTH and ARANGO_RANDOM_ROOT_PASSWORD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants