Skip to content

Commit 948706d

Browse files
authored
Add GitHub Action to Release All Images (#514)
1 parent cb8f250 commit 948706d

File tree

11 files changed

+180
-148
lines changed

11 files changed

+180
-148
lines changed

.evergreen.yml

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ functions:
3939
permissions: public-read
4040
content_type: text/plain
4141

42-
# This is a blocker for the release process. It will *always* fail and needs to be overriden
43-
# if the release needs to proceed.
44-
release_blocker:
45-
- command: subprocess.exec
46-
type: setup
47-
params:
48-
working_dir: mongodb-kubernetes-operator
49-
binary: scripts/ci/release_blocker
50-
5142
setup_kubernetes_environment:
5243
- command: subprocess.exec
5344
type: setup
@@ -125,20 +116,6 @@ functions:
125116
binary: scripts/ci/build_and_push_image_sonar.sh
126117

127118

128-
add_supported_release:
129-
- *python_venv
130-
- *python_requirements
131-
- command: subprocess.exec
132-
type: setup
133-
params:
134-
working_dir: mongodb-kubernetes-operator
135-
include_expansions_in_env:
136-
- atlas_connection_string
137-
- atlas_password
138-
- atlas_database
139-
- image_name
140-
command: "${workdir}/venv/bin/python scripts/ci/add_supported_release.py --image ${image_name}"
141-
142119
task_groups:
143120
- name: e2e_test_group
144121
max_hosts: 8
@@ -336,62 +313,6 @@ tasks:
336313
vars:
337314
test: replica_set_custom_role
338315

339-
- name: release_blocker
340-
commands:
341-
- func: clone
342-
- func: release_blocker
343-
344-
- name: release_operator
345-
commands:
346-
- func: clone
347-
- func: setup_virtualenv
348-
- func: build_and_push_image_sonar
349-
vars:
350-
image_name: operator-ubi
351-
release: true
352-
353-
- name: release_version_upgrade_post_start_hook
354-
commands:
355-
- func: clone
356-
- func: setup_virtualenv
357-
- func: build_and_push_image_sonar
358-
vars:
359-
image_name: version-post-start-hook-init
360-
release: true
361-
362-
363-
- name: release_readiness_probe
364-
commands:
365-
- func: clone
366-
- func: setup_virtualenv
367-
- func: build_and_push_image_sonar
368-
vars:
369-
image_name: readiness-probe-init
370-
release: true
371-
372-
- name: release_agent_ubuntu
373-
commands:
374-
- func: clone
375-
- func: setup_virtualenv
376-
- func: build_and_push_image_sonar
377-
vars:
378-
image_name: agent-ubuntu
379-
release: true
380-
- func: add_supported_release
381-
vars:
382-
image_name: mongodb-agent
383-
384-
- name: release_agent_ubi
385-
commands:
386-
- func: clone
387-
- func: setup_virtualenv
388-
- func: build_and_push_image_sonar
389-
vars:
390-
image_name: agent-ubi
391-
release: true
392-
- func: add_supported_release
393-
vars:
394-
image_name: mongodb-agent
395316

396317
buildvariants:
397318
- name: e2e_tests_ubuntu
@@ -445,32 +366,3 @@ buildvariants:
445366
- name: build_agent_image_ubi
446367
- name: build_agent_image_ubuntu
447368
- name: build_readiness_probe_image
448-
449-
- name: release_blocker
450-
display_name: release_blocker
451-
run_on:
452-
- ubuntu1604-packer # Note: cheapest machine I found
453-
tasks:
454-
- name: release_blocker
455-
456-
- name: release_images_quay
457-
display_name: release_images_quay
458-
depends_on:
459-
- name: release_blocker
460-
variant: release_blocker
461-
- name: build_operator_image
462-
variant: init_test_run
463-
- name: build_prehook_image
464-
variant: init_test_run
465-
- name: build_agent_image_ubuntu
466-
variant: init_test_run
467-
- name: build_agent_image_ubi
468-
variant: init_test_run
469-
run_on:
470-
- ubuntu1804-small
471-
tasks:
472-
- name: release_operator
473-
- name: release_version_upgrade_post_start_hook
474-
- name: release_readiness_probe
475-
- name: release_agent_ubuntu
476-
- name: release_agent_ubi
File renamed without changes.
File renamed without changes.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Release Images
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted]
6+
7+
jobs:
8+
release-images:
9+
runs-on: ubuntu-latest
10+
if: startsWith(github.event.pull_request.title, 'Release MongoDB Kubernetes Operator') && github.event.review.state == 'approved'
11+
strategy:
12+
matrix:
13+
include:
14+
- pipeline-argument: operator-ubi
15+
release-key: mongodb-kubernetes-operator
16+
- pipeline-argument: version-post-start-hook-init
17+
release-key: version-upgrade-hook
18+
- pipeline-argument: readiness-probe-init
19+
release-key: readiness-probe
20+
- pipeline-argument: agent-ubi
21+
release-key: mongodb-agent
22+
- pipeline-argument: agent-ubuntu
23+
release-key: mongodb-agent
24+
steps:
25+
- name: Checkout Code
26+
uses: actions/checkout@v2
27+
- name: Setup Python
28+
uses: actions/setup-python@v2
29+
with:
30+
python-version: '3.8'
31+
architecture: 'x64'
32+
33+
- uses: actions/cache@v2
34+
with:
35+
path: ~/.cache/pip
36+
key: ${{ hashFiles('requirements.txt') }}
37+
38+
- name: Install Python Dependencies
39+
run: pip install -r requirements.txt
40+
- name: Determine if release is needed
41+
id: release_status
42+
run: |
43+
OUTPUT=$(scripts/ci/determine_required_releases.py ${{ matrix.release-key }})
44+
echo "::set-output name=OUTPUT::$OUTPUT"
45+
46+
- name: Login to Quay.io
47+
uses: docker/login-action@v1
48+
with:
49+
registry: quay.io
50+
username: ${{ secrets.QUAY_USERNAME }}
51+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
52+
53+
- name: Publish Image To Quay
54+
if: steps.release_status.outputs.OUTPUT == 'unreleased'
55+
run: python pipeline.py --image-name ${{ matrix.pipeline-argument }} --release true
56+
env:
57+
MONGODB_COMMUNITY_CONFIG: "${{ github.workspace }}/scripts/ci/config.json"
58+
59+
- name: Add Supported Release
60+
if: steps.release_status.outputs.OUTPUT == 'unreleased'
61+
run: python scripts/ci/add_supported_release.py --image-name ${{ matrix.release-key }}
62+
env:
63+
ATLAS_DATABASE: "${{ secrets.ATLAS_DATABASE }}"
64+
ATLAS_CONNECTION_STRING: "${{ secrets.ATLAS_CONNECTION_STRING }}"
65+
66+
merge-release-pr-and-draft-github-release:
67+
runs-on: ubuntu-latest
68+
needs: [release-images]
69+
steps:
70+
- name: Checkout Code
71+
uses: actions/checkout@v2
72+
- name: Determine Release Tag
73+
id: release_tag
74+
run: |
75+
OUTPUT=$(jq -r '."mongodb-kubernetes-operator"' < $GITHUB_WORKSPACE/release.json)
76+
echo "::set-output name=OUTPUT::$OUTPUT"
77+
- name: Merge Release PR
78+
uses: pascalgn/automerge-action@v0.14.2
79+
env:
80+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
81+
MERGE_LABELS: ""
82+
MERGE_DELETE_BRANCH: true
83+
MERGE_METHOD: squash
84+
MERGE_COMMIT_MESSAGE: "Release MongoDB Kubernetes Operator v${{ steps.release_tag.outputs.OUTPUT }}"
85+
- name: Create Github Release
86+
uses: ncipollo/release-action@v1
87+
with:
88+
tag: ${{ steps.release_tag.outputs.OUTPUT }}
89+
name: MongoDB Kubernetes Operator
90+
bodyFile: "${{ github.workspace }}/docs/RELEASE_NOTES.md"
91+
draft: true
92+
token: ${{ secrets.GITHUB_TOKEN }}

docs/how-to-release.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

22
## How to Release
33

4-
* Update any finished tickets in [kube-community-next](https://jira.mongodb.org/issues?jql=project%20%3D%20CLOUDP%20AND%20component%20%3D%20%22Kubernetes%20Community%22%20%20AND%20status%20in%20(Resolved%2C%20Closed)%20and%20fixVersion%3D%20kube-community-next%20%20ORDER%20BY%20resolved) to have the version of the release you're doing (kube-community-x.y)
4+
* Ensure the versions specified in [release.json](../release.json) are correct.
5+
* Prepare a PR to bump and versions as required.
56

6-
* Prepare the release PR
7-
1. Increment any image version changes.
8-
2. Create a github draft release `./scripts/dev/create_github_release.sh`.
9-
3. Commit changes.
10-
11-
* Create release PR
12-
1. Reconfigure the Evergreen run to add the relevant release task(s).
7+
* Ensure that [the release notes](./RELEASE_NOTES.md) are up to date for this release.
8+
* Review the [tickets for this release](https://jira.mongodb.org/issues?jql=project%20%3D%20CLOUDP%20AND%20component%20%20%3D%20"Kubernetes%20Community"%20%20AND%20status%20in%20(Resolved%2C%20Closed)%20AND%20fixVersion%20%3D%20kube-community-0.6.0%20) (ensure relevant fix version is in the jql query)
139

10+
* Run the `Create Release PR` GitHub Action
11+
* In the GitHub UI:
12+
* `Actions` > `Create Release PR` > `Run Workflow` (on master)
13+
14+
* Review and Approve the release PR that is created by this action.
15+
* Upon approval, all new images for this release will be built and released, and a Github release draft will be created.
1416

15-
* Unblock release task once everything is green
16-
17-
Once the images are released, merge release PR & publish github release
17+
* Review and publish the new GitHub release draft.

release.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mongodb-kubernetes-operator": "0.6.0",
2+
"mongodb-kubernetes-operator": "0.6.1",
33
"version-upgrade-hook": "1.0.2",
44
"readiness-probe": "1.0.4",
55
"mongodb-agent": {

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ tqdm==v4.49.0
99
boto3==1.16.21
1010
pymongo==3.11.4
1111
dnspython==2.0.0
12+
requests==2.24.0
1213
pyyaml==5.4.1
1314
rsa>=4.7 # not directly required, pinned by Snyk to avoid a vulnerability

scripts/ci/add_supported_release.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ def get_release() -> Dict[str, Any]:
3030

3131

3232
def get_atlas_connection_string() -> str:
33-
password = os.environ["atlas_password"]
34-
cnx_str = os.environ["atlas_connection_string"]
35-
36-
return cnx_str.format(password=password)
33+
return os.environ["ATLAS_CONNECTION_STRING"]
3734

3835

3936
def mongo_client() -> pymongo.MongoClient:
@@ -44,7 +41,7 @@ def mongo_client() -> pymongo.MongoClient:
4441
def add_release_version(image: str, version: str) -> None:
4542
client = mongo_client()
4643

47-
database = os.environ["atlas_database"]
44+
database = os.environ["ATLAS_DATABASE"]
4845
collection = client[database][image]
4946

5047
year_from_now = datetime.datetime.now() + datetime.timedelta(days=365)
@@ -72,18 +69,23 @@ def add_release_version(image: str, version: str) -> None:
7269
def main() -> int:
7370
parser = argparse.ArgumentParser()
7471
parser.add_argument(
75-
"--image", help="image to add a new supported version", type=str
72+
"--image-name", help="image to add a new supported version", type=str
7673
)
7774
args = parser.parse_args()
7875

79-
if args.image not in VALID_IMAGES:
80-
raise ValueError("Image {} not supported".format(args.image))
76+
if args.image_name not in VALID_IMAGES:
77+
print(
78+
"Image {} not supported. Not adding release version.".format(
79+
args.image_name
80+
)
81+
)
82+
return 0
8183

8284
# for now, there is just one version to add as a supported release.
83-
version = get_release()[args.image]["version"]
84-
logging.info("Adding new release: {} {}".format(args.image, version))
85+
version = get_release()[args.image_name]["version"]
86+
logging.info("Adding new release: {} {}".format(args.image_name, version))
8587

86-
add_release_version(args.image, version)
88+
add_release_version(args.image_name, version)
8789

8890
return 0
8991

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
3+
# This script accepts a key from the "release.json" file.
4+
# If the corresponding image of the specified version has been released,
5+
6+
import json
7+
import sys
8+
from typing import List, Dict
9+
10+
import requests
11+
12+
# contains a map of the quay urls to fetch data about the corresponding images.
13+
QUAY_URL_MAP = {
14+
"mongodb-agent": "https://quay.io/api/v1/repository/mongodb/mongodb-agent-ubi",
15+
"readiness-probe": "https://quay.io/api/v1/repository/mongodb/mongodb-kubernetes-readinessprobe",
16+
"version-upgrade-hook": "https://quay.io/api/v1/repository/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook",
17+
"mongodb-kubernetes-operator": "https://quay.io/api/v1/repository/mongodb/mongodb-kubernetes-operator",
18+
}
19+
20+
21+
def _get_all_released_tags(image_type: str) -> List[str]:
22+
url = QUAY_URL_MAP[image_type]
23+
resp = requests.get(url).json()
24+
tags = resp["tags"]
25+
return list(tags.keys())
26+
27+
28+
def _load_image_name_to_version_map() -> Dict:
29+
with open("release.json") as f:
30+
release = json.loads(f.read())
31+
32+
# agent section is a sub object, we change the mapping so the key corresponds to the version directly.
33+
release["mongodb-agent"] = release["mongodb-agent"]["version"]
34+
return release
35+
36+
37+
def main() -> int:
38+
if len(sys.argv) != 2:
39+
raise ValueError("usage: determine_required_releases.py [image-name]")
40+
image_name = sys.argv[1]
41+
image_name_map = _load_image_name_to_version_map()
42+
43+
if image_name not in image_name_map:
44+
raise ValueError(
45+
"Unknown image type [{}], valid values are [{}]".format(
46+
image_name, ",".join(image_name_map.keys())
47+
)
48+
)
49+
50+
if image_name not in QUAY_URL_MAP:
51+
raise ValueError("No associated image url with key [{}]".format(image_name))
52+
53+
tags = _get_all_released_tags(image_name)
54+
if image_name_map[image_name] in tags:
55+
print("released")
56+
else:
57+
print("unreleased")
58+
return 0
59+
60+
61+
if __name__ == "__main__":
62+
sys.exit(main())

scripts/ci/release_blocker

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)