Skip to content

Commit

Permalink
Merge pull request #4 from scalableminds/python-client
Browse files Browse the repository at this point in the history
add backup client (python)
  • Loading branch information
jstriebel authored Nov 27, 2017
2 parents de023c1 + a44fa79 commit 2e84bed
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 7 deletions.
39 changes: 32 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
jobs:
build_and_deploy:
build_and_push_db:
machine:
image: circleci/classic:latest
environment:
Expand All @@ -15,7 +15,7 @@ jobs:
- restore_cache:
key: cache-{{ .Branch }}
- run:
name: build
name: Build server
command: docker-compose run sbt sbt assembly
- save_cache:
key: cache-{{ .Branch }}
Expand All @@ -24,20 +24,45 @@ jobs:
- "~/.ivy2"
- "~/.sbt"
- run:
name: build docker
command: docker build -t scalableminds/fossildb:${CIRCLE_BRANCH}__${CIRCLE_BUILD_NUM} .
name: Build server docker image
command: |
docker build \
-t scalableminds/fossildb:${CIRCLE_BRANCH}__${CIRCLE_BUILD_NUM} \
-t scalableminds/fossildb:${CIRCLE_BRANCH} \
.
- run:
name: deployment
name: Push to DockerHub
command: |
set -x
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker tag scalableminds/fossildb:${CIRCLE_BRANCH}__${CIRCLE_BUILD_NUM} scalableminds/fossildb:${CIRCLE_BRANCH}
docker push scalableminds/fossildb:${CIRCLE_BRANCH}__${CIRCLE_BUILD_NUM}
docker push scalableminds/fossildb:${CIRCLE_BRANCH}
docker logout
build_and_push_client:
machine:
image: circleci/classic:latest
steps:
- checkout
- run:
name: Build client docker image
command: |
docker build \
-f client/Dockerfile \
-t scalableminds/fossildb-client:${CIRCLE_BRANCH}__${CIRCLE_BUILD_NUM} \
-t scalableminds/fossildb-client:${CIRCLE_BRANCH} \
.
- run:
name: Push to DockerHub
command: |
set -x
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push scalableminds/fossildb-client:${CIRCLE_BRANCH}__${CIRCLE_BUILD_NUM}
docker push scalableminds/fossildb-client:${CIRCLE_BRANCH}
docker logout
workflows:
version: 2
default:
jobs:
- build_and_deploy
- build_and_push_db
- build_and_push_client
5 changes: 5 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__
*.pyc

fossildbapi_pb2_grpc.py
fossildbapi_pb2.py
11 changes: 11 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.6-stretch

COPY src/main/protobuf /fossildb/src/main/protobuf
COPY client /fossildb/client

WORKDIR /fossildb/client

RUN pip3 install -r requirements.txt
RUN ./update_api.sh

ENTRYPOINT /fossildb/client/backup-client.py
51 changes: 51 additions & 0 deletions client/backup-client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3

import grpc
import sys
import argparse

import fossildbapi_pb2
import fossildbapi_pb2_grpc


def main():

commands = {'backup': backup, 'restore': restore}

parser = argparse.ArgumentParser()
parser.add_argument(
'address', metavar='address', default='localhost', nargs='?',
help='address of the fossildb server (default: %(default)s)')
parser.add_argument(
'port', metavar='port', type=int, default=8090, nargs='?',
help='port of the fossildb server (default: %(default)s)')
parser.add_argument(
'command', metavar='command',
help='command to execute, one of {}'.format(list(commands.keys())))

args = parser.parse_args()

full_address = '{}:{}'.format(args.address, args.port)

print('Requesting RestoreFromBackup to FossilDB at', full_address)

channel = grpc.insecure_channel(full_address)
stub = fossildbapi_pb2_grpc.FossilDBStub(channel)

reply = commands[args.command](stub)

print(reply)
if not reply.success:
sys.exit(1)


def restore(stub):
return stub.RestoreFromBackup(fossildbapi_pb2.RestoreFromBackupRequest())


def backup(stub):
return stub.Backup(fossildbapi_pb2.BackupRequest())


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
argparse
grpcio-tools
6 changes: 6 additions & 0 deletions client/update_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -Eeuo pipefail

SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

python3 -m grpc_tools.protoc -I$SCRIPTPATH/../src/main/protobuf --python_out=$SCRIPTPATH --grpc_python_out=$SCRIPTPATH $SCRIPTPATH/../src/main/protobuf/fossildbapi.proto

0 comments on commit 2e84bed

Please sign in to comment.