Skip to content

Commit

Permalink
Update swegram
Browse files Browse the repository at this point in the history
- Frontend
-- Remove logo

- Backend
-- Bugfix to resolve dict_items for texts with labels

- Update run.sh to provide options for re-deployment
- update docker-compose
  • Loading branch information
rexruan committed Aug 24, 2024
1 parent 1b91b99 commit 56788a8
Show file tree
Hide file tree
Showing 10 changed files with 387 additions and 39 deletions.
1 change: 1 addition & 0 deletions SWEGRAM_BACKEND
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.5
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ services:
- swegram-network
profiles:
- client
- frontend
- database

backend:
image: rex0046/swegram-backend:1.0.4 # Image needs to be built with network
image: rex0046/swegram-backend:$BACKEND_TAG # Image needs to be built with network
depends_on:
- db
container_name: swegram-backend-fastapi
Expand Down Expand Up @@ -57,6 +57,7 @@ services:
- swegram-network
profiles:
- client
- frontend

networks:
swegram-network:
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/HelpPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
height="110"
width="160"
>
<img
<!-- <img
src="../assets/UU_logo_sv_84_transparent.png"
height="125"
width="125"
>
> -->
</div>
</el-row>
<el-row>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
height="110"
width="160"
>
<img
<!-- <img
src="../assets/UU_logo_sv_84_transparent.png"
height="125"
width="125"
>
> -->
<!-- <p class="link-container">
<a href="..">
<el-button type="plain">{{ $t('homePage.legacyVersion') }}
Expand Down
84 changes: 72 additions & 12 deletions run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,18 +1,78 @@
#!/bin/bash -e

#clean up possible old containers
docker compose --profile client down
deploy_all=false
deploy_backend=false
deploy_frontend=false
deploy_database=false

BASE_PATH=$(pwd)
FRONTEND_PATH="$BASE_PATH/frontend"
print_usage() {
echo "Usage: $0 [-a] [-b] [-d] [-f] [-h]" >&2;
echo "options:
-a Deploy all containers
-b Deploy backend container
-d Deploy database container
-f Build and Deploy frontend container
-h this help message"
exit 1;
}

# create vue-builder image
cd $FRONTEND_PATH
docker build --network host -t vue-builder -f Dockerfile.build .
while getopts ":abdfh" OPTION; do
case "$OPTION" in
a) deploy_all=true;;
b) deploy_backend=true;;
d) deploy_database=true;;
f) deploy_frontend=true;;
h) print_usage;;
\?) echo "$0: Error: Invalid option: -${OPTARG}" >&2; exit 1;;
:) echo "$0: Error: option -${OPTARG} requires an argument" >&2; exit 1;;
esac
done
shift "$(($OPTIND -1))"

# run vue-builder image to create dist
docker run --rm -v $FRONTEND_PATH/dist:/root/dist vue-builder
echo "all: $deploy_all"
echo "backend: $deploy_backend"
echo "database: $deploy_database"
echo "frontend: $deploy_frontend"

if $deploy_all; then
echo "Re-deploy all containers"

#clean up possible old containers
docker compose --profile client down

BASE_PATH=$(pwd)
FRONTEND_PATH="$BASE_PATH/frontend"

# create vue-builder image
cd $FRONTEND_PATH
docker build --network host -t vue-builder -f Dockerfile.build .

# run vue-builder image to create dist
docker run --rm -v $FRONTEND_PATH/dist:/root/dist vue-builder

export BACKEND_TAG=$(cat $BASE_PATH/SWEGRAM_BACKEND)
# Start the containers with help of docker compose
# remove data (mysql container generates data folder)
docker compose --profile client up -d --build

else
if $deploy_backend; then
docker compose --profile backend down || true
export BACKEND_TAG=$(cat $(pwd)/SWEGRAM_BACKEND)
backend_image="rex0046/swegram-backend:$BACKEND_TAG"
echo "backend image: $backend_image"
# docker pull $backend_image
docker compose --profile backend up -d
fi

if $deploy_frontend; then
docker compose --profile frontend down || true
docker compose --profile frontned up -d --build
fi

if $deploy_database; then
docker compose --profile database down || true
docker compose --profile database up -d
fi
fi

# Start the containers with help of docker compose
# remove data (mysql container generates data folder)
docker compose --profile client up -d --build
24 changes: 10 additions & 14 deletions server/lib/fetch_current_sentences.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Fetch current sentences"""
from typing import Any, Dict

from fastapi import HTTPException
from fastapi.responses import JSONResponse
from sqlalchemy.orm import Session

Expand All @@ -12,17 +11,14 @@
def fetch_current_sentences(text_id: int, page: int, db: Session) -> Dict[str, Any]:
"""The default size to show the sentence for visualization is 20"""

try:
text = db.query(Text).get(ident=text_id)
sentences = db.query(Sentence) \
.filter(Sentence.uuid == text.uuid) \
.order_by(Sentence.id)[(int(page) - 1) * PAGE_SIZE: int(page) * PAGE_SIZE]
text = db.query(Text).get(ident=text_id)
sentences = db.query(Sentence) \
.filter(Sentence.uuid == text.uuid) \
.order_by(Sentence.id)[(int(page) - 1) * PAGE_SIZE: int(page) * PAGE_SIZE]

return JSONResponse({
"current_sentences": [{"tokens": sentence.serialize_tokens()} for sentence in sentences],
"metadata": text.labels.items() if text.labels else [],
"total_items": text.sents,
"page_size": PAGE_SIZE
})
except Exception as err:
raise HTTPException(status_code=500, detail=str(err)) from err
return JSONResponse({
"current_sentences": [{"tokens": sentence.serialize_tokens()} for sentence in sentences],
"metadata": [(key, value) for key, value in text.labels.items()] if text.labels else [],
"total_items": text.sents,
"page_size": PAGE_SIZE
})
File renamed without changes.
Loading

0 comments on commit 56788a8

Please sign in to comment.