Skip to content

Commit 8904f79

Browse files
committed
Remove Dockerfile and convert to Azure Function App
--- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/tblanarik/spotbot?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 22093de commit 8904f79

File tree

4 files changed

+89
-115
lines changed

4 files changed

+89
-115
lines changed
+75-75
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
2-
# More GitHub Actions for Azure: https://github.com/Azure/actions
3-
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions
4-
5-
name: Build and deploy Python project to Azure Function App - hamalertspotbot
6-
7-
on:
8-
push:
9-
branches:
10-
- main
11-
workflow_dispatch:
12-
13-
env:
14-
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
15-
PYTHON_VERSION: '3.11' # set this to the python version to use (supports 3.6, 3.7, 3.8)
16-
17-
jobs:
18-
build:
19-
runs-on: ubuntu-latest
20-
steps:
21-
- name: Checkout repository
22-
uses: actions/checkout@v4
23-
24-
- name: Setup Python version
25-
uses: actions/setup-python@v1
26-
with:
27-
python-version: ${{ env.PYTHON_VERSION }}
28-
29-
- name: Create and start virtual environment
30-
run: |
31-
python -m venv venv
32-
source venv/bin/activate
33-
34-
- name: Install dependencies
35-
run: pip install -r requirements.txt
36-
37-
# Optional: Add step to run tests here
38-
39-
- name: Zip artifact for deployment
40-
run: zip release.zip ./* -r
41-
42-
- name: Upload artifact for deployment job
43-
uses: actions/upload-artifact@v3
44-
with:
45-
name: python-app
46-
path: |
47-
release.zip
48-
!venv/
49-
50-
deploy:
51-
runs-on: ubuntu-latest
52-
needs: build
53-
environment:
54-
name: 'Production'
55-
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
56-
57-
steps:
58-
- name: Download artifact from build job
59-
uses: actions/download-artifact@v3
60-
with:
61-
name: python-app
62-
63-
- name: Unzip artifact for deployment
64-
run: unzip release.zip
65-
66-
- name: 'Deploy to Azure Functions'
67-
uses: Azure/functions-action@v1
68-
id: deploy-to-function
69-
with:
70-
app-name: 'hamalertspotbot'
71-
slot-name: 'Production'
72-
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
73-
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2A375008FC1743E4AE2D6A345036BDC4 }}
74-
scm-do-build-during-deployment: true
75-
enable-oryx-build: true
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions
4+
5+
name: Build and deploy Python project to Azure Function App - hamalertspotbot
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
env:
14+
AZURE_FUNCTIONAPP_PACKAGE_PATH: './' # set this to the path to your web app project, defaults to the repository root
15+
PYTHON_VERSION: '3.11' # set this to the python version to use (supports 3.6, 3.7, 3.8)
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Python version
25+
uses: actions/setup-python@v1
26+
with:
27+
python-version: ${{ env.PYTHON_VERSION }}
28+
29+
- name: Create and start virtual environment
30+
run: |
31+
python -m venv venv
32+
source venv/bin/activate
33+
34+
- name: Install dependencies
35+
run: pip install -r requirements.txt
36+
37+
# Optional: Add step to run tests here
38+
39+
- name: Zip artifact for deployment
40+
run: zip release.zip ./* -r
41+
42+
- name: Upload artifact for deployment job
43+
uses: actions/upload-artifact@v3
44+
with:
45+
name: python-app
46+
path: |
47+
release.zip
48+
!venv/
49+
50+
deploy:
51+
runs-on: ubuntu-latest
52+
needs: build
53+
environment:
54+
name: 'Production'
55+
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
56+
57+
steps:
58+
- name: Download artifact from build job
59+
uses: actions/download-artifact@v3
60+
with:
61+
name: python-app
62+
63+
- name: Unzip artifact for deployment
64+
run: unzip release.zip
65+
66+
- name: 'Deploy to Azure Functions'
67+
uses: Azure/functions-action@v1
68+
id: deploy-to-function
69+
with:
70+
app-name: 'hamalertspotbot'
71+
slot-name: 'Production'
72+
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
73+
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2A375008FC1743E4AE2D6A345036BDC4 }}
74+
scm-do-build-during-deployment: true
75+
enable-oryx-build: true

Dockerfile

-17
This file was deleted.

README.md

+8-11
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,15 @@ curl -X POST http://localhost:5000/forward -H "Content-Type: application/json" -
4242

4343
Replace `{"key": "value"}` with the actual JSON content you want to send.
4444

45-
## Running the Webserver using Docker
45+
## Deploying and Running the App as an Azure Function App
4646

47-
To run the webserver using Docker, follow these steps:
47+
To deploy and run the app as an Azure Function App, follow these steps:
4848

49-
1. Build the Docker image:
50-
```sh
51-
docker build -t spotbot .
52-
```
49+
1. Create an Azure Function App in the Azure portal.
5350

54-
2. Run the Docker container:
55-
```sh
56-
docker run -p 5000:5000 -e TARGET_URL=<target_url> -e DESTINATION_URL=<destination_url> spotbot
57-
```
51+
2. Set up the required environment variables in the Azure Function App configuration:
52+
- `TARGET_URL`: The target URL to which the content will be forwarded.
5853

59-
Replace `<target_url>` with the actual target URL and `<destination_url>` with the desired port number for the Flask app. If `DESTINATION_URL` is not set, the default port will be 5000.
54+
3. Deploy the app to the Azure Function App using the provided GitHub Actions workflow.
55+
56+
4. Once deployed, you can send POST requests to the Azure Function App endpoint to forward the content to the target URL.

spotbot.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
from flask import Flask, request
1+
import azure.functions as func
22
import requests
33
import os
44

5-
app = Flask(__name__)
6-
7-
@app.route('/forward', methods=['POST'])
8-
def forward():
9-
content = request.get_json()
10-
target_url = os.getenv('TARGET_URL') # Replace with the actual target URL
5+
def main(req: func.HttpRequest) -> func.HttpResponse:
6+
content = req.get_json()
7+
target_url = os.getenv('TARGET_URL')
118
if not target_url:
12-
return "Error: TARGET_URL environment variable is not set.", 500
9+
return func.HttpResponse("Error: TARGET_URL environment variable is not set.", status_code=500)
1310
response = requests.post(target_url, json=content)
14-
return response.text, response.status_code
15-
16-
if __name__ == '__main__':
17-
app.run(port=os.getenv('DESTINATION_URL', 5000))
11+
return func.HttpResponse(response.text, status_code=response.status_code)

0 commit comments

Comments
 (0)