Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for pydantic 2 #52

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
109 changes: 55 additions & 54 deletions murdock/config.py
Original file line number Diff line number Diff line change
@@ -1,102 +1,103 @@
import os
import tempfile

from typing import List, Optional
from pydantic import BaseSettings, Field, validator
from typing import List, Optional, Dict
from pydantic import Field, validator
from pydantic_settings import BaseSettings


class DatabaseSettings(BaseSettings):
type: str = Field(env="MURDOCK_DB_TYPE", default="mongodb")
host: str = Field(env="MURDOCK_DB_HOST", default="localhost")
port: int = Field(env="MURDOCK_DB_PORT", default=0)
name: str = Field(env="MURDOCK_DB_NAME", default="murdock")
user: str = Field(env="MURDOCK_DB_AUTH_USER", default="murdock")
password: str = Field(env="MURDOCK_DB_AUTH_PASSWORD", default="hunter2")
type: str = Field(alias="MURDOCK_DB_TYPE", default="mongodb")
host: str = Field(alias="MURDOCK_DB_HOST", default="localhost")
port: int = Field(alias="MURDOCK_DB_PORT", default=0)
name: str = Field(alias="MURDOCK_DB_NAME", default="murdock")
user: str = Field(alias="MURDOCK_DB_AUTH_USER", default="murdock")
password: str = Field(alias="MURDOCK_DB_AUTH_PASSWORD", default="hunter2")


class GithubSettings(BaseSettings):
app_client_id: str = Field(env="MURDOCK_GITHUB_APP_CLIENT_ID")
app_client_secret: str = Field(env="MURDOCK_GITHUB_APP_CLIENT_SECRET")
repo: str = Field(env="GITHUB_REPO")
webhook_secret: str = Field(env="GITHUB_WEBHOOK_SECRET")
api_token: str = Field(env="GITHUB_API_TOKEN")
app_client_id: str = Field(alias="MURDOCK_GITHUB_APP_CLIENT_ID")
app_client_secret: str = Field(alias="MURDOCK_GITHUB_APP_CLIENT_SECRET")
repo: str = Field(alias="GITHUB_REPO")
webhook_secret: str = Field(alias="GITHUB_WEBHOOK_SECRET")
api_token: str = Field(alias="GITHUB_API_TOKEN")


class CISettings(BaseSettings):
ready_label: str = Field(env="CI_READY_LABEL", default="CI: ready for build")
ready_label: str = Field(alias="CI_READY_LABEL", default="CI: ready for build")
fasttrack_labels: List[str] = Field(
env="CI_FASTTRACK_LABELS",
alias="CI_FASTTRACK_LABELS",
default=["CI: skip compile test", "Process: release backport"],
)


class MailNotifierSettings(BaseSettings):
recipients: List[str] = Field(env="MURDOCK_NOTIFIER_MAIL_RECIPIENTS", default=[])
server: str = Field(env="MURDOCK_NOTIFIER_MAIL_SERVER", default="localhost")
port: int = Field(env="MURDOCK_NOTIFIER_MAIL_PORT", default=25)
use_tls: bool = Field(env="MURDOCK_NOTIFIER_MAIL_USE_TLS", default=True)
username: str = Field(env="MURDOCK_NOTIFIER_MAIL_USERNAME", default="")
password: str = Field(env="MURDOCK_NOTIFIER_MAIL_PASSWORD", default="")
recipients: List[str] = Field(alias="MURDOCK_NOTIFIER_MAIL_RECIPIENTS", default=[])
server: str = Field(alias="MURDOCK_NOTIFIER_MAIL_SERVER", default="localhost")
port: int = Field(alias="MURDOCK_NOTIFIER_MAIL_PORT", default=25)
use_tls: bool = Field(alias="MURDOCK_NOTIFIER_MAIL_USE_TLS", default=True)
username: str = Field(alias="MURDOCK_NOTIFIER_MAIL_USERNAME", default="")
password: str = Field(alias="MURDOCK_NOTIFIER_MAIL_PASSWORD", default="")


class MatrixNotifierSettings(BaseSettings):
room: str = Field(env="MURDOCK_NOTIFIER_MATRIX_ROOM", default="")
token: str = Field(env="MURDOCK_NOTIFIER_MATRIX_TOKEN", default="")
room: str = Field(alias="MURDOCK_NOTIFIER_MATRIX_ROOM", default="")
token: str = Field(alias="MURDOCK_NOTIFIER_MATRIX_TOKEN", default="")


class NotifierSettings(BaseSettings):
pr: List[str] = Field(env="MURDOCK_NOTIFIER_PR_NOTIFIERS", default=["matrix"])
pr: List[str] = Field(alias="MURDOCK_NOTIFIER_PR_NOTIFIERS", default=["matrix"])
branch: List[str] = Field(
env="MURDOCK_NOTIFIER_BRANCH_NOTIFIERS", default=["mail", "matrix"]
alias="MURDOCK_NOTIFIER_BRANCH_NOTIFIERS", default=["mail", "matrix"]
)
tag: List[str] = Field(
env="MURDOCK_NOTIFIER_TAG_NOTIFIERS", default=["mail", "matrix"]
alias="MURDOCK_NOTIFIER_TAG_NOTIFIERS", default=["mail", "matrix"]
)
commit: List[str] = Field(
env="MURDOCK_NOTIFIER_COMMIT_NOTIFIERS", default=["matrix"]
alias="MURDOCK_NOTIFIER_COMMIT_NOTIFIERS", default=["matrix"]
)


class GlobalSettings(BaseSettings):
project: str = Field(env="MURDOCK_PROJECT", default="default")
base_url: str = Field(env="MURDOCK_BASE_URL", default="http://localhost:8000")
work_dir: str = Field(env="MURDOCK_WORK_DIR", default="/var/lib/murdock-data")
project: str = Field(alias="MURDOCK_PROJECT", default="default")
base_url: str = Field(alias="MURDOCK_BASE_URL", default="http://localhost:8000")
work_dir: str = Field(alias="MURDOCK_WORK_DIR", default="/var/lib/murdock-data")
host_work_dir: str = Field(
env="MURDOCK_HOST_WORK_DIR",
alias="MURDOCK_HOST_WORK_DIR",
default=os.path.join(tempfile.gettempdir(), "murdock-data"),
)
scripts_dir: str = Field(
env="MURDOCK_SCRIPTS_DIR", default="/var/lib/murdock-scripts"
alias="MURDOCK_SCRIPTS_DIR", default="/var/lib/murdock-scripts"
)
script_name: str = Field(env="MURDOCK_SCRIPT_NAME", default="run.sh")
run_in_docker: bool = Field(env="MURDOCK_RUN_IN_DOCKER", default=False)
docker_user_uid: int = Field(env="MURDOCK_USER_UID", default=1000)
docker_user_gid: int = Field(env="MURDOCK_USER_GID", default=1000)
script_name: str = Field(alias="MURDOCK_SCRIPT_NAME", default="run.sh")
run_in_docker: bool = Field(alias="MURDOCK_RUN_IN_DOCKER", default=False)
docker_user_uid: int = Field(alias="MURDOCK_USER_UID", default=1000)
docker_user_gid: int = Field(alias="MURDOCK_USER_GID", default=1000)
docker_default_image: str = Field(
env="MURDOCK_DOCKER_DEFAULT_TASK_IMAGE", default="ubuntu:latest"
alias="MURDOCK_DOCKER_DEFAULT_TASK_IMAGE", default="ubuntu:latest"
)
docker_volumes: dict = Field(env="MURDOCK_DOCKER_VOLUMES", default=dict())
docker_cpu_limit: float = Field(env="MURDOCK_DOCKER_CPU_LIMIT", default=1.0)
docker_mem_limit: str = Field(env="MURDOCK_DOCKER_MEM_LIMIT", default="1g")
docker_volumes: dict = Field(alias="MURDOCK_DOCKER_VOLUMES", default=dict())
docker_cpu_limit: float = Field(alias="MURDOCK_DOCKER_CPU_LIMIT", default=1.0)
docker_mem_limit: str = Field(alias="MURDOCK_DOCKER_MEM_LIMIT", default="1g")
accepted_events: List[str] = Field(
env="MURDOCK_ACCEPTED_EVENTS", default=["push", "pull_request"]
alias="MURDOCK_ACCEPTED_EVENTS", default=["push", "pull_request"]
)
num_workers: int = Field(env="MURDOCK_NUM_WORKERS", default=1)
custom_env: dict[str, str] = Field(env="MURDOCK_CUSTOM_ENV", default=dict())
log_level: str = Field(env="MURDOCK_LOG_LEVEL", default="DEBUG")
uvicorn_access_log_output: str = Field(env="UVICORN_LOG_LEVEl", default="INFO")
log_output: str = Field(env="MURDOCK_LOG_OUTPUT", default="console")
num_workers: int = Field(alias="MURDOCK_NUM_WORKERS", default=1)
custom_env: Dict[str, str] = Field(alias="MURDOCK_CUSTOM_ENV", default=dict())
log_level: str = Field(alias="MURDOCK_LOG_LEVEL", default="DEBUG")
uvicorn_access_log_output: str = Field(alias="UVICORN_LOG_LEVEL", default="INFO")
log_output: str = Field(alias="MURDOCK_LOG_OUTPUT", default="console")
max_finished_length_default: int = Field(
env="MURDOCK_MAX_FINISHED_LENGTH_DEFAULT", default=25
alias="MURDOCK_MAX_FINISHED_LENGTH_DEFAULT", default=25
)
cancel_on_update: bool = Field(env="MURDOCK_CANCEL_ON_UPDATE", default=True)
enable_commit_status: bool = Field(env="MURDOCK_ENABLE_COMMIT_STATUS", default=True)
cancel_on_update: bool = Field(alias="MURDOCK_CANCEL_ON_UPDATE", default=True)
enable_commit_status: bool = Field(alias="MURDOCK_ENABLE_COMMIT_STATUS", default=True)
commit_status_context: str = Field(
env="MURDOCK_COMMIT_STATUS_CONTEXT", default="Murdock"
alias="MURDOCK_COMMIT_STATUS_CONTEXT", default="Murdock"
)
enable_pr_comment: bool = Field(env="MURDOCK_ENABLE_PR_COMMENT", default=True)
store_stopped_jobs: bool = Field(env="MURDOCK_STORE_STOPPED_JOBS", default=True)
enable_notifications: bool = Field(env="MURDOCK_NOTIFIER_ENABLE", default=False)
enable_pr_comment: bool = Field(alias="MURDOCK_ENABLE_PR_COMMENT", default=True)
store_stopped_jobs: bool = Field(alias="MURDOCK_STORE_STOPPED_JOBS", default=True)
enable_notifications: bool = Field(alias="MURDOCK_NOTIFIER_ENABLE", default=False)

@validator("work_dir")
def work_dir_exists(cls, path):
Expand Down Expand Up @@ -143,7 +144,7 @@ class MurdockSettings(BaseSettings):
push: PushSettings = Field(default=PushSettings())
pr: PRSettings = Field(default=PRSettings())
commit: CommitSettings = Field(default=CommitSettings())
env: dict[str, str] = Field(default=dict())
env: Dict[str, str] = Field(default=dict())
failfast: bool = Field(default=False)
artifacts: List[str] = Field(default=[])
tasks: List[TaskSettings] = Field(default=[TaskSettings()])
Expand Down
2 changes: 1 addition & 1 deletion murdock/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
config: MurdockSettings = MurdockSettings(),
trigger: Optional[str] = "api",
triggered_by: Optional[str] = None,
user_env: Optional[dict] = None,
user_env: Optional[dict[str, str]] = None,
kaspar030 marked this conversation as resolved.
Show resolved Hide resolved
):
self.trigger: Optional[str] = trigger
self.triggered_by: Optional[str] = triggered_by
Expand Down
10 changes: 5 additions & 5 deletions murdock/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from datetime import time as dtime
from typing import List, Optional
from typing import Dict, List, Optional

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -48,7 +48,7 @@ class PullRequestInfo(BaseModel):
None,
title="True if the pull request is mergeable, False otherwise",
)
labels: list[str] = Field(
labels: List[str] = Field(
None,
title="List of Github labels assigned to the pull request",
)
Expand Down Expand Up @@ -108,7 +108,7 @@ class JobModel(BaseModel):
None,
title="Status of the job",
)
state: str = Field(
state: Optional[str] = Field(
None,
title="State of a job (queued, running, passed, errored or stopped)",
)
Expand All @@ -130,11 +130,11 @@ class JobModel(BaseModel):
triggered_by: Optional[str] = Field(
None, title="Github user who triggered the job creation"
)
env: Optional[dict[str, str]] = Field(
env: Optional[Dict[str, str]] = Field(
None,
title="Dictionnary of environment variables attached to the job",
)
user_env: Optional[dict[str, str]] = Field(
user_env: Optional[Dict[str, str]] = Field(
None,
title="User defined dictionnary of environment variables atteched to the job",
)
Expand Down
Loading