diff --git a/.github/workflows/publish_dockerhub.yml b/.github/workflows/publish_dockerhub.yml new file mode 100644 index 0000000..8805711 --- /dev/null +++ b/.github/workflows/publish_dockerhub.yml @@ -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 }} diff --git a/.github/workflows/ci.yml b/.github/workflows/publish_upm.yml similarity index 78% rename from .github/workflows/ci.yml rename to .github/workflows/publish_upm.yml index aaf50bd..deebaac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/publish_upm.yml @@ -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 @@ -18,4 +18,4 @@ jobs: cd unity_package npm publish env: - NODE_AUTH_TOKEN: ${{secrets.VERDACCIO_TOKEN}} \ No newline at end of file + NODE_AUTH_TOKEN: ${{secrets.VERDACCIO_TOKEN}} diff --git a/velconnect/db.py b/velconnect/db.py index 6356ea1..f5a0b01 100644 --- a/velconnect/db.py +++ b/velconnect/db.py @@ -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) diff --git a/velconnect/rebuild.bat b/velconnect/rebuild.bat new file mode 100644 index 0000000..307ff9d --- /dev/null +++ b/velconnect/rebuild.bat @@ -0,0 +1,4 @@ +docker build --tag velconnect . +docker rm web +docker run -p 8081:80 --name web velconnect + diff --git a/velconnect/rebuild.ps1 b/velconnect/rebuild.ps1 new file mode 100644 index 0000000..307ff9d --- /dev/null +++ b/velconnect/rebuild.ps1 @@ -0,0 +1,4 @@ +docker build --tag velconnect . +docker rm web +docker run -p 8081:80 --name web velconnect + diff --git a/velconnect/routes/api.py b/velconnect/routes/api.py index 25448aa..b23d48f 100644 --- a/velconnect/routes/api.py +++ b/velconnect/routes/api.py @@ -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}