Skip to content

Commit

Permalink
Update CI files
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
pulpbot committed Nov 5, 2023
1 parent 934ed82 commit 409442d
Show file tree
Hide file tree
Showing 28 changed files with 771 additions and 536 deletions.
46 changes: 32 additions & 14 deletions .ci/ansible/Containerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,50 @@ FROM {{ ci_base | default("ghcr.io/pulp/pulp-ci-centos:" + pulp_container_tag) }

# Add source directories to container
{% for item in plugins %}
{% if item.source.startswith("./") %}
ADD {{ item.source }} {{ item.source }}
{% if item.source.startswith("./") or item.ci_requirements | default(false) %}
ADD ./{{ item.name }} ./{{ item.name }}
{% endif %}
{% endfor %}

# Install python packages
# Hacking botocore (https://github.com/boto/botocore/pull/1990)

RUN pip3 install \
{%- if stream_test | default(false) -%}
{{ " " }}django-storages[sftp]
RUN pip3 install
{%- for item in plugins -%}
{%- if item.name == "pulp-certguard" -%}
{{ " " }}python-dateutil rhsm
{%- endif -%}
{{ " " }}{{ item.source }}
{%- if item.name == "pulpcore" -%}
{%- if s3_test | default(false) -%}
{{ " " }}django-storages[boto3] git+https://github.com/fabricio-aguiar/botocore.git@fix-100-continue
[s3]
{%- elif azure_test | default(false) -%}
[azure]
{%- elif gcp_test | default(false) -%}
[google]
{%- endif -%}
{%- if azure_test | default(false) -%}
{{ " " }}django-storages[azure]>=1.12.2
{%- endif -%}
{%- for item in plugins -%}
{%- if item.name == "pulp-certguard" -%}
{{ " " }}python-dateutil rhsm
{%- if item.ci_requirements | default(false) -%}
{{ " " }}-r ./{{ item.name }}/ci_requirements.txt
{%- endif -%}
{{ " " }}"{{ item.source }}"
{%- endfor %}

RUN mkdir -p /etc/nginx/pulp/
{% if pulp_env is defined and pulp_env %}
{% for key, value in pulp_env.items() %}
ENV {{ key | upper }}={{ value }}
{% endfor %}
{% endif %}

{% if pulp_scenario_env is defined and pulp_scenario_env %}
{% for key, value in pulp_scenario_env.items() %}
ENV {{ key | upper }}={{ value }}
{% endfor %}
{% endif %}

USER pulp:pulp
RUN PULP_STATIC_ROOT=/var/lib/operator/static/ PULP_CONTENT_ORIGIN=localhost \
/usr/local/bin/pulpcore-manager collectstatic --clear --noinput --link
USER root:root

{% for item in plugins %}
RUN export plugin_path="$(pip3 show {{ item.name }} | sed -n -e 's/Location: //p')/{{ item.name }}" && \
ln $plugin_path/app/webserver_snippets/nginx.conf /etc/nginx/pulp/{{ item.name }}.conf || true
Expand Down
21 changes: 8 additions & 13 deletions .ci/ansible/settings.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TOKEN_SIGNATURE_ALGORITHM = "ES256"
CACHE_ENABLED = True
REDIS_HOST = "localhost"
REDIS_PORT = 6379
TELEMETRY = False
ANALYTICS = False

{% if api_root is defined %}
API_ROOT = {{ api_root | repr }}
Expand All @@ -26,18 +26,6 @@ API_ROOT = {{ api_root | repr }}
{% endfor %}
{% endif %}

{% if stream_test | default(false) -%}
REDIRECT_TO_OBJECT_STORAGE = False
DEFAULT_FILE_STORAGE = "pulpcore.app.models.storage.PulpSFTPStorage"
MEDIA_ROOT = ""
SFTP_STORAGE_HOST = "ci-sftp"
SFTP_STORAGE_ROOT = "/storage/"
SFTP_STORAGE_PARAMS = {
"username": "foo",
"key_filename": "/keys/id_ed25519",
}
{%- endif %}

{% if s3_test | default(false) %}
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
MEDIA_ROOT = ""
Expand All @@ -63,3 +51,10 @@ AZURE_OVERWRITE_FILES = True
AZURE_URL_EXPIRATION_SECS = 120
AZURE_CONNECTION_STRING = 'DefaultEndpointsProtocol={{ pulp_scheme }};AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint={{ pulp_scheme }}://ci-azurite:10000/devstoreaccount1;'
{% endif %}

{% if gcp_test | default(false) %}
DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
MEDIA_ROOT = ""
GS_BUCKET_NAME = "gcppulp"
GS_CUSTOM_ENDPOINT = "http://ci-gcp:4443"
{% endif %}
8 changes: 0 additions & 8 deletions .ci/ansible/start_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
- ssh
- ~/.config/pulp_smash

- name: Generate an OpenSSH keypair
community.crypto.openssh_keypair:
path: ssh/id_ed25519
type: ed25519
owner: 700 # pulp in the container
become: true
when: stream_test | default(false)

- name: "Generate Pulp Settings"
template:
src: settings.py.j2
Expand Down
1 change: 0 additions & 1 deletion .ci/assets/release_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bump2version
gitpython
python-redmine
towncrier
34 changes: 34 additions & 0 deletions .ci/scripts/calc_deps_lowerbounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# WARNING: DO NOT EDIT!
#
# This file was generated by plugin_template, and is managed by it. Please use
# './plugin-template --github pulp_cookbook' to update this file.
#
# For more info visit https://github.com/pulp/plugin_template

from packaging.requirements import Requirement


def main():
"""Calculate the lower bound of dependencies where possible."""
with open("requirements.txt") as req_file:
for line in req_file:
try:
requirement = Requirement(line)
except ValueError:
print(line.strip())
else:
for spec in requirement.specifier:
if spec.operator == ">=":
if requirement.name == "pulpcore":
operator = "~="
else:
operator = "=="
min_version = str(spec)[2:]
print(f"{requirement.name}{operator}{min_version}")
break
else:
print(line.strip())


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion .ci/scripts/check_gettext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ cd "$(dirname "$(realpath -e "$0")")"/../..

set -uv

# check for imports not from pulpcore.plugin. exclude tests
MATCHES=$(grep -n -r --include \*.py "_(f")

if [ $? -ne 1 ]; then
Expand Down
112 changes: 112 additions & 0 deletions .ci/scripts/check_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env python

# WARNING: DO NOT EDIT!
#
# This file was generated by plugin_template, and is managed by it. Please use
# './plugin-template --github pulp_cookbook' to update this file.
#
# For more info visit https://github.com/pulp/plugin_template

import argparse
import re
import os
import yaml
from tempfile import TemporaryDirectory
from packaging.version import Version
from git import Repo

UPSTREAM_REMOTE = "https://github.com/pulp/pulp_cookbook.git"
DEFAULT_BRANCH = "main"
RELEASE_BRANCH_REGEX = r"^([0-9]+)\.([0-9]+)$"
Y_CHANGELOG_EXTS = [".feature", ".removal", ".deprecation"]
Z_CHANGELOG_EXTS = [".bugfix", ".doc", ".misc"]


def main():
"""Check which branches need a release."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--branches",
default="supported",
help="A comma separated list of branches to check for releases. Can also use keyword: "
"'supported'. Defaults to 'supported', see `ci_update_branches` in "
"`plugin_template.yml`.",
)
opts = parser.parse_args()

with TemporaryDirectory() as d:
# Clone from upstream to ensure we have updated branches & main
repo = Repo.clone_from(UPSTREAM_REMOTE, d, filter="blob:none")
heads = [h.split("/")[-1] for h in repo.git.ls_remote("--heads").split("\n")]
available_branches = [h for h in heads if re.search(RELEASE_BRANCH_REGEX, h)]
available_branches.sort(key=lambda ver: Version(ver))
available_branches.append(DEFAULT_BRANCH)

branches = opts.branches
if branches == "supported":
with open(f"{d}/template_config.yml", mode="r") as f:
tc = yaml.safe_load(f)
branches = tc["ci_update_branches"]
branches.append(DEFAULT_BRANCH)
else:
branches = branches.split(",")

if diff := set(branches) - set(available_branches):
print(f"Supplied branches contains non-existent branches! {diff}")
exit(1)

print(f"Checking for releases on branches: {branches}")

releases = []
for branch in branches:
if branch != DEFAULT_BRANCH:
# Check if a Z release is needed
changes = repo.git.ls_tree("-r", "--name-only", f"origin/{branch}", "CHANGES/")
z_release = False
for change in changes.split("\n"):
# Check each changelog file to make sure everything checks out
_, ext = os.path.splitext(change)
if ext in Y_CHANGELOG_EXTS:
print(
f"Warning: A non-backported changelog ({change}) is present in the "
f"{branch} release branch!"
)
elif ext in Z_CHANGELOG_EXTS:
z_release = True
if z_release:
# Blobless clone does not have file contents for Z branches,
# check commit message for last Z bump
git_branch = f"origin/{branch}"
next_version = repo.git.log(
"--oneline", "--grep=Bump to", "-n 1", git_branch, "--", ".bumpversion.cfg"
).split("to")[-1]
next_version = Version(next_version)
print(
f"A Z-release is needed for {branch}, "
f"New Version: {next_version.base_version}"
)
releases.append(next_version)
else:
# Check if a Y release is needed
changes = repo.git.ls_tree("-r", "--name-only", DEFAULT_BRANCH, "CHANGES/")
for change in changes.split("\n"):
_, ext = os.path.splitext(change)
if ext in Y_CHANGELOG_EXTS:
# We don't put Y release bumps in the commit message, check file instead
# The 'current_version' is always the next version to release
next_version = repo.git.grep(
"current_version", DEFAULT_BRANCH, "--", ".bumpversion.cfg"
).split("=")[-1]
next_version = Version(next_version)
print(
f"A new Y-release is needed! New Version: {next_version.base_version}"
)
releases.append(next_version)
break

if len(releases) == 0:
print("No new releases to perform.")


if __name__ == "__main__":
main()
66 changes: 66 additions & 0 deletions .ci/scripts/check_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# WARNING: DO NOT EDIT!
#
# This file was generated by plugin_template, and is managed by it. Please use
# './plugin-template --github pulp_cookbook' to update this file.
#
# For more info visit https://github.com/pulp/plugin_template

import warnings
from pkg_resources import Requirement


CHECK_MATRIX = [
("requirements.txt", True, True, True),
("dev_requirements.txt", False, True, False),
("ci_requirements.txt", False, True, True),
("doc_requirements.txt", False, True, False),
("lint_requirements.txt", False, True, True),
("unittest_requirements.txt", False, True, True),
("functest_requirements.txt", False, True, True),
("clitest_requirements.txt", False, True, True),
]

errors = []

for filename, check_upperbound, check_prereleases, check_r in CHECK_MATRIX:
try:
with open(filename, "r") as fd:
for nr, line in enumerate(fd.readlines()):
line = line.strip()
if not line or line.startswith("#"):
continue
try:
req = Requirement.parse(line)
except ValueError:
if line.startswith("git+"):
# The single exception...
if "pulp-smash" not in line:
errors.append(f"{filename}:{nr}: Invalid source requirement: {line}")
elif line.startswith("-r "):
if check_r:
errors.append(f"{filename}:{nr}: Invalid deferred requirement: {line}")
else:
errors.append(f"{filename}:{nr}: Unreadable requirement {line}")
else:
if check_prereleases and req.specifier.prereleases:
# Do not even think about begging for more exceptions!
if (
not req.name.startswith("opentelemetry")
and req.name != "pulp-cookbook-client"
):
errors.append(f"{filename}:{nr}: Prerelease versions found in {line}.")
ops = [op for op, ver in req.specs]
spec = str(req.specs)
if "~=" in ops:
warnings.warn(f"{filename}:{nr}: Please avoid using ~= on {req.name}!")
elif "<" not in ops and "<=" not in ops and "==" not in ops:
if check_upperbound:
errors.append(f"{filename}:{nr}: Upper bound missing in {line}.")
except FileNotFoundError:
# skip this test for plugins that don't use this requirements.txt
pass

if errors:
print("Dependency issues found:")
print("\n".join(errors))
exit(1)
Loading

0 comments on commit 409442d

Please sign in to comment.