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
7 changes: 7 additions & 0 deletions .github/branch-protection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
required_status_checks:
strict: true

contexts:
- "Lint and Format Check"

require_branches_up_to_date: true
36 changes: 35 additions & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,42 @@ env:
REGISTRY_PASSWORD: ${{ github.token }}

jobs:
lint:
name: Lint and Format Check
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
success: ${{ steps.lint.outputs.success }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install ruff
run: pip install ruff

- name: Run linting
id: lint
run: |
echo "Running ruff check..."
ruff check . --output-format=github

echo "Running ruff format check..."
ruff format --check .

echo "success=true" >> $GITHUB_OUTPUT

build-and-push-image:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [lint]
if: needs.lint.outputs.success == 'true'
permissions:
contents: read
packages: write
Expand All @@ -43,7 +77,7 @@ jobs:
type=ref,event=tag
type=ref,event=pr
type=sha,format=long

- name: Build and push Docker image
uses: docker/build-push-action@91df6b874e498451163feb47610c87c4a218c1ee
with:
Expand Down
11 changes: 6 additions & 5 deletions KubernetesLogFormatter.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import json
import os
import logging
import os


def get_kubernetes_namespace():
namespace_file = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
try:
with open(namespace_file, "r") as f:
with open(namespace_file) as f:
namespace = f.read().strip()
return namespace
except FileNotFoundError:
return "Namespace file not found"
except Exception as e:
return f"Error reading namespace: {e}"


class KubernetesLogFormatter(logging.Formatter):
def format(self, record):
timestamp = self.formatTime(record, self.datefmt or "%Y-%m-%d %H:%M:%S")
level = record.levelname
message = record.getMessage()
pod_name = os.getenv('HOSTNAME', 'unknown-pod')
pod_name = os.getenv("HOSTNAME", "unknown-pod")
namespace = get_kubernetes_namespace()

return f"[{timestamp}] [{level}] [{namespace}/{pod_name}] {message}"
return f"[{timestamp}] [{level}] [{namespace}/{pod_name}] {message}"
23 changes: 17 additions & 6 deletions RunningJob.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from typing import List


class RunningJob:
def __init__(self, repo: str, job_id: int, slurm_job_id: int, workflow_name: str, job_name: str, labels: List[str]):
def __init__(
self,
repo: str,
job_id: int,
slurm_job_id: int,
workflow_name: str,
job_name: str,
labels: List[str],
):
"""Class to represent a running Github Actions Job on Slurm."""
self.repo = repo
self.job_id = job_id
Expand All @@ -11,9 +20,11 @@ def __init__(self, repo: str, job_id: int, slurm_job_id: int, workflow_name: str
self.labels = labels

def __str__(self) -> str:
return (f"RunningJob(job_id = {self.job_id}, slurm_job_id = {self.slurm_job_id}, "
f"workflow_name = {self.workflow_name}, "
f"job_name = {self.job_name}, labels = {self.labels})")

return (
f"RunningJob(job_id = {self.job_id}, slurm_job_id = {self.slurm_job_id}, "
f"workflow_name = {self.workflow_name}, "
f"job_name = {self.job_name}, labels = {self.labels})"
)

def __repr__(self) -> str:
return self.__str__()
return self.__str__()
12 changes: 6 additions & 6 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
GITHUB_API_BASE_URL = 'https://api.github.com/repos/WATonomous/infra-config'
GITHUB_REPO_URL = 'https://github.com/WATonomous/infra-config'
ALLOCATE_RUNNER_SCRIPT_PATH = "apptainer.sh" # relative path from '/allocation_script'
GITHUB_API_BASE_URL = "https://api.github.com/repos/WATonomous/infra-config"
GITHUB_REPO_URL = "https://github.com/WATonomous/infra-config"
ALLOCATE_RUNNER_SCRIPT_PATH = "apptainer.sh" # relative path from '/allocation_script'


REPOS_TO_MONITOR = [
{
'name': 'WATonomous/infra-config',
'api_base_url': 'https://api.github.com/repos/WATonomous/infra-config',
'repo_url': 'https://github.com/WATonomous/infra-config'
"name": "WATonomous/infra-config",
"api_base_url": "https://api.github.com/repos/WATonomous/infra-config",
"repo_url": "https://github.com/WATonomous/infra-config",
},
]
Loading