diff --git a/deploy_stack.sh b/deploy_stack.sh index aaea8aa1c..c38ce9177 100755 --- a/deploy_stack.sh +++ b/deploy_stack.sh @@ -5,6 +5,50 @@ if ! [ -x "$(command -v docker)" ]; then exit 1 fi -echo "Deploying stack" -docker stack deploy func --compose-file docker-compose.yml +export BASIC_AUTH="true" + +sha_cmd="shasum -a 256" +if ! command -v shasum >/dev/null; then + sha_cmd="sha256sum" +fi + +while [ ! $# -eq 0 ] +do + case "$1" in + --no-auth | -n) + export BASIC_AUTH="false" + ;; + --help | -h) + echo "Usage: \n [default]\tdeploy the OpenFaaS core services\n --no-auth [-n]\tdisable basic authentication.\n --help\tdisplays this screen" + exit + ;; + esac + shift +done + +# Secrets should be created even if basic-auth is disabled. +echo "Attempting to create credentials for gateway.." +echo "admin" | docker secret create basic-auth-user - +secret=$(head -c 16 /dev/urandom| $sha_cmd | cut -d " " -f 1) +echo "$secret" | docker secret create basic-auth-password - +if [ $? = 0 ]; +then + echo "[Credentials]\n username: admin \n password: $secret\n echo -n "$secret" | faas-cli login --username=admin --password-stdin" +else + echo "[Credentials]\n already exist, not creating" +fi + +if [ $BASIC_AUTH = "true" ]; +then + echo "" + echo "Enabling basic authentication for gateway.." + echo "" +else + echo "" + echo "Disabling basic authentication for gateway.." + echo "" +fi +echo "Deploying OpenFaaS core services" + +docker stack deploy func --compose-file docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml index aaa985ff9..683f69168 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: gateway: ports: - 8080:8080 - image: openfaas/gateway:0.8.3 + image: openfaas/gateway:0.8.5 networks: - functions environment: @@ -16,7 +16,7 @@ services: faas_nats_port: 4222 direct_functions: "true" # Functions are invoked directly over the overlay network direct_functions_suffix: "" - basic_auth: "false" + basic_auth: "${BASIC_AUTH:-true}" secret_mount_path: "/run/secrets/" deploy: resources: @@ -32,9 +32,9 @@ services: placement: constraints: - 'node.platform.os == linux' - # secrets: - # - basic-auth-user - # - basic-auth-password + secrets: + - basic-auth-user + - basic-auth-password # Docker Swarm provider faas-swarm: @@ -180,8 +180,8 @@ networks: labels: - "openfaas=true" -# secrets: -# basic-auth-user: -# external: true -# basic-auth-password: -# external: true +secrets: + basic-auth-user: + external: true + basic-auth-password: + external: true