8000 Updates to run on Cabotage · python/webhook-mailer@68366ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 68366ba

Browse files
committed
Updates to run on Cabotage
Moving from Heroku, we'll update this to run on cabotage. - Build a dockerfile - Enable CI via GitHub Actions - Fix a test - Add a health check endpoint
1 parent 0f42205 commit 68366ba

File tree

14 files changed

+169
-48
lines changed

14 files changed

+169
-48
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
permissions:
8+
contents: read
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out repository
14+
uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version-file: 'python-version'
18+
- name: Install Python dependencies
19+
run: |
20+
pip install -U setuptools wheel pip
21+
pip install -r requirements/main.txt
22+
pip install -r requirements/dev.txt
23+
pip check
24+
- name: Run Tests
25+
run: |
26+
pytest

Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM python:3.7.17-slim-bookworm
2+
3+
# We create an /opt directory with a virtual environment in it to store our
4+
# application in.
5+
RUN set -x \
6+
&& python3 -m venv /opt/mailer
7+
8+
# Now that we've created our virtual environment, we'll go ahead and update
9+
# our $PATH to refer to it first.
10+
ENV PATH="/opt/mailer/bin:${PATH}"
11+
WORKDIR /opt/mailer/src/
12+
13+
# Define whether we're building a production or a development image. This will
14+
# generally be used to control whether or not we install our development and
15+
# test dependencies.
16+
ARG DEVEL=no
17+
18+
# Next, we want to update pip, setuptools, and wheel inside of this virtual
19+
# environment to ensure that we have the latest versions of them.
20+
# TODO: We use --require-hashes in our requirements files, but not here, making
21+
# the ones in the requirements files kind of a moot point. We should
22+
# probably pin these too, and update them as we do anything else.
23+
RUN pip --no-cache-dir --disable-pip-version-check install --upgrade pip setuptools wheel
24+
25+
# We copy this into the docker container prior to copying in the rest of our
26+
# application so that we can skip installing requirements if the only thing
27+
# that has changed is the Warehouse code itself.
28+
COPY requirements /tmp/requirements
29+
30+
# Install our development dependencies if we're building a development install
31+
# otherwise this will do nothing.
32+
RUN --mount=type=cache,target=/root/.cache/pip \
33+
set -x \
34+
&& if [ "$DEVEL" = "yes" ]; then pip --disable-pip-version-check install -r /tmp/requirements/dev.txt; fi
35+
36+
# Install the Python level Warehouse requirements, this is done after copying
37+
# the requirements but prior to copying Warehouse itself into the container so
38+
# that code changes don't require triggering an entire install of all of
39+
# Warehouse's dependencies.
40+
RUN --mount=type=cache,target=/root/.cache/pip \
41+
set -x \
42+
&& pip --disable-pip-version-check \
43+
install --no-deps \
44+
-r /tmp/requirements/main.txt \
45+
&& pip check \
46+
&& find /opt/mailer -name '*.pyc' -delete
47+
48+
COPY . /opt/mailer/src/

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: python3 -m mailer
1+
web: python -m mailer

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ A webhook to send every [CPython][cpython] commit to
55

66
## Requirements
77

8-
* CPython 3.6
8+
* CPython 3.7
99
* aiohttp
1010
* aiosmtplib
1111

12-
See [requirements.txt](requirements.txt) for details.
12+
See [requirements](requirements) for details.
1313

1414

1515
## Configuration

dev-requirements.txt

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

mailer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
SMTP_USERNAME = os.environ.get('SMTP_USERNAME')
2222
SMTP_PASSWORD = os.environ.get('SMTP_PASSWORD')
2323
PORT = int(os.environ.get('PORT', 8585))
24+
UNIX_SOCKET = os.environ.get('UNIX_SOCKET', None)
2425

2526

2627
class ResponseExit(Exception):
@@ -134,6 +135,8 @@ async def handler(request):
134135
return aiohttp.web.Response(status=http.HTTPStatus.INTERNAL_SERVER_ERROR)
135136
return handler
136137

138+
async def health(request):
139+
return aiohttp.web.Response(status=200)
137140

138141
def application(loop):
139142
app = aiohttp.web.Application(loop=loop)
@@ -142,10 +145,11 @@ def application(loop):
142145
# TODO: remove use_tls=False if we won't use starttls
143146
lambda: aiosmtplib.SMTP(hostname=SMTP_HOSTNAME, port=SMTP_PORT, loop=loop, use_tls=False),
144147
))
148+
app.router.add_route("GET", "/_health", health)
145149
return app
146150

147151

148152
if __name__ == '__main__':
149153
loop = asyncio.get_event_loop()
150154
app = application(loop)
151-
aiohttp.web.run_app(app, port=PORT)
155+
aiohttp.web.run_app(app, port=PORT, path=UNIX_SOCKET)

python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.7.17

requirements.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
-r requirements.in
1+
-r main.in
22
pytest
33
pytest-aiohttp

requirements/dev.txt

Lines changed: 58 additions & 0 deletions
F987
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.7
3+
# by the following command:
4+
#
5+
# pip-compile requirements/dev.in
6+
#
7+
aiohttp==2.3.10
8+
# via
9+
# -r requirements/main.in
10+
# pytest-aiohttp
11+
aiosmtplib==1.0.6
12+
# via -r requirements/main.in
13+
async-timeout==3.0.1
14+
# via aiohttp
15+
atomicwrites==1.3.0
16+
# via pytest
17+
attrs==19.1.0
18+
# via pytest
19+
chardet==3.0.4
20+
# via aiohttp
21+
idna==2.8
22+
# via
23+
# idna-ssl
24+
# yarl
25+
idna-ssl==1.1.0
26+
# via aiohttp
27+
importlib-metadata==0.18
28+
# via
29+
# pluggy
30+
# pytest
31+
more-itertools==7.1.0
32+
# via pytest
33+
multidict==4.5.2
34+
# via
35+
# aiohttp
36+
# yarl
37+
packaging==19.0
38+
# via pytest
39+
pluggy==0.12.0
40+
# via pytest
41+
py==1.8.0
42+
# via pytest
43+
pyparsing==2.4.0
44+
# via packaging
45+
pytest==5.0.1
46+
# via
47+
# -r requirements/dev.in
48+
# pytest-aiohttp
49+
pytest-aiohttp==0.3.0
50+
# via -r requirements/dev.in
51+
six==1.12.0
52+
# via packaging
53+
wcwidth==0.1.7
54+
# via pytest
55+
yarl==1.3.0
56+
# via aiohttp
57+
zipp==0.5.2
58+
# via importlib-metadata
File renamed without changes.

requirements/main.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.7
3+
# by the following command:
4+
#
5+
# pip-compile requirements/main.in
6+
#
7+
aiohttp==2.3.10
8+
# via -r requirements/main.in
9+
aiosmtplib==1.0.0
10+
# via -r requirements/main.in
11+
async-timeout==3.0.1
12+
# via aiohttp
13+
chardet==3.0.4
14+
# via aiohttp
15+
idna==2.8
16+
# via
17+
# idna-ssl
18+
# yarl
19+
idna-ssl==1.1.0
20+
# via aiohttp
21+
multidict==4.5.2
22+
# via
23+
# aiohttp
24+
# yarl
25+
yarl==1.3.0
26+
# via aiohttp

runtime.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

test_mailer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
diff = """\
1616
diff --git a/.gitignore b/.gitignore
17-
index c2b4fc703f7..e0d0685fa7d 100644
17+
index c2b4fc703f7c..e0d0685fa7da 100644
1818
--- a/.gitignore
1919
+++ b/.gitignore
2020
@@ -93,3 +93,4 @@ htmlcov/

0 commit comments

Comments
 (0)
0