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

Improve linkage of PR CL items for admin (#6706) #6712

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions .github/ISSUE_TEMPLATE/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ _period: 14 days
- [ ] Remove unused dependencies with high or critical CVEs
- [ ] Push commit to GitHub (directly to `master` branch, no PR needed)
- [ ] GH Action workflow succeeded
- [ ] Image is available on [DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm)
- [ ] Image is available on [DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm/tags)
- [ ] Update [Elasticsearch image](https://github.com/DataBiosphere/azul-docker-elasticsearch)
- [ ] Bump [base image](https://hub.docker.com/_/elasticsearch/tags) tag (only minor and patch versions), if possible
- [ ] Bump internal version
- [ ] Remove unused dependencies with high or critical CVEs
- [ ] Push commit to GitHub (directly to `main` branch, no PR needed)
- [ ] GH Action workflow succeeded
- [ ] Image is available on [DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch)
- [ ] Image is available on [DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch/tags)
- [ ] Update [BigQuery Emulator image](https://github.com/DataBiosphere/azul-bigquery-emulator)
- [ ] Bump [base image](https://hub.docker.com/_/debian/tags?name=bookworm) tag, if possible
- [ ] Bump internal version
- [ ] Push commit to GitHub (directly to `azul` branch, no PR needed)
- [ ] GH Action workflow succeeded
- [ ] Image is available on [DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator)
- [ ] Image is available on [DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator/tags)
- [ ] Create Azul PR, connected to this issue, with …
- [ ] … changes to `requirements*.txt` from open Dependabot PRs, one commit per PR
- [ ] … update to [Python](https://hub.docker.com/_/python/tags) (only patch versions) <sub>or no update available</sub>
- [ ] … update to [Terraform](https://hub.docker.com/r/hashicorp/terraform/tags) (only patch versions) <sub>or no update available</sub>
- [ ] … new [PyCharm image](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm)
- [ ] … new [Elasticsearch image](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch)
- [ ] … new [BigQuery Emulator image](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator)
- [ ] … new [PyCharm image](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm/tags)
- [ ] … new [Elasticsearch image](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch/tags)
- [ ] … new [BigQuery Emulator image](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator/tags)
- [ ] … update to [Docker images](https://hub.docker.com/_/docker/tags) (only minor and patch versions) <sub>or no update available</sub>
- [ ] … update to [GitLab](https://hub.docker.com/r/gitlab/gitlab-ce/tags) & [GitLab runner images](https://hub.docker.com/r/gitlab/gitlab-runner/tags) <sub>or no update available</sub>
- [ ] … update to [ClamAV image](https://hub.docker.com/r/clamav/clamav/tags) <sub>or no update available</sub>
Expand Down
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE/anvilprod-promotion.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Connected issue: #0000

### System administrator

- [ ] Background migrations for `anvilprod.gitlab` are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for [`anvilprod.gitlab`](https://gitlab.explore.anvilproject.org/admin/background_migrations) are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] PR is assigned to only the operator


Expand Down Expand Up @@ -100,9 +100,9 @@ Connected issue: #0000

### System administrator

- [ ] Removed unused image tags from [pycharm image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [elasticsearch image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [bigquery_emulator image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [pycharm image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm/tags) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [elasticsearch image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch/tags) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [bigquery_emulator image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator/tags) <sub>or this promotion does not alter references to that image</sub>
- [ ] PR is assigned to no one


Expand Down
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE/prod-promotion.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Connected issue: #0000

### System administrator

- [ ] Background migrations for `prod.gitlab` are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for [`prod.gitlab`](https://gitlab.azul.data.humancellatlas.org/admin/background_migrations) are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] PR is assigned to only the operator


Expand Down Expand Up @@ -94,9 +94,9 @@ Connected issue: #0000

### System administrator

- [ ] Removed unused image tags from [pycharm image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [elasticsearch image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [bigquery_emulator image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [pycharm image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-pycharm/tags) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [elasticsearch image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-elasticsearch/tags) <sub>or this promotion does not alter references to that image</sub>
- [ ] Removed unused image tags from [bigquery_emulator image on DockerHub](https://hub.docker.com/repository/docker/ucscgi/azul-bigquery-emulator/tags) <sub>or this promotion does not alter references to that image</sub>
- [ ] PR is assigned to no one


Expand Down
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ Connected issue: #0000

### System administrator

- [ ] Background migrations for `dev.gitlab` are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for `anvildev.gitlab` are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for [`dev.gitlab`](https://gitlab.dev.singlecell.gi.ucsc.edu/admin/background_migrations) are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for [`anvildev.gitlab`](https://gitlab.anvil.gi.ucsc.edu/admin/background_migrations) are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] PR is assigned to only the operator


Expand Down
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ title is `Fix: ` followed by the issue title

### System administrator

- [ ] Background migrations for `dev.gitlab` are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for `anvildev.gitlab` are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for [`dev.gitlab`](https://gitlab.dev.singlecell.gi.ucsc.edu/admin/background_migrations) are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] Background migrations for [`anvildev.gitlab`](https://gitlab.anvil.gi.ucsc.edu/admin/background_migrations) are complete <sub>or this PR is not labeled `deploy:gitlab`</sub>
- [ ] PR is assigned to only the operator


Expand Down
20 changes: 18 additions & 2 deletions .github/pull_request_template.md.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
from azul.collections import (
OrderedSet,
)
from azul.modules import (
load_module,
)
from azul.strings import (
back_quote as bq,
join_grammatically,
Expand Down Expand Up @@ -237,6 +240,17 @@ def main():
emit(t, target_branch)


def env_var(deployment: str, variable: str) -> str:
"""
Return an environment variable value from the given deployment.
"""
module_path = f'{config.project_root}/scripts/export_environment.py'
export_environment = load_module(module_path, 'export_environment')
env, warning = export_environment.load_env(deployment)
resolved_env = export_environment.resolve_env(env)
return resolved_env[variable]


def emit(t: T, target_branch: str):
emit_checklist(
[
Expand Down Expand Up @@ -714,7 +728,9 @@ def emit(t: T, target_branch: str):
*[
{
'type': 'cli',
'content': f'Background migrations for `{d}.gitlab` are complete',
'content': f'Background migrations for '
f'[`{d}.gitlab`](https://gitlab.{env_var(d, "AZUL_DOMAIN_NAME")}'
f'/admin/background_migrations) are complete',
'alt': 'or this PR is not labeled `deploy:gitlab`'
}
for d in t.target_deployments(target_branch)
Expand Down Expand Up @@ -1011,7 +1027,7 @@ def emit(t: T, target_branch: str):
*[
{
'type': 'cli',
'content': f'Removed unused image tags from [{name} image on DockerHub]({url})',
'content': f'Removed unused image tags from [{name} image on DockerHub]({url}/tags)',
'alt': 'or this promotion does not alter references to that image'
}
for name, url in custom_images.items()
Expand Down
56 changes: 35 additions & 21 deletions scripts/export_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def env(self) -> DraftEnvironment:
}


class InvalidDeployment(RuntimeError):

def __init__(self, dir_: Path) -> None:
super().__init__(
f"{dir_} does not exist or is not a symbolic link to a directory."
)


class InvalidActiveDeployment(RuntimeError):

def __init__(self, dir_: Path) -> None:
Expand All @@ -91,35 +99,41 @@ def __init__(self, parent: Path, component: Path) -> None:
)


def load_env() -> Tuple[Environment, Optional[str]]:
def load_env(deployment: Optional[str] = None
) -> Tuple[Environment, Optional[str]]:
"""
Load environment.py and environment.local.py modules from the project
root and the current active deployment directory, call their env()
function to obtain the environment dictionary and merge the dictionaries.
The entries from an environment.local.py take precedence over those from
a corresponding environment.py in the same directory. The modules from
the deployment directory take precedence over ones in the project root.
root and either the specified deployment or the current active deployment
directory, call their env() function to obtain the environment dictionary
and merge the dictionaries. The entries from an environment.local.py take
precedence over those from a corresponding environment.py in the same
directory. The modules from the deployment directory take precedence over
ones in the project root.
"""

deployments_dir = root_dir / 'deployments'
active_deployment_dir = deployments_dir / '.active'
if active_deployment_dir.exists():
if not active_deployment_dir.is_dir() or not active_deployment_dir.is_symlink():
raise InvalidActiveDeployment(active_deployment_dir)

if deployment is not None or active_deployment_dir.exists():
if deployment is not None:
deployment_dir = deployments_dir / deployment
if not deployment_dir.is_dir():
raise InvalidDeployment(deployment_dir)
else:
if not active_deployment_dir.is_dir() or not active_deployment_dir.is_symlink():
raise InvalidActiveDeployment(active_deployment_dir)
deployment_dir = Path(os.readlink(str(active_deployment_dir)))
if not deployment_dir.is_absolute():
deployment_dir = deployments_dir / deployment_dir
if not deployment_dir.is_dir():
raise InvalidActiveDeployment(deployment_dir)
# If active deployment is a component of another one, also load the parent
# deployments (like dev.gitlab).
active_deployment_dir = Path(os.readlink(str(active_deployment_dir)))
if not active_deployment_dir.is_absolute():
active_deployment_dir = deployments_dir / active_deployment_dir
if not active_deployment_dir.is_dir():
raise InvalidActiveDeployment(active_deployment_dir)
relative_active_deployment_dir = active_deployment_dir.relative_to(deployments_dir)
prefix, _, suffix = str(relative_active_deployment_dir).partition('.')
relative_deployment_dir = deployment_dir.relative_to(deployments_dir)
prefix, _, suffix = str(relative_deployment_dir).partition('.')
if suffix and suffix != 'local':
parent_deployment_dir = deployments_dir / prefix
if not parent_deployment_dir.exists():
raise BadParentDeployment(parent_deployment_dir, active_deployment_dir)
raise BadParentDeployment(parent_deployment_dir, deployment_dir)
else:
parent_deployment_dir = None
warning = None
Expand All @@ -128,7 +142,7 @@ def load_env() -> Tuple[Environment, Optional[str]]:
f'No active deployment (missing {str(active_deployment_dir)!r}). '
f'Loaded global defaults only.'
)
active_deployment_dir = None
deployment_dir = None
parent_deployment_dir = None

def _load(dir_path: Path, local: bool = False) -> Optional[EnvironmentModule]:
Expand All @@ -153,10 +167,10 @@ def _load(dir_path: Path, local: bool = False) -> Optional[EnvironmentModule]:
return None

modules = [
active_deployment_dir and _load(active_deployment_dir, local=True),
deployment_dir and _load(deployment_dir, local=True),
parent_deployment_dir and _load(parent_deployment_dir, local=True),
_load(root_dir, local=True),
active_deployment_dir and _load(active_deployment_dir),
deployment_dir and _load(deployment_dir),
parent_deployment_dir and _load(parent_deployment_dir),
_load(root_dir)
]
Expand Down
Loading