Skip to content

Commit a39ed6c

Browse files
committed
Merge branch 'main' of https://github.com/jupyter-naas/abi
2 parents 68388b6 + 45b63fc commit a39ed6c

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ storage-push: .venv storage-pull
4444
@ echo "Pushing storage..."
4545
@ docker compose run --rm --remove-orphans abi bash -c 'poetry run python scripts/storage_push.py | sh'
4646

47+
triplestore-prod-remove: .venv
48+
@ echo "Removing production triplestore..."
49+
@ docker compose run --rm -it --remove-orphans abi bash -c 'poetry run python scripts/triplestore_prod_remove.py'
50+
51+
triplestore-prod-override: .venv
52+
@ echo "Overriding production triplestore..."
53+
@ docker compose run -it --rm --remove-orphans abi bash -c 'poetry run python scripts/triplestore_prod_override.py'
54+
55+
triplestore-prod-pull: .venv
56+
@ echo "Pulling production triplestore..."
57+
@ docker compose run --rm --remove-orphans abi bash -c 'poetry run python scripts/triplestore_prod_pull.py'
58+
4759
clean:
4860
@echo "Cleaning up build artifacts..."
4961
rm -rf __pycache__ .pytest_cache build dist *.egg-info lib/.venv .venv

scripts/triplestore_prod_override.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from common import get_config, get_storage_credentials
2+
import os
3+
from datetime import datetime
4+
5+
if __name__ == "__main__":
6+
7+
# Ask user to validate storage? (y/n): " confirm
8+
confirm = input("Are you sure you want to override the storage? (y/n): ")
9+
if confirm != "y":
10+
print("Storage override cancelled.")
11+
exit()
12+
13+
naas_api_key, workspace_id, storage_name = get_config()
14+
bucket, access_key_id, secret_access_key, session_token = get_storage_credentials(naas_api_key, workspace_id, storage_name)
15+
16+
# Backup the prod before overriding
17+
backup_timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
18+
os.system(f'AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_access_key} AWS_SESSION_TOKEN={session_token} aws s3 mv --recursive {bucket}/ontologies {bucket}/ontologies-backups/{backup_timestamp}')
19+
20+
# os.system(f'AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_access_key} AWS_SESSION_TOKEN={session_token} aws s3 cp --recursive {bucket}/storage/triplestore {bucket}/ontologies')
21+
os.system(f'AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_access_key} AWS_SESSION_TOKEN={session_token} aws s3 sync --follow-symlinks --delete storage/triplestore {bucket}/ontologies')

scripts/triplestore_prod_pull.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from common import get_config, get_storage_credentials
2+
import os
3+
from datetime import datetime
4+
if __name__ == "__main__":
5+
6+
naas_api_key, workspace_id, storage_name = get_config()
7+
bucket, access_key_id, secret_access_key, session_token = get_storage_credentials(naas_api_key, workspace_id, storage_name)
8+
9+
os.system(f'AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_access_key} AWS_SESSION_TOKEN={session_token} aws s3 sync --follow-symlinks --delete {bucket}/ontologies storage/triplestore')

scripts/triplestore_prod_remove.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from common import get_config, get_storage_credentials
2+
import os
3+
from datetime import datetime
4+
if __name__ == "__main__":
5+
6+
confirm = input("Are you sure you want to remove the storage? (y/n): ")
7+
if confirm != "y":
8+
print("Storage removal cancelled.")
9+
exit()
10+
11+
naas_api_key, workspace_id, storage_name = get_config()
12+
bucket, access_key_id, secret_access_key, session_token = get_storage_credentials(naas_api_key, workspace_id, storage_name)
13+
14+
backup_timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
15+
os.system(f'AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_access_key} AWS_SESSION_TOKEN={session_token} aws s3 mv --recursive {bucket}/ontologies {bucket}/ontologies-backups/{backup_timestamp}')
16+
17+
os.system(f'AWS_ACCESS_KEY_ID={access_key_id} AWS_SECRET_ACCESS_KEY={secret_access_key} AWS_SESSION_TOKEN={session_token} aws s3 rm --recursive {bucket}/ontologies')

0 commit comments

Comments
 (0)