Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .funcignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2025 The Regents of the University of California
# SPDX-License-Identifier: BSD-3-Clause

.git*
.vscode
__azurite_db*__.json
Expand All @@ -7,4 +10,4 @@ local.settings.json
test
.venv
.env
update_filter_view.py
update_filter_view.py
76 changes: 76 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
# Copyright (c) 2025 The Regents of the University of California
# SPDX-License-Identifier: BSD-3-Clause

name: CI Tests for Pull Requests

on:
pull_request:
types: [opened, synchronize, ready_for_review]

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Run pre-commit hooks
uses: pre-commit/[email protected]


unit-tests:
runs-on: ubuntu-24.04

if: github.event.pull_request.draft == false
needs: pre-commit
env:
FUNCTIONS_WORKER_RUNTIME: python
MONGO_CONNECTION_STRING: ${{ secrets.MONGO_CONNECTION_STRING }}
AzureWebJobsStorage: UseDevelopmentStorage=true
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ];
then
pip install -r requirements.txt
fi

- name: Install Azure Functions Core Tools
run: |
npm install -g azure-functions-core-tools@4 --unsafe-perm true

- name: Start Azure Functions
run: |
# Start Azure Functions in the background
func start --port 7071 --no-build > func.log 2>&1 &
echo $! > func.pid
# Wait for the functions to be ready (adjust time as needed)
sleep 20

- name: Run tests
run: |
python3 -m unittest tests.resources_api_unit_tests -v
- name: Cleanup Azure Functions
if: always()
run: |
kill $(cat func.pid) || true
69 changes: 40 additions & 29 deletions .github/workflows/deploy-azure.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
---
# Copyright (c) 2025 The Regents of the University of California
# SPDX-License-Identifier: BSD-3-Clause

name: Deploy Python project to Azure Function App

on:
workflow_dispatch: # allows manual triggering of the workflow

# on:
# push:
# branches:
# - main # only run on pushes to main

env:
AZURE_FUNCTIONAPP_NAME: 'gem5-resources-api'
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # function API code lives in the repo root
PYTHON_VERSION: '3.12'
AZURE_FUNCTIONAPP_NAME: gem5-resources-api

# function API code lives in the repo root
AZURE_FUNCTIONAPP_PACKAGE_PATH: .
PYTHON_VERSION: '3.12'

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies into .python_packages
run: |
pushd ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
python -m pip install --upgrade pip
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd

- name: Deploy to Azure Functions
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
scm-do-build-during-deployment: true
enable-oryx-build: true
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies into .python_packages
run: |
pushd ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
python -m pip install --upgrade pip
pip install -r requirements.txt \
--target=".python_packages/lib/site-packages"
popd

- name: Deploy to Azure Functions
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: |
${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
scm-do-build-during-deployment: true
enable-oryx-build: true
41 changes: 0 additions & 41 deletions .github/workflows/pr-unittest.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2025 The Regents of the University of California
# SPDX-License-Identifier: BSD-3-Clause

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -132,4 +135,4 @@ local.settings.json
__blobstorage__
__queuestorage__
__azurite_db*__.json
.python_packages
.python_packages
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# Copyright (c) 2025 The Regents of the University of California
# SPDX-License-Identifier: BSD-3-Clause

minimum_pre_commit_version: '2.18'

default_language_version:
python: python3

default_stages: [pre-commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-yaml
- id: check-added-large-files
- id: mixed-line-ending
args: [--fix=lf]
- id: check-ast
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: destroyed-symlinks
- id: requirements-txt-fixer
- repo: https://github.com/PyCQA/isort
rev: 6.0.1
hooks:
- id: isort
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
- id: yamlfmt
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
# Python 3.10 is the earliest version supported.
# We therefore conform to the standards compatible with 3.10+.
args: [--py310-plus]
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ gem5-resources-api/
Start the Azure Function locally. By default, the development server starts at `http://localhost:7071`. Use func start `--port <port>` to run on a different port:

```bash
func start
func start
```

Expected output:

```bash
Functions:
get_resources_by_batch: [GET] http://localhost:7071/api/resources/find-resources-in-batch
get_resources_by_batch: [GET] http://localhost:7071/api/resources/find-resources-in-batch
search_resources: [GET] http://localhost:7071/api/resources/search
get_filters: [GET] http://localhost:7071/api/resources/filters
get_dependent_workloads: [GET] http://localhost:7071/api/resources/get-dependent-workloads
Expand Down Expand Up @@ -322,7 +322,7 @@ This repository has github actions set up that will re deploy the functions once
Each new endpoint file must be manually imported and registered in function_app.py using the pattern shown below.

1. **Create Function Module**:

```python
# functions/new_endpoint.py
def register_function(app, collection):
Expand Down
13 changes: 7 additions & 6 deletions function_app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2025 The Regents of the University of California
# SPDX-License-Identifier: BSD-3-Clause


import azure.functions as func
import logging
from shared.database import initialize_database

from functions import (
get_dependent_workloads,
get_filters,
get_resources_by_batch,
search_resources,
get_filters,
get_dependent_workloads
)
from shared.database import initialize_database

# Initialize the function app
app = func.FunctionApp()
Expand All @@ -21,4 +22,4 @@
get_resources_by_batch.register_function(app, collection)
search_resources.register_function(app, collection)
get_filters.register_function(app, collection, db["filter_values"])
get_dependent_workloads.register_function(app, collection)
get_dependent_workloads.register_function(app, collection)
23 changes: 14 additions & 9 deletions functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Copyright (c) 2025 The Regents of the University of California
# SPDX-License-Identifier: BSD-3-Clause

# Make this directory a package
from . import get_resources_by_batch
from . import search_resources
from . import get_filters
from . import get_dependent_workloads
from . import (
get_dependent_workloads,
get_filters,
get_resources_by_batch,
search_resources,
)

__all__ = [
'get_resources_by_batch',
'search_resources',
'get_filters',
'get_dependent_workloads'
]
"get_resources_by_batch",
"search_resources",
"get_filters",
"get_dependent_workloads",
]
Loading