Skip to content

Commit be7b367

Browse files
authored
Merge pull request #307 from dkliban/update-travis
Updates Travis config to the latest
2 parents 95b4426 + 3a9a7b9 commit be7b367

13 files changed

Lines changed: 165 additions & 42 deletions

.travis/Containerfile.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM pulp/pulp-ci:latest
1+
FROM {{ ci_base | default("pulp/pulp-ci:latest") }}
22

33
{% if s3_test | default(false) %}
44
# Hacking botocore (https://github.com/boto/botocore/pull/1990)

.travis/before_install.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
set -mveuo pipefail
1111

12+
mkdir .travis/vars || true
13+
echo "---" > .travis/vars/main.yaml
14+
1215
export PRE_BEFORE_INSTALL=$TRAVIS_BUILD_DIR/.travis/pre_before_install.sh
1316
export POST_BEFORE_INSTALL=$TRAVIS_BUILD_DIR/.travis/post_before_install.sh
1417

@@ -29,10 +32,12 @@ then
2932
export PULPCORE_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore\/pull\/(\d+)' | awk -F'/' '{print $7}')
3033
export PULP_SMASH_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp-smash\/pull\/(\d+)' | awk -F'/' '{print $7}')
3134
export PULP_OPENAPI_GENERATOR_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp-openapi-generator\/pull\/(\d+)' | awk -F'/' '{print $7}')
35+
echo $COMMIT_MSG | sed -n -e 's/.*CI Base Image:\s*\([-_/[:alnum:]]*:[-_[:alnum:]]*\).*/ci_base: "\1"/p' >> .travis/vars/main.yaml
3236
else
3337
export PULPCORE_PR_NUMBER=
3438
export PULP_SMASH_PR_NUMBER=
3539
export PULP_OPENAPI_GENERATOR_PR_NUMBER=
40+
export CI_BASE_IMAGE=
3641
fi
3742

3843
# dev_requirements contains tools needed for flake8, etc.

.travis/before_script.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ if [[ -f $PRE_BEFORE_SCRIPT ]]; then
1818
source $PRE_BEFORE_SCRIPT
1919
fi
2020

21+
# Developers should be able to reproduce the containers with this config
22+
echo "CI vars:"
23+
tail -v -n +1 .travis/vars/main.yaml
24+
2125
# Developers often want to know the final pulp config
2226
echo "PULP CONFIG:"
2327
tail -v -n +1 .travis/settings/settings.* ~/.config/pulp_smash/settings.json

.travis/build_container.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
dest: Containerfile
1212

1313
- name: "Build pulp image"
14-
docker_image:
1514
# We build from the ../.. (parent dir of pulpcore git repo) Docker build
1615
# "context" so that repos like pulp-smash are accessible to Docker
1716
# build. So that PR branches can be used via relative paths.
@@ -20,15 +19,7 @@
2019
# 1-off-builds and Travis CI purposes (which has no cache across CI runs.)
2120
# Run build.yaml with -e cache=false if your builds are using outdated
2221
# layers.
23-
name: "{{ image.name }}"
24-
tag: "{{ image.tag }}"
25-
build:
26-
path: "../.."
27-
dockerfile: "{{ playbook_dir }}/Containerfile"
28-
nocache: "{{ not cache | default(true) | bool }}"
29-
pull: false
30-
state: present
31-
source: build
22+
command: "docker build --network host --no-cache={{ not cache | default(true) | bool }} -t {{ image.name }}:{{ image.tag }} -f {{ playbook_dir }}/Containerfile ../.."
3223

3324
- name: "Clean image cache"
3425
docker_prune:

.travis/install.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ else
4444
# Fallback
4545
TAG=$(git rev-parse --abbrev-ref HEAD | tr / _)
4646
fi
47-
48-
mkdir vars
4947
if [ -n "$TRAVIS_TAG" ]; then
5048
# Install the plugin only and use published PyPI packages for the rest
5149
# Quoting ${TAG} ensures Ansible casts the tag as a string.
52-
cat > vars/main.yaml << VARSYAML
53-
---
50+
cat >> vars/main.yaml << VARSYAML
5451
image:
5552
name: pulp
5653
tag: "${TAG}"
@@ -66,8 +63,7 @@ services:
6663
- ./settings:/etc/pulp
6764
VARSYAML
6865
else
69-
cat > vars/main.yaml << VARSYAML
70-
---
66+
cat >> vars/main.yaml << VARSYAML
7167
image:
7268
name: pulp
7369
tag: "${TAG}"

.travis/redmine.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# WARNING: DO NOT EDIT!
2+
#
3+
# This file was generated by plugin_template, and is managed by it. Please use
4+
# './plugin-template --travis pulp_python' to update this file.
5+
#
6+
# For more info visit https://github.com/pulp/plugin_template
7+
8+
import os
9+
import sys
10+
11+
from redminelib import Redmine
12+
13+
REDMINE_API_KEY = os.environ["REDMINE_API_KEY"]
14+
REDMINE_QUERY_URL = sys.argv[1]
15+
CLOSED_CURRENTRELEASE = 11
16+
17+
redmine = Redmine(REDMINE_QUERY_URL.split("issues")[0], key=REDMINE_API_KEY)
18+
query_issues = REDMINE_QUERY_URL.split("=")[-1].split(",")
19+
20+
to_update = []
21+
for issue in query_issues:
22+
status = redmine.issue.get(int(issue)).status.name
23+
if "CLOSE" not in status and status != "MODIFIED":
24+
raise ValueError("One or more issues are not MODIFIED")
25+
if status == "MODIFIED": # Removing the already closed
26+
to_update.append(int(issue))
27+
28+
for issue in to_update:
29+
print(f"Closing #{issue}")
30+
redmine.issue.update(issue, status_id=CLOSED_CURRENTRELEASE)

.travis/release.py

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,81 @@
1+
# WARNING: DO NOT EDIT!
2+
#
3+
# This file was generated by plugin_template, and is managed by it. Please use
4+
# './plugin-template --travis pulp_python' to update this file.
5+
#
6+
# For more info visit https://github.com/pulp/plugin_template
7+
18
import argparse
9+
import json
210
import os
311
import textwrap
12+
from collections import defaultdict
13+
from pathlib import Path
414

515
from git import Repo
16+
from redminelib import Redmine
17+
18+
19+
REDMINE_URL = "https://pulp.plan.io"
20+
REDMINE_QUERY_URL = f"{REDMINE_URL}/issues?set_filter=1&status_id=*&issue_id="
21+
22+
23+
def validate_redmine_data(redmine_query_url, redmine_issues):
24+
"""Validate redmine milestone."""
25+
redmine = Redmine("https://pulp.plan.io")
26+
project_set = set()
27+
stats = defaultdict(list)
28+
milestone_url = "\n[noissue]"
29+
for issue in redmine_issues:
30+
redmine_issue = redmine.issue.get(int(issue))
31+
32+
project_name = redmine_issue.project.name
33+
project_set.update([project_name])
34+
stats[f"project_{project_name.lower().replace(' ', '_')}"].append(issue)
35+
36+
status = redmine_issue.status.name
37+
if "CLOSE" not in status and status != "MODIFIED":
38+
stats["status_not_modified"].append(issue)
39+
40+
print(f"\n\nRedmine stats: {json.dumps(stats, indent=2)}")
41+
error_messages = []
42+
if stats.get("status_not_modified"):
43+
error_messages.append(f"One or more issues are not MODIFIED {stats['status_not_modified']}")
44+
if stats.get("without_milestone"):
45+
error_messages.append(
46+
f"One or more issues are not associated with a milestone {stats['without_milestone']}"
47+
)
48+
if len(project_set) > 1:
49+
error_messages.append(f"Issues with different projects - {project_set}")
50+
if error_messages:
51+
error_messages.append(f"Verify at {redmine_query_url}")
52+
raise RuntimeError("\n".join(error_messages))
53+
54+
return milestone_url
655

756

8-
REDMINE_QUERY_URL = "https://pulp.plan.io/issues?set_filter=1&status_id=*&issue_id="
957
release_path = os.path.dirname(os.path.abspath(__file__))
1058
plugin_path = release_path
1159
if ".travis" in release_path:
1260
plugin_path = os.path.dirname(release_path)
1361

1462
version = {}
15-
with open(f"{plugin_path}/pulp_python/__init__.py") as fp:
63+
plugin_name = "pulp_python"
64+
with open(f"{plugin_path}/{plugin_name}/__init__.py") as fp:
1665
version_line = [line for line in fp.readlines() if "__version__" in line][0]
1766
exec(version_line, version)
1867
release_version = version["__version__"].replace(".dev", "")
1968

20-
to_close = []
21-
for filename in os.listdir(f"{plugin_path}/CHANGES"):
22-
if filename.split(".")[0].isdigit():
23-
to_close.append(filename.split(".")[0])
24-
issues = ",".join(to_close)
69+
issues_to_close = []
70+
for filename in Path(f"{plugin_path}/CHANGES").rglob("*"):
71+
if filename.stem.isdigit():
72+
issue = filename.stem
73+
issue_url = f"{REDMINE_URL}/issues/{issue}.json"
74+
issues_to_close.append(issue)
75+
76+
issues = ",".join(issues_to_close)
77+
redmine_final_query = f"{REDMINE_QUERY_URL}{issues}"
78+
milestone_url = validate_redmine_data(redmine_final_query, issues_to_close)
2579

2680
helper = textwrap.dedent(
2781
"""\
@@ -89,28 +143,29 @@
89143

90144
os.system("bump2version release --allow-dirty")
91145

92-
plugin_name = plugin_path.split("/")[-1]
93146
git.add(f"{plugin_path}/{plugin_name}/__init__.py")
94147
git.add(f"{plugin_path}/setup.py")
95148
git.add(f"{plugin_path}/requirements.txt")
96149
git.add(f"{plugin_path}/.bumpversion.cfg")
97-
git.commit("-m", f"Releasing {release_version}\n\n[noissue]")
150+
git.commit(
151+
"-m", f"Releasing {release_version}\n\nRedmineQuery: {redmine_final_query}\n{milestone_url}"
152+
)
98153

99154
sha = repo.head.object.hexsha
100155
short_sha = git.rev_parse(sha, short=7)
101156

102157
# Third commit: bump to .dev
103158
with open(f"{plugin_path}/requirements.txt", "wt") as setup_file:
104159
for line in setup_lines:
105-
if "pulpcore" in line and "pulpcore" not in release_path:
160+
if "pulpcore" in line and "pulpcore" not in release_path and release_type != "patch":
106161
line = f"pulpcore>={lower_pulpcore_version}\n"
107162

108163
setup_file.write(line)
109164

110165
os.system(f"bump2version {release_type} --allow-dirty")
111166

112167
version = {}
113-
with open(f"{plugin_path}/pulp_python/__init__.py") as fp:
168+
with open(f"{plugin_path}/{plugin_name}/__init__.py") as fp:
114169
version_line = [line for line in fp.readlines() if "__version__" in line][0]
115170
exec(version_line, version)
116171
new_dev_version = version["__version__"]
@@ -122,6 +177,6 @@
122177
git.add(f"{plugin_path}/.bumpversion.cfg")
123178
git.commit("-m", f"Bump to {new_dev_version}\n\n[noissue]")
124179

125-
print(f"\n\nRedmine query of issues to close:\n{REDMINE_QUERY_URL}{issues}")
180+
print(f"\n\nRedmine query of issues to close:\n{redmine_final_query}")
126181
print(f"Release commit == {short_sha}")
127182
print(f"All changes were committed on branch: release_{release_version}")

.travis/release_requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bump2version
2+
gitpython
3+
python-redmine

.travis/settings.py.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
CONTENT_ORIGIN = "http://pulp:80"
22
ANSIBLE_API_HOSTNAME = "http://pulp:80"
33
ANSIBLE_CONTENT_HOSTNAME = "http://pulp:80/pulp/content"
4-
TOKEN_AUTH_DISABLED = True
4+
PRIVATE_KEY_PATH = "/etc/pulp/certs/token_private_key.pem"
5+
PUBLIC_KEY_PATH = "/etc/pulp/certs/token_public_key.pem"
6+
TOKEN_SERVER = "http://pulp:80/token"
7+
TOKEN_SIGNATURE_ALGORITHM = "ES256"
58

69
{% if pulp_settings %}
710
{% for key, value in pulp_settings.items() %}

.travis/start_container.yaml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,27 @@
6767
state: present
6868
when: s3_test | default(false)
6969

70-
- name: "Wait for Pulp"
71-
uri:
72-
url: "http://pulp/pulp/api/v3/status/"
73-
follow_redirects: none
74-
register: result
75-
until: result.status == 200
76-
retries: 6
77-
delay: 5
70+
- block:
71+
- name: "Wait for Pulp"
72+
uri:
73+
url: "http://pulp/pulp/api/v3/status/"
74+
follow_redirects: none
75+
register: result
76+
until: result.status == 200
77+
retries: 6
78+
delay: 5
79+
rescue:
80+
- name: "Output pulp container log"
81+
command: "docker logs pulp"
82+
failed_when: true
83+
84+
- name: "Set pulp password in .netrc"
85+
copy:
86+
dest: "~/.netrc"
87+
content: |
88+
machine pulp
89+
login admin
90+
password password
7891
7992
- hosts: pulp
8093
gather_facts: false

0 commit comments

Comments
 (0)