mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 01:42:37 +08:00
Merge pull request #3857 from johscheuer/update-python-sample-app
Update Python Docker sample app
This commit is contained in:
commit
0795bcbcf2
@ -20,7 +20,8 @@
|
||||
COMPOSE_PROJECT_NAME=fdbpythonsample
|
||||
|
||||
FDB_API_VERSION=620
|
||||
FDB_VERSION=6.2.11
|
||||
FDB_VERSION=6.2.26
|
||||
FDB_COORDINATOR=fdb-coordinator
|
||||
FDB_NETWORKING_MODE=container
|
||||
FDB_COORDINATOR_PORT=4500
|
||||
FDB_COORDINATOR_PORT=4500
|
||||
FDB_ADDITIONAL_VERSIONS=""
|
||||
|
@ -11,13 +11,14 @@ docker-compose up -d
|
||||
```
|
||||
|
||||
This will start:
|
||||
* 1 coordinator,
|
||||
* 2 fdbservers,
|
||||
* 1 Flask application.
|
||||
|
||||
* 1 coordinator
|
||||
* 2 fdbservers
|
||||
* 1 Flask application
|
||||
|
||||
The Flask application can be accessed using curl:
|
||||
|
||||
```sh
|
||||
```bash
|
||||
# retrieve counter
|
||||
curl http://0.0.0.0:5000/counter # 0
|
||||
|
||||
@ -29,7 +30,6 @@ curl -X POST http://0.0.0.0:5000/counter/increment # 2
|
||||
curl http://0.0.0.0:5000/counter # 2
|
||||
```
|
||||
|
||||
|
||||
## Access the FoundationDB cluster
|
||||
|
||||
If you want to access the cluster from your machine, here's a `cluster file` ready for you:
|
||||
@ -41,10 +41,10 @@ FDB_CLUSTER_FILE=./docker.cluster fdbcli
|
||||
|
||||
## Stop the Python demo
|
||||
|
||||
```
|
||||
```bash
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
## Use outside of docker-compose
|
||||
|
||||
The client application is also available as a standalone image: `foundationdb/foundationdb-sample-python-app:latest`.
|
||||
The client application is also available as a standalone image: `foundationdb/foundationdb-sample-python-app:latest`.
|
||||
|
@ -20,9 +20,9 @@
|
||||
ARG FDB_VERSION
|
||||
|
||||
FROM foundationdb/foundationdb:${FDB_VERSION} as fdb
|
||||
FROM python:3.8
|
||||
FROM python:3.8-slim
|
||||
|
||||
RUN apt-get update; apt-get install -y dnsutils
|
||||
RUN apt-get update; apt-get install -y dnsutils curl && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir -p /app
|
||||
WORKDIR /app
|
||||
@ -32,12 +32,11 @@ COPY --from=fdb /usr/bin/fdbcli /usr/bin/
|
||||
COPY --from=fdb /var/fdb/scripts/create_cluster_file.bash /app
|
||||
|
||||
ARG FDB_WEBSITE=https://foundationdb.org
|
||||
ARG FDB_OLDER_VERSIONS=""
|
||||
ARG FDB_ADDITIONAL_VERSIONS
|
||||
ENV FDB_NETWORK_OPTION_EXTERNAL_CLIENT_DIRECTORY=/usr/lib/fdb-multiversion
|
||||
RUN \
|
||||
mkdir /usr/lib/fdb-multiversion; \
|
||||
for version in ${FDB_OLDER_VERSIONS}; do \
|
||||
wget ${FDB_WEBSITE}/downloads/$version/linux/libfdb_c_$version.so -O /usr/lib/fdb-multiversion/libfdb_c_$version.so; \
|
||||
RUN mkdir /usr/lib/fdb-multiversion; \
|
||||
for version in ${FDB_ADDITIONAL_VERSIONS}; do \
|
||||
curl ${FDB_WEBSITE}/downloads/$version/linux/libfdb_c_$version.so -o /usr/lib/fdb-multiversion/libfdb_c_$version.so; \
|
||||
done
|
||||
|
||||
COPY requirements.txt /app
|
||||
|
@ -18,4 +18,4 @@
|
||||
#
|
||||
|
||||
Flask==1.1.1
|
||||
foundationdb==6.1.11
|
||||
foundationdb==6.2.10
|
||||
|
@ -17,16 +17,16 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import os
|
||||
from flask import Flask
|
||||
import fdb
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
fdb.api_version(int(os.getenv('FDB_API_VERSION')))
|
||||
db=fdb.open()
|
||||
db = fdb.open()
|
||||
|
||||
COUNTER_KEY=fdb.tuple.pack(('counter',))
|
||||
COUNTER_KEY = fdb.tuple.pack(('counter',))
|
||||
def _increment_counter(tr):
|
||||
counter_value = tr[COUNTER_KEY]
|
||||
if counter_value == None:
|
||||
@ -41,9 +41,9 @@ def get_counter():
|
||||
counter_value = db[COUNTER_KEY]
|
||||
if counter_value == None:
|
||||
return '0'
|
||||
else:
|
||||
return str(fdb.tuple.unpack(counter_value)[0])
|
||||
|
||||
return str(fdb.tuple.unpack(counter_value)[0])
|
||||
|
||||
@app.route("/counter/increment", methods=['POST'])
|
||||
def increment_counter():
|
||||
return str(_increment_counter(db))
|
||||
return str(_increment_counter(db))
|
||||
|
@ -21,18 +21,18 @@
|
||||
|
||||
set -xe;
|
||||
|
||||
if [[ ! -n "${FDB_CLUSTER_FILE:-}" || ! -s "${FDB_CLUSTER_FILE}" ]]; then
|
||||
if [[ -z "${FDB_CLUSTER_FILE:-}" || ! -s "${FDB_CLUSTER_FILE}" ]]; then
|
||||
/app/create_cluster_file.bash
|
||||
FDB_CLUSTER_FILE="${FDB_CLUSTER_FILE:-/etc/foundationdb/fdb.cluster}"
|
||||
|
||||
# Attempt to connect. Configure the database if necessary.
|
||||
if ! /usr/bin/fdbcli -C $FDB_CLUSTER_FILE --exec status --timeout 3 ; then
|
||||
if ! /usr/bin/fdbcli -C "${FDB_CLUSTER_FILE}" --exec status --timeout 3 ; then
|
||||
echo "creating the database"
|
||||
if ! fdbcli -C $FDB_CLUSTER_FILE --exec "configure new single memory ; status" --timeout 10 ; then
|
||||
if ! fdbcli -C "${FDB_CLUSTER_FILE}" --exec "configure new single memory ; status" --timeout 10 ; then
|
||||
echo "Unable to configure new FDB cluster."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
FLASK_APP=server.py flask run --host=0.0.0.0
|
||||
FLASK_APP=server.py flask run --host=0.0.0.0
|
||||
|
@ -55,6 +55,7 @@ services:
|
||||
context: app
|
||||
args:
|
||||
FDB_VERSION: ${FDB_VERSION}
|
||||
FDB_ADDITIONAL_VERSIONS: ${FDB_ADDITIONAL_VERSIONS}
|
||||
ports:
|
||||
- 5000:5000/tcp
|
||||
environment:
|
||||
|
Loading…
x
Reference in New Issue
Block a user