File size: 1,384 Bytes
65d3b67 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import os
import zipfile
import requests
import dotenv
# Load environment variables
dotenv.load_dotenv()
def zip_folder(source_dir, zip_path):
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(source_dir):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.relpath(file_path, start=source_dir)
zipf.write(file_path, arcname)
def upload_zip(zip_path, app_name, server_url):
with open(zip_path, 'rb') as f:
files = {'file': (os.path.basename(zip_path), f, 'application/zip')}
data = {'app_name': app_name}
response = requests.post(f'{server_url}/deploy/project', files=files, data=data)
if response.status_code == 200:
print("β
Deployed Successfully!")
print(response.json())
else:
print("β Deployment Failed:")
print(response.text)
if __name__ == "__main__":
# Configuration
folder_to_zip = "examples/test" # Folder with main.py and requirements.txt
zip_output = "project.zip"
app_name = "maouapp"
server_url = 'http://192.168.29.195:8000' # Replace with your server URL
print("π¦ Zipping project...")
zip_folder(folder_to_zip, zip_output)
print("π€ Uploading...")
upload_zip(zip_output, app_name, server_url) |