Last active
January 24, 2024 04:31
-
-
Save bhuiyanmobasshir94/3d3c9df907ac8432eeff539bd296bf6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
from fastapi import FastAPI | |
app = FastAPI() | |
def run_command_in_folder(folder_path, command): | |
# Get the current working directory | |
original_directory = os.getcwd() | |
try: | |
# Change the current working directory to the specified folder | |
os.chdir(folder_path) | |
# Run the command in the new directory | |
subprocess.run(command, shell=True, check=True) | |
except subprocess.CalledProcessError as e: | |
print(f"Error running command: {e}") | |
finally: | |
# Change back to the original directory | |
os.chdir(original_directory) | |
@app.post("/deploy") | |
async def root(): | |
run_command_in_folder('build_station/recsys-saas/', 'git pull origin shihab_wip_v4') | |
run_command_in_folder('build_station/recsys-saas/', 'git reset --hard origin/shihab_wip_v4') | |
run_command_in_folder('build_station/recsys-saas/', 'bash docker.sh') | |
run_command_in_folder('recsys-containers/saas', 'docker-compose down') | |
run_command_in_folder('recsys-containers/saas', 'docker-compose pull') | |
run_command_in_folder('recsys-containers/saas', 'docker-compose up -d') | |
return {"deployment_success": True} | |
# screen uvicorn build_automation:app --reload --host=0.0.0.0 --port=9999 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment