Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
# production
/build
/dist
/backend/deploy

# python stuff
__pycache__/
venv/
*.egg-info


# misc
.DS_Store
.env.local
Expand Down
64 changes: 64 additions & 0 deletions backend/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Standard library imports
import os
import shutil
import zipfile
from typing import Dict, List, Tuple, Union

# Third-party imports
from flask import request
from flask_restful import Resource

# Our imports
from main import basedir

class DeployResource(Resource):
def post(self) -> Union[Dict[str, Union[str, int, List[str]]], Tuple[Dict[str, str], int]]:
"""Upload and extract a zip file to the deploy directory"""
if 'file' not in request.files:
return {'error': 'No file provided'}, 400

file = request.files['file']

if file.filename == '':
return {'error': 'No file selected'}, 400

if not file.filename.endswith('.zip'):
return {'error': 'Only zip files are allowed'}, 400

try:
# Create deploy directory if it doesn't exist
deploy_dir = os.path.join(basedir, 'deploy')

# Clear existing deploy directory
if os.path.exists(deploy_dir):
shutil.rmtree(deploy_dir)
os.makedirs(deploy_dir)

# Save the zip file temporarily
temp_zip_path = os.path.join(basedir, 'temp_deploy.zip')
file.save(temp_zip_path)

# Extract the zip file
with zipfile.ZipFile(temp_zip_path, 'r') as zip_ref:
zip_ref.extractall(deploy_dir)

# Remove the temporary zip file
os.remove(temp_zip_path)

# List extracted files
extracted_files = []
for root, dirs, files in os.walk(deploy_dir):
for filename in files:
rel_path = os.path.relpath(os.path.join(root, filename), deploy_dir)
extracted_files.append(rel_path)

return {
'message': 'Deployment successful',
'deploy_directory': deploy_dir,
'files_extracted': len(extracted_files),
'files': extracted_files[:20] # Show first 20 files
}
except zipfile.BadZipFile:
return {'error': 'Invalid zip file'}, 400
except Exception as e:
return {'error': f'Deployment failed: {str(e)}'}, 500
Loading