Skip to content

Instantly share code, notes, and snippets.

@bhuiyanmobasshir94
Last active January 24, 2024 04:31
Show Gist options
  • Save bhuiyanmobasshir94/3d3c9df907ac8432eeff539bd296bf6b to your computer and use it in GitHub Desktop.
Save bhuiyanmobasshir94/3d3c9df907ac8432eeff539bd296bf6b to your computer and use it in GitHub Desktop.
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