From 6e44399ae500bfcba55099e7f03e3d5743665e71 Mon Sep 17 00:00:00 2001 From: Laura Boenchen Date: Thu, 26 Jun 2025 10:53:21 +0200 Subject: [PATCH] Add heroku setup and action --- .github/workflows/model-training.yml | 3 ++ .github/workflows/production-deployment.yml | 52 +++++++++++++++++++++ Procfile | 1 + 3 files changed, 56 insertions(+) create mode 100644 .github/workflows/production-deployment.yml create mode 100644 Procfile diff --git a/.github/workflows/model-training.yml b/.github/workflows/model-training.yml index 8d1c746..ea28591 100644 --- a/.github/workflows/model-training.yml +++ b/.github/workflows/model-training.yml @@ -6,13 +6,16 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v3 + - name: Setup Python und install requirements uses: actions/setup-python@v4 with: python-version: "3.8" - run: pip install -r requirements.txt + - name: Train model run: python src/train.py + - name: Upload trained model uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/production-deployment.yml b/.github/workflows/production-deployment.yml new file mode 100644 index 0000000..22cca2b --- /dev/null +++ b/.github/workflows/production-deployment.yml @@ -0,0 +1,52 @@ +name: Deploy to Production +on: + push: + branches: + - main + +jobs: + train-model: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Switch to heroku branch + shell: bash + run: | + git config --global user.email "" + git config --global user.name "Github Actions" + git fetch --all --unshallow + git checkout heroku 2>/dev/null || git checkout -b heroku + git merge main -X theirs --allow-unrelated-histories + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.9" + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Train model + run: python src/train.py + + - name: Upload trained model + uses: actions/upload-artifact@v4 + with: + name: regressor_mpg.pickle + path: data/models/regressor_mpg.pickle + + - name: Push changes to heroku branch + shell: bash + run: | + git add . + git add --force data/models/regressor_mpg.pickle + git commit -m "[CI] update trained model" || echo "No changes to commit" + git push --set-upstream origin heroku + + - name: Deploy to Heroku + uses: akhileshns/heroku-deploy@v3.13.15 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: ${{secrets.HEROKU_APP_NAME}} + heroku_email: ${{secrets.HEROKU_EMAIL}} + branch: "heroku" diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..a9d6344 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn src.api:app