Skip to content

Instantly share code, notes, and snippets.

@vst
Last active March 11, 2020 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vst/685ec02fb5caf69bb4bd8fac24727821 to your computer and use it in GitHub Desktop.
Save vst/685ec02fb5caf69bb4bd8fac24727821 to your computer and use it in GitHub Desktop.
Setting up an OpenFAAS Gateway (using Docker Swarm)

Setting up an OpenFAAS Gateway (using Docker Swarm)

Note: For the Docker Swarm setup, check out the official guide.

bash setup.sh [<OPENFAAS-HOME-DIRECTORY>]

whereby OPENFAAS-HOME-DIRECTORY defaults to /data/openfaas.

Note down the credentials which you will need later.

#!/usr/bin/env bash
## Stop on errors:
set -e
## Get the OpenFAAS home:
OPENFAAS_HOME="${1:-/data/openfaas}"
## Check if the OpenFAAS home can be created later:
echo "Checking if OpenFAAS home can be created..."
if mkdir "${OPENFAAS_HOME}"; then
echo "OpenFAAS home can be created. Proceeding..."
rmdir "${OPENFAAS_HOME}"
else
echo "OpenFAAS home can not be created. Exiting..." >&2
exit 1
fi
## Check if we have swarm. If yes, stop as we do not want to mess up.
if docker info 2>&1 | grep -o "Swarm: active" > /dev/null; then
echo "We already have a swarm. Exiting..." >&2
exit 1
else
echo "No swarm detected. Creating..."
docker swarm init
fi
## Clone OpenFAAS repository:
echo "Cloning OpenFAAS repository..."
git clone https://github.com/openfaas/faas "${OPENFAAS_HOME}"
## Deploy OpenFAAS stack:
echo "Deploying OpenFAAS stack..."
cd "${OPENFAAS_HOME}" || exit 1
./deploy_stack.sh
cd - || exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment