Skip to content

Commit ca88ab4

Browse files
committed
Completed
1 parent d01676f commit ca88ab4

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/fabfile.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,35 @@ def deploy(ctx):
5353
raise Exit(f"Deployment failed: {str(e)}")
5454

5555
@task
56-
def rollback(ctx):
56+
def upload(ctx, filename, target_dir=None):
5757
"""
58-
Rollback to the previous version if something goes wrong
58+
Upload file to the server
59+
Usage: fab upload file1 [target_dir=path]
60+
Example: fab upload .env
61+
fab upload .env target_dir=configs
5962
"""
60-
conn = Connection(host=HOST, user=USER)
61-
with conn.cd(PROJECT_DIR):
62-
conn.run('git reset --hard HEAD^')
63-
with conn.prefix('source ../venv/bin/activate'):
64-
conn.run('python manage.py migrate')
65-
conn.sudo('systemctl restart gunicorn')
63+
conn = Connection(
64+
HOST,
65+
user=USER,
66+
connect_kwargs={
67+
"password": PASSWORD
68+
}
69+
)
70+
71+
try:
72+
# Default target directory if none specified
73+
if target_dir is None:
74+
target_dir = f'{PROJECT_DIR}/src'
75+
else:
76+
target_dir = f'{PROJECT_DIR}/{target_dir}'
77+
78+
with conn.cd(target_dir):
79+
print(f"Uploading {filename} to {target_dir}...")
80+
if os.path.exists(filename):
81+
conn.put(filename, target_dir)
82+
print(f"Successfully uploaded {filename}")
83+
else:
84+
print(f"Error: {filename} not found in local directory")
85+
86+
except Exception as e:
87+
print(f"Upload failed: {str(e)}")

0 commit comments

Comments
 (0)