mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: move docker-compose to this repo (#2666)
Use latest official image for Unleash for simplicity. Also takes away the proxy as it is not needed anymore.
This commit is contained in:
parent
cef4181f11
commit
10aa79eb56
@ -34,8 +34,8 @@ With [`git`](https://git-scm.com/) and [`docker`](https://www.docker.com/) insta
|
||||
Run this script:
|
||||
|
||||
```bash
|
||||
git clone git@github.com:Unleash/unleash-docker.git
|
||||
cd unleash-docker
|
||||
git clone git@github.com:Unleash/unleash.git
|
||||
cd unleash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
@ -53,8 +53,8 @@ Find your preferred SDK in [our list of official SDKs](#unleash-sdks) and import
|
||||
If you use the docker compose file from the previous step, here's the configuration details you'll need to get going:
|
||||
|
||||
- For front-end SDKs, use:
|
||||
- URL: `http://localhost:3000/proxy`
|
||||
- `clientKey`: `proxy-client-key`
|
||||
- URL: `http://localhost:4242/api/frontend/`
|
||||
- `clientKey`: `default:development.unleash-insecure-frontend-api-token`
|
||||
- For server-side SDKs, use:
|
||||
- Unleash API URL: `http://localhost:4242/api/`
|
||||
- API token: `default:development.unleash-insecure-api-token`
|
||||
|
63
docker-compose.yml
Normal file
63
docker-compose.yml
Normal file
@ -0,0 +1,63 @@
|
||||
# This docker compose setup configures:
|
||||
# - the Unleash server instance + the necessary backing Postgres database
|
||||
# - the Unleash proxy
|
||||
#
|
||||
# To learn more about all the parts of Unleash, visit
|
||||
# https://docs.getunleash.io
|
||||
#
|
||||
# NOTE: please do not use this configuration for production setups.
|
||||
# Unleash does not take responsibility for any data leaks or other
|
||||
# problems that may arise as a result.
|
||||
#
|
||||
# This is intended to be used for demo, development, and learning
|
||||
# purposes only.
|
||||
|
||||
version: "3.9"
|
||||
services:
|
||||
|
||||
# The Unleash server contains the Unleash configuration and
|
||||
# communicates with server-side SDKs and the Unleash Proxy
|
||||
web:
|
||||
image: unleashorg/unleash-server:latest
|
||||
ports:
|
||||
- "4242:4242"
|
||||
environment:
|
||||
# This points Unleash to its backing database (defined in the `db` section below)
|
||||
DATABASE_URL: "postgres://postgres:unleash@db/postgres"
|
||||
# Disable SSL for database connections. @chriswk: why do we do this?
|
||||
DATABASE_SSL: "false"
|
||||
# Changing log levels:
|
||||
LOG_LEVEL: "warn"
|
||||
# Proxy clients must use one of these keys to connect to the
|
||||
# Proxy. To add more keys, separate them with a comma (`key1,key2`).
|
||||
INIT_FRONTEND_API_TOKENS: "default:development.unleash-insecure-frontend-api-token"
|
||||
# Initialize Unleash with a default set of client API tokens. To
|
||||
# initialize Unleash with multiple tokens, separate them with a
|
||||
# comma (`token1,token2`).
|
||||
INIT_CLIENT_API_TOKENS: "default:development.unleash-insecure-api-token"
|
||||
depends_on:
|
||||
- db
|
||||
volumes:
|
||||
- ./scripts:/scripts
|
||||
command: ["/scripts/wait-for", "db:5432", "--", "node", "index.js"]
|
||||
healthcheck:
|
||||
test: wget --no-verbose --tries=1 --spider http://localhost:4242/health || exit 1
|
||||
interval: 1s
|
||||
timeout: 1m
|
||||
retries: 5
|
||||
start_period: 15s
|
||||
db:
|
||||
expose:
|
||||
- "5432"
|
||||
image: postgres:14
|
||||
environment:
|
||||
# create a database called `db`
|
||||
POSTGRES_DB: "db"
|
||||
# trust incoming connections blindly (DON'T DO THIS IN PRODUCTION!)
|
||||
POSTGRES_HOST_AUTH_METHOD: "trust"
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "--username=postgres", "--host=127.0.0.1", "--port=5432"]
|
||||
interval: 2s
|
||||
timeout: 1m
|
||||
retries: 5
|
||||
start_period: 10s
|
191
scripts/wait-for
Executable file
191
scripts/wait-for
Executable file
@ -0,0 +1,191 @@
|
||||
#!/bin/sh
|
||||
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2017 Eficode Oy
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
VERSION="2.2.3"
|
||||
|
||||
set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
|
||||
TIMEOUT=15
|
||||
QUIET=0
|
||||
# The protocol to make the request with, either "tcp" or "http"
|
||||
PROTOCOL="tcp"
|
||||
|
||||
echoerr() {
|
||||
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
|
||||
}
|
||||
|
||||
usage() {
|
||||
exitcode="$1"
|
||||
cat << USAGE >&2
|
||||
Usage:
|
||||
$0 host:port|url [-t timeout] [-- command args]
|
||||
-q | --quiet Do not output any status messages
|
||||
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
|
||||
-v | --version Show the version of this tool
|
||||
-- COMMAND ARGS Execute command with args after the test finishes
|
||||
USAGE
|
||||
exit "$exitcode"
|
||||
}
|
||||
|
||||
wait_for() {
|
||||
case "$PROTOCOL" in
|
||||
tcp)
|
||||
if ! command -v nc >/dev/null; then
|
||||
echoerr 'nc command is missing!'
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
http)
|
||||
if ! command -v wget >/dev/null; then
|
||||
echoerr 'wget command is missing!'
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
TIMEOUT_END=$(($(date +%s) + TIMEOUT))
|
||||
|
||||
while :; do
|
||||
case "$PROTOCOL" in
|
||||
tcp)
|
||||
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
|
||||
;;
|
||||
http)
|
||||
wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
|
||||
;;
|
||||
*)
|
||||
echoerr "Unknown protocol '$PROTOCOL'"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
result=$?
|
||||
|
||||
if [ $result -eq 0 ] ; then
|
||||
if [ $# -gt 7 ] ; then
|
||||
for result in $(seq $(($# - 7))); do
|
||||
result=$1
|
||||
shift
|
||||
set -- "$@" "$result"
|
||||
done
|
||||
|
||||
TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
|
||||
shift 7
|
||||
exec "$@"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $TIMEOUT -ne 0 -a $(date +%s) -ge $TIMEOUT_END ]; then
|
||||
echo "Operation timed out" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
while :; do
|
||||
case "$1" in
|
||||
http://*|https://*)
|
||||
HOST="$1"
|
||||
PROTOCOL="http"
|
||||
shift 1
|
||||
;;
|
||||
*:* )
|
||||
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
|
||||
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
|
||||
shift 1
|
||||
;;
|
||||
-v | --version)
|
||||
echo $VERSION
|
||||
exit
|
||||
;;
|
||||
-q | --quiet)
|
||||
QUIET=1
|
||||
shift 1
|
||||
;;
|
||||
-q-*)
|
||||
QUIET=0
|
||||
echoerr "Unknown option: $1"
|
||||
usage 1
|
||||
;;
|
||||
-q*)
|
||||
QUIET=1
|
||||
result=$1
|
||||
shift 1
|
||||
set -- -"${result#-q}" "$@"
|
||||
;;
|
||||
-t | --timeout)
|
||||
TIMEOUT="$2"
|
||||
shift 2
|
||||
;;
|
||||
-t*)
|
||||
TIMEOUT="${1#-t}"
|
||||
shift 1
|
||||
;;
|
||||
--timeout=*)
|
||||
TIMEOUT="${1#*=}"
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
--help)
|
||||
usage 0
|
||||
;;
|
||||
-*)
|
||||
QUIET=0
|
||||
echoerr "Unknown option: $1"
|
||||
usage 1
|
||||
;;
|
||||
*)
|
||||
QUIET=0
|
||||
echoerr "Unknown argument: $1"
|
||||
usage 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
|
||||
echoerr "Error: invalid timeout '$TIMEOUT'"
|
||||
usage 3
|
||||
fi
|
||||
|
||||
case "$PROTOCOL" in
|
||||
tcp)
|
||||
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
|
||||
echoerr "Error: you need to provide a host and port to test."
|
||||
usage 2
|
||||
fi
|
||||
;;
|
||||
http)
|
||||
if [ "$HOST" = "" ]; then
|
||||
echoerr "Error: you need to provide a host to test."
|
||||
usage 2
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
wait_for "$@"
|
@ -282,6 +282,10 @@ const loadInitApiTokens = () => {
|
||||
process.env.INIT_CLIENT_API_TOKENS,
|
||||
ApiTokenType.CLIENT,
|
||||
),
|
||||
...loadTokensFromString(
|
||||
process.env.INIT_FRONTEND_API_TOKENS,
|
||||
ApiTokenType.FRONTEND,
|
||||
),
|
||||
];
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user