Skip to content

Commit f13d2b2

Browse files
committed
feat: Add CI/CD pipeline, testing framework, Slurm environment setup, and documentation
This commit introduces several new features and improvements: - Added a CI/CD pipeline using GitHub Actions to build and push Docker images to Docker Hub. - Implemented a testing framework using pytest with coverage reporting and integrated it with Codecov. - Added documentation for setting up a Slurm environment for worker management. - Created a shell script for setting up the Slurm environment. - Added a test case for the Processes API view. - Updated the README with instructions for setting up the Slurm environment. - Added pytest and related packages to the requirements.txt file. - Configured Django REST Framework for testing.
1 parent 1cf7deb commit f13d2b2

10 files changed

Lines changed: 172 additions & 6 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- 'main'
12+
13+
jobs:
14+
15+
build_backend:
16+
name: Build and Push Backend
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check out the repo
20+
uses: actions/checkout@v3
21+
22+
- name: Extract metadata (tags, labels) for Docker
23+
id: meta
24+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
25+
with:
26+
images: linea/orchestration
27+
tags: |
28+
type=raw,enable=${{ startsWith(github.ref, 'refs/tags/v') }},priority=100,prefix=backend_,value=latest
29+
type=semver,enable=true,priority=200,prefix=backend_v,suffix=,pattern={{version}}
30+
type=sha,enable=true,priority=300,prefix=backend_,suffix=,format=short
31+
type=raw,priority=400,prefix=backend_dev_,value=latest
32+
flavor: |
33+
latest=false
34+
35+
- name: Log in to Docker Hub
36+
if: github.event_name != 'pull_request'
37+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
38+
with:
39+
username: ${{ secrets.DOCKER_USERNAME }}
40+
password: ${{ secrets.DOCKER_PASSWORD }}
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v1
44+
45+
- name: Build and push Docker image
46+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
47+
with:
48+
context: ./backend
49+
push: ${{ github.event_name != 'pull_request' }}
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
# build-args: |
53+
# USERNAME=${{ secrets.PZ_USERNAME }}
54+
# USERID=${{ secrets.PZ_USERID }}
55+
# GROUPID=${{ secrets.PZ_GROUPID }}

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test API workflow
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
name: Test python API
9+
steps:
10+
- uses: actions/checkout@v3
11+
- name: Set up uWSGI dependencies
12+
uses: awalsh128/cache-apt-pkgs-action@latest
13+
with:
14+
packages: gcc python3-dev build-essential libpcre3 libpcre3-dev
15+
version: 1.0
16+
- name: Set up Python 3.10
17+
uses: actions/setup-python@v4
18+
with:
19+
# Semantic version range syntax or exact version of a Python version
20+
python-version: '3.10'
21+
# Optional - x64 or x86 architecture, defaults to x64
22+
architecture: 'x64'
23+
# You can test your matrix by printing the current Python version
24+
- name: Display Python version
25+
run: python -c "import sys; print(sys.version)"
26+
- name: Install requirements
27+
working-directory: ./backend
28+
run: |
29+
python -m pip install --upgrade pip wheel
30+
pip install -r requirements.txt
31+
- name: Run tests and collect coverage
32+
working-directory: ./backend
33+
run: pytest --cov=./ --cov-report=xml
34+
- name: Upload coverage reports to Codecov with GitHub Action
35+
uses: codecov/codecov-action@v3
36+
with:
37+
token: ${{ secrets.CODECOV_TOKEN }}
38+

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Orchestration tool for the Brazilian IDAC applications.
44

5-
## Setup Develop Enviroment
5+
## Setup Enviroment
66

77
Clone the repository and access the directory:
88

@@ -71,7 +71,6 @@ $ docker-compose run backend python -c "import secrets; print(secrets.token_urls
7171
Copy the generated key, replace the `SECRET_KEY` variable value in the `.env` file and uncomment it by removing the "#".
7272

7373

74-
7574
Create the Django superuser.
7675

7776
Enter in container:
@@ -117,7 +116,7 @@ Point your browser to <http://localhost/admin/oauth2_provider/application/add/>
117116
- `Algorithm`: keep the default option (No OIDC support)
118117

119118

120-
WARNING!!!
119+
WARNING!!!
121120
Fill the form as show in the screenshot below, and before saving take note of **Client id** and **Client secret** we will use it in a minute.
122121

123122

@@ -259,3 +258,33 @@ docker-compose exec backend bash
259258
# with the service turned off
260259
docker-compose run backend bash
261260
```
261+
262+
## Setup Slurm Enviroment
263+
264+
### What is it?
265+
266+
Internal application that interacts with the Slurm cluster and must be installed on a submission node. The application is a consumer of rabbitmq, and with each pipeline submission, a Slurm submission file is created and the process is finally submitted.
267+
268+
*note: This installation requires an orchestration running on the same submission node.*
269+
270+
Clone the repository and create a directory that will serve as the base for the application:
271+
```bash
272+
git clone https://github.com/linea-it/orchestration.git
273+
mkdir slurm-worker
274+
```
275+
276+
Copy the `slurm_env.sh` file and edit the environment variables as needed:
277+
```bash
278+
cp orchestration/backend/sh/slurm_env.sh slurm-worker/env.sh
279+
vi slurm-worker/env.sh # edit file
280+
```
281+
282+
With Conda loaded, run:
283+
```bash
284+
source slurm-worker/env.sh
285+
```
286+
287+
And start the application:
288+
```bash
289+
slurm_worker_manager start
290+
```

backend/core/tests.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

backend/core/tests/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from rest_framework.test import APITestCase
2+
3+
4+
class ProcessesAPIViewTestCase(APITestCase):
5+
6+
def test_list_product(self):
7+
self.assertEqual(1, 1)

backend/orchestration/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"rest_framework.filters.OrderingFilter",
9494
],
9595
"PAGE_SIZE": 10,
96+
"TEST_REQUEST_DEFAULT_FORMAT": "json",
9697
}
9798

9899
MIDDLEWARE = [

backend/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ psycopg2-binary==2.9.9
1515
pydantic==2.9.2
1616
pydantic_core==2.23.4
1717
python-crontab==3.2.0
18+
pytest==8.3.3
19+
pytest-cov==5.0.0
20+
pytest-django==4.9.0
1821
PyYAML==6.0.2
1922
requests==2.32.3

backend/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool:pytest]
2+
DJANGO_SETTINGS_MODULE = orchestration.settings

backend/sh/slurm_env.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash --login
2+
3+
export APP_DIR= # e.g.: /data/apps/app.orch/dev
4+
export BASE_DIR= # e.g.: ${APP_DIR}/orchestration
5+
export CONDA_PATH= # e.g.: ${APP_DIR}/miniconda3/bin/activate
6+
export RABBITMQ_ENV= # e.g.: /home/app.orch/rabbitmq/.env
7+
8+
set -a
9+
. $RABBITMQ_ENV # environment variables related to rabbitmq running on srvorch-dev server
10+
. $BASE_DIR/.env
11+
set +a
12+
13+
echo "Activating environment"
14+
15+
source $CONDA_PATH || { echo "Failed to activate Conda environment"; exit 1; }
16+
17+
if [ ! -d "$PIPELINES_DIR" ]; then
18+
echo "Error: PIPELINES_DIR not defined."
19+
exit 1
20+
fi
21+
22+
HASENV=`conda env list | grep 'orchestration '`
23+
24+
if [ -z "$HASENV" ]; then
25+
echo "Create virtual environment..."
26+
conda env create -f $BASE_DIR/backend/environment.yml
27+
echo "Virtual environment created and packages installed."
28+
fi
29+
30+
conda activate orchestration
31+
32+
export PATH=$PATH:$BASE_DIR/backend/sh/
33+
34+
umask g+w

0 commit comments

Comments
 (0)