Skip to content

Commit f651376

Browse files
authored
add ol-concourse common components (#1894)
* add ol-concourse to requirements * add common ol-concourse based classes for pipeline definitions * fmt * isort * remove unused import * add tests for add_error_handling and error if the Step object passed in does not extend StepModifierMixin * Change add_error_handling type hint for step to StepModifierMixin * remove unused `Step` class * throw an error if add_error_handling is called with a value already set on on_failure, on_error or on_abort * remove dev check from adding slack alert * fix failure description for aborts * make ClearCdnCacheStep a TaskStepWithErrorHandling
1 parent 4cc3f88 commit f651376

File tree

11 files changed

+521
-0
lines changed

11 files changed

+521
-0
lines changed

content_sync/pipelines/definitions/__init__.py

Whitespace-only changes.

content_sync/pipelines/definitions/concourse/__init__.py

Whitespace-only changes.

content_sync/pipelines/definitions/concourse/common/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from ol_concourse.lib.models.pipeline import Identifier
2+
3+
4+
# Commonly used identifiers
5+
HTTP_RESOURCE_TYPE_IDENTIFIER = Identifier("http-resource")
6+
KEYVAL_RESOURCE_TYPE_IDENTIFIER = Identifier("keyval")
7+
S3_IAM_RESOURCE_TYPE_IDENTIFIER = Identifier("s3-resource-iam")
8+
OCW_STUDIO_WEBHOOK_RESOURCE_TYPE_IDENTIFIER = Identifier("ocw-studio-webhook")
9+
SLACK_ALERT_RESOURCE_IDENTIFIER = Identifier("slack-alert")
10+
OPEN_DISCUSSIONS_RESOURCE_IDENTIFIER = Identifier("open-discussions-webhook")
11+
WEBPACK_MANIFEST_S3_IDENTIFIER = Identifier("webpack-manifest-s3")
12+
WEBPACK_ARTIFACTS_IDENTIFIER = Identifier("webpack-artifacts")
13+
OCW_HUGO_THEMES_GIT_IDENTIFIER = Identifier("ocw-hugo-themes-git")
14+
OCW_HUGO_PROJECTS_GIT_IDENTIFIER = Identifier("ocw-hugo-projects-git")
15+
SITE_CONTENT_GIT_IDENTIFIER = Identifier("site-content-git")
16+
STATIC_RESOURCES_S3_IDENTIFIER = Identifier("static-resources-s3")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from ol_concourse.lib.constants import REGISTRY_IMAGE
2+
from ol_concourse.lib.models.pipeline import AnonymousResource, RegistryImage
3+
4+
5+
"""
6+
Docker image for building OCW sites
7+
8+
https://github.com/mitodl/ol-infrastructure/tree/main/dockerfiles/ocw/node-hugo
9+
"""
10+
OCW_COURSE_PUBLISHER_REGISTRY_IMAGE = AnonymousResource(
11+
type=REGISTRY_IMAGE,
12+
source=RegistryImage(repository="mitodl/ocw-course-publisher", tag="0.6"),
13+
)
14+
15+
AWS_CLI_REGISTRY_IMAGE = AnonymousResource(
16+
type=REGISTRY_IMAGE, source=RegistryImage(repository="amazon/aws-cli", tag="latest")
17+
)
18+
19+
CURL_REGISTRY_IMAGE = AnonymousResource(
20+
type=REGISTRY_IMAGE, source=RegistryImage(repository="curlimages/curl")
21+
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from ol_concourse.lib.constants import REGISTRY_IMAGE
2+
from ol_concourse.lib.models.pipeline import ResourceType
3+
4+
from content_sync.pipelines.definitions.concourse.common.identifiers import (
5+
HTTP_RESOURCE_TYPE_IDENTIFIER,
6+
KEYVAL_RESOURCE_TYPE_IDENTIFIER,
7+
S3_IAM_RESOURCE_TYPE_IDENTIFIER,
8+
)
9+
10+
11+
class HttpResourceType(ResourceType):
12+
"""
13+
A Resource for making HTTP requests
14+
"""
15+
16+
def __init__(self, **kwargs):
17+
super().__init__(
18+
name=HTTP_RESOURCE_TYPE_IDENTIFIER,
19+
type=REGISTRY_IMAGE,
20+
source={"repository": "jgriff/http-resource", "tag": "latest"},
21+
**kwargs
22+
)
23+
24+
25+
class KeyvalResourceType(ResourceType):
26+
"""
27+
A resource for storing and recalling simple key / value pairs
28+
"""
29+
30+
def __init__(self, **kwargs):
31+
super().__init__(
32+
name=KEYVAL_RESOURCE_TYPE_IDENTIFIER,
33+
type=REGISTRY_IMAGE,
34+
source={
35+
"repository": "ghcr.io/cludden/concourse-keyval-resource",
36+
"tag": "latest",
37+
},
38+
**kwargs
39+
)
40+
41+
42+
class S3IamResourceType(ResourceType):
43+
"""
44+
A resource for interacting with S3-compatible storage services that supports instance profiles
45+
"""
46+
47+
def __init__(self, **kwargs):
48+
super().__init__(
49+
name=S3_IAM_RESOURCE_TYPE_IDENTIFIER,
50+
type=REGISTRY_IMAGE,
51+
source={"repository": "governmentpaas/s3-resource", "tag": "latest"},
52+
**kwargs
53+
)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from django.conf import settings
2+
from ol_concourse.lib.models.pipeline import Identifier, Resource
3+
from ol_concourse.lib.resource_types import slack_notification_resource
4+
5+
from content_sync.pipelines.definitions.concourse.common.identifiers import (
6+
HTTP_RESOURCE_TYPE_IDENTIFIER,
7+
OCW_STUDIO_WEBHOOK_RESOURCE_TYPE_IDENTIFIER,
8+
OPEN_DISCUSSIONS_RESOURCE_IDENTIFIER,
9+
SLACK_ALERT_RESOURCE_IDENTIFIER,
10+
)
11+
12+
13+
class SlackAlertResource(Resource):
14+
"""
15+
A Resource using the version of concourse-slack-notification specified by ol-concourse
16+
17+
It sends messages to a Slack channel
18+
"""
19+
20+
def __init__(self, **kwargs):
21+
super().__init__(
22+
name=SLACK_ALERT_RESOURCE_IDENTIFIER,
23+
icon="slack",
24+
type=slack_notification_resource().name,
25+
check_every="never",
26+
source={"url": "((slack-url))", "disabled": "false"},
27+
**kwargs,
28+
)
29+
30+
31+
class OpenDiscussionsResource(Resource):
32+
"""
33+
A Resource that uses the http-resource ResourceType to trigger API calls to open-discussions
34+
"""
35+
36+
def __init__(self, **kwargs):
37+
super().__init__(
38+
name=OPEN_DISCUSSIONS_RESOURCE_IDENTIFIER,
39+
icon="cloud-search",
40+
type=HTTP_RESOURCE_TYPE_IDENTIFIER,
41+
check_every="never",
42+
source={
43+
"url": f"{settings.OPEN_DISCUSSIONS_URL}/api/v0/ocw_next_webhook/",
44+
"method": "POST",
45+
"out_only": True,
46+
"headers": {
47+
"Content-Type": "application/json",
48+
},
49+
},
50+
**kwargs,
51+
)
52+
53+
54+
class GitResource(Resource):
55+
"""
56+
A Resource for interacting with git repositories
57+
"""
58+
59+
def __init__(self, name: Identifier, uri: str, branch: str, **kwagrs):
60+
super().__init__(
61+
name=name,
62+
icon="git",
63+
type="git",
64+
source={"uri": uri, "branch": branch},
65+
**kwagrs,
66+
)
67+
68+
69+
class OcwStudioWebhookResource(Resource):
70+
"""
71+
A Resource for making API calls ocw-studio to set a Website's status
72+
73+
args:
74+
ocw_studio_url(str): The URL to the instance of ocw-studio to POST to
75+
site_name(str): The name of the site the status is in reference to
76+
api_token(str): The ocw-studio API token
77+
"""
78+
79+
def __init__(self, ocw_studio_url: str, site_name: str, api_token: str, **kwargs):
80+
super().__init__(
81+
name=OCW_STUDIO_WEBHOOK_RESOURCE_TYPE_IDENTIFIER,
82+
icon="language-python",
83+
type=HTTP_RESOURCE_TYPE_IDENTIFIER,
84+
check_every="never",
85+
source={
86+
"url": f"{ocw_studio_url}/api/websites/{site_name}/pipeline_status/",
87+
"method": "POST",
88+
"out_only": True,
89+
"headers": {
90+
"Content-Type": "application/json",
91+
"Authorization": f"Bearer {api_token}",
92+
},
93+
},
94+
**kwargs,
95+
)

0 commit comments

Comments
 (0)