fix db creation not working, publish docker img action

dev
Anton Franzluebbers 2023-05-20 19:26:08 -04:00
parent adb13c9305
commit f669b899ce
6 changed files with 70 additions and 24 deletions

34
.github/workflows/publish_dockerhub.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Publish Docker image
on:
push:
branches: ["main"]
paths: ["velconnect/**"]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: velaboratory/velconnect
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./velconnect
file: ./velconnect/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@ -1,8 +1,8 @@
name: Publish to Verdaccio
on:
push:
branches:
- master
branches: ["main"]
paths: ["unity_package/**"]
jobs:
publish-npm:
name: publish to npm.ugavel.com

View File

@ -9,7 +9,7 @@ class DB:
def create_or_connect(self):
create = False
if not os.path.exists(self.db_name, ):
if not os.path.exists(self.db_name):
create = True
conn = sqlite3.connect(self.db_name)

4
velconnect/rebuild.bat Normal file
View File

@ -0,0 +1,4 @@
docker build --tag velconnect .
docker rm web
docker run -p 8081:80 --name web velconnect

4
velconnect/rebuild.ps1 Normal file
View File

@ -0,0 +1,4 @@
docker build --tag velconnect .
docker rm web
docker run -p 8081:80 --name web velconnect

View File

@ -92,7 +92,8 @@ def get_device_by_pairing_code(pairing_code: str):
def get_device_by_pairing_code_dict(pairing_code: str) -> dict | None:
values = db.query("SELECT * FROM `Device` WHERE `pairing_code`=:pairing_code;", {'pairing_code': pairing_code})
values = db.query(
"SELECT * FROM `Device` WHERE `pairing_code`=:pairing_code;", {'pairing_code': pairing_code})
if len(values) == 1:
device = dict(values[0])
parse_data(device)
@ -101,7 +102,8 @@ def get_device_by_pairing_code_dict(pairing_code: str) -> dict | None:
def get_user_for_device(hw_id: str) -> dict:
values = db.query("""SELECT * FROM `UserDevice` WHERE `hw_id`=:hw_id;""", {'hw_id': hw_id})
values = db.query(
"""SELECT * FROM `UserDevice` WHERE `hw_id`=:hw_id;""", {'hw_id': hw_id})
if len(values) == 1:
user_id = dict(values[0])['user_id']
user = get_user_dict(user_id=user_id)
@ -149,7 +151,7 @@ def get_device_data(request: Request, response: Response, hw_id: str):
room_data = get_data(response, key=room_key, user_id=user['id'])
if "error" in room_data:
response.status_code = None # this really isn't an error, so we reset the status code
response.status_code = None # this really isn't an error, so we reset the status code
set_data(request, data={}, key=room_key,
modified_by=None, category="room")
room_data = get_data(response, key=room_key, user_id=user['id'])
@ -264,21 +266,21 @@ def set_data(request: fastapi.Request, data: dict, key: str = None, owner: str =
old_data: dict = json.loads(old_data_query[0]["data"])
data = {**old_data, **data}
# add the data to the db
db.insert("""
REPLACE INTO `DataBlock` (id, owner_id, category, modified_by, data, last_modified)
VALUES(:id, :owner_id, :category, :modified_by, :data, CURRENT_TIMESTAMP);
""", {"id": key, "owner_id": owner, "category": category, "modified_by": modified_by, "data": json.dumps(data)})
# # add the data to the db
# db.insert("""
# REPLACE INTO `DataBlock` SET
# category = :category,
# modified_by = :modified_by,
# data = :data,
# last_modified = CURRENT_TIMESTAMP
# WHERE id=:id AND owner_id = :owner_id;
# """, {"id": key, "category": category, "modified_by": modified_by, "owner_id": owner, "data": json.dumps(data)})
# add the data to the db
db.insert("""
UPDATE `DataBlock` SET
category = :category,
modified_by = :modified_by,
data = :data,
last_modified = CURRENT_TIMESTAMP
WHERE id=:id AND owner_id = :owner_id;
""", {"id": key, "category": category, "modified_by": modified_by, "owner_id": owner, "data": json.dumps(data)})
else:
# add the data to the db
db.insert("""
INSERT INTO `DataBlock` (id, owner_id, category, modified_by, data, last_modified)
VALUES(:id, :owner_id, :category, :modified_by, :data, CURRENT_TIMESTAMP);
""", {"id": key, "owner_id": owner, "category": category, "modified_by": modified_by, "data": json.dumps(data)})
return {'key': key}
@ -349,7 +351,8 @@ def get_user(response: Response, user_id: str):
def get_user_dict(user_id: str) -> dict | None:
values = db.query("SELECT * FROM `User` WHERE `id`=:user_id;", {'user_id': user_id})
values = db.query(
"SELECT * FROM `User` WHERE `id`=:user_id;", {'user_id': user_id})
if len(values) == 1:
user = dict(values[0])
parse_data(user)
@ -379,7 +382,8 @@ async def upload_file(request: fastapi.Request, file: UploadFile, key: str | Non
content = await file.read() # async read
await out_file.write(content) # async write
# add a datablock to link to the file
set_data(request, data={'filename': file.filename}, key=key, category='file', modified_by=modified_by)
set_data(request, data={'filename': file.filename},
key=key, category='file', modified_by=modified_by)
return {"filename": file.filename, 'key': key}