Skip to content

Commit 92088dd

Browse files
author
SendGrid's DX Team
authored
Add docker files to test setup
Official Docker docs are very unclear about whether they support the new "public access only" option, so this is to test it. Please don't merge this branch or do anything with it.
1 parent aa8dc48 commit 92088dd

3 files changed

Lines changed: 174 additions & 0 deletions

File tree

docker/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM ubuntu:xenial
2+
ENV PYTHON_VERSIONS='python2.6 python2.7 python3.4 python3.5 python3.6' \
3+
OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json"
4+
5+
# install testing versions of python, including old versions, from deadsnakes
6+
RUN set -x \
7+
&& apt-get update \
8+
&& apt-get install -y --no-install-recommends software-properties-common \
9+
&& apt-add-repository -y ppa:fkrull/deadsnakes \
10+
&& apt-get update \
11+
&& apt-get install -y --no-install-recommends $PYTHON_VERSIONS \
12+
git \
13+
curl \
14+
&& apt-get purge -y --auto-remove software-properties-common \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
WORKDIR /root
18+
19+
# install Prism
20+
ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh
21+
RUN chmod +x ./install.sh && \
22+
./install.sh && \
23+
rm ./install.sh
24+
25+
# install pip, tox
26+
ADD https://bootstrap.pypa.io/get-pip.py get-pip.py
27+
RUN python2.7 get-pip.py && \
28+
pip install tox && \
29+
rm get-pip.py
30+
31+
# set up default sendgrid env
32+
WORKDIR /root/sources
33+
RUN git clone https://github.com/sendgrid/sendgrid-python.git && \
34+
git clone https://github.com/sendgrid/python-http-client.git
35+
WORKDIR /root
36+
RUN ln -s /root/sources/sendgrid-python/sendgrid && \
37+
ln -s /root/sources/python-http-client/python_http_client
38+
39+
COPY entrypoint.sh entrypoint.sh
40+
RUN chmod +x entrypoint.sh
41+
ENTRYPOINT ["./entrypoint.sh"]
42+
CMD ["--mock"]

docker/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
You can use Docker to easily try out or test sendgrid-python.
2+
3+
<a name="Quickstart"></a>
4+
# Quickstart
5+
6+
1. Install Docker on your machine.
7+
2. Run `docker run -it sendgrid/sendgrid-python`.
8+
9+
<a name="Info"></a>
10+
# Info
11+
12+
This Docker image contains
13+
- `sendgrid-python` and `python-http-client`
14+
- Stoplight's Prism, which lets you try out the API without actually sending email
15+
- `tox` and all supported Python versions, set up to test `sendgrid-python` or your own fork
16+
17+
Run it in interactive mode with `-it`.
18+
19+
You can mount repositories in the `/mnt/sendgrid-python` and `/mnt/python-http-client` directories to use them instead of the default SendGrid libraries. Read on for more info.
20+
21+
<a name="Options"></a>
22+
# Options
23+
24+
## Using an old version
25+
26+
The easiest way to use an old version is to use an [old tag](https://github.com/sendgrid/sendgrid-python/releases).
27+
28+
```sh-session
29+
$ docker run -it sendgrid/sendgrid-python:v3.6.1
30+
```
31+
32+
Tags from before this Docker image was created might not exist yet. You may [manually download](#Versions) [old versions](https://github.com/sendgrid/sendgrid-python/releases) in order to use them.
33+
34+
<a name="Versions"></a>
35+
## Specifying specific versions
36+
37+
To use different versions of sendgrid-python or python-http-client - for instance, to replicate your production setup - mount them with the `-v <host_dir>:<container_dir>` option. When you put either repository under `/mnt`, the container will automatically detect it and make the proper symlinks. You can edit these files from the host machine while the container is running.
38+
39+
For instance, to install sendgrid-python 3.6.1 and use the current python-http-client:
40+
41+
```sh-session
42+
$ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1
43+
$ realpath sendgrid-python
44+
/path/to/sendgrid-python
45+
$ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
46+
```
47+
48+
To install sendgrid-python v3.6.1 and use an older version of python-http-client:
49+
50+
```sh-session
51+
$ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1
52+
$ realpath sendgrid-python
53+
/path/to/sendgrid-python
54+
$ git clone https://github.com/sendgrid/python-http-client.git --branch v1.2.4
55+
$ realpath python-http-client
56+
/path/to/python-http-client
57+
$ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python \
58+
> -v /path/to/python-http-client:/mnt/python-http-client \
59+
> sendgrid/sendgrid-python
60+
```
61+
62+
## Specifying your own fork:
63+
64+
```sh-session
65+
$ git clone https://github.com/you/cool-sendgrid-python.git
66+
$ realpath cool-sendgrid-python
67+
/path/to/cool-sendgrid-python
68+
$ docker run -it -v /path/to/cool-sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
69+
```
70+
71+
Note that the paths you specify in `-v` must be absolute.
72+
73+
<a name="Testing"></a>
74+
# Testing
75+
Testing is easy! Run the container, `cd sendgrid`, and run `tox`.
76+
77+
<a name="about"></a>
78+
# About
79+
80+
sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
81+
82+
sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc.
83+
84+
![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)

docker/entrypoint.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! /bin/bash
2+
clear
3+
4+
# check for + link mounted libraries:
5+
if [ -d /mnt/sendgrid-python ]
6+
then
7+
rm /root/sendgrid
8+
ln -s /mnt/sendgrid-python/sendgrid
9+
echo "Linked mounted sendgrid-python's code to /root/sendgrid"
10+
fi
11+
if [ -d /mnt/python_http_client ]
12+
then
13+
rm /root/python_http_client
14+
ln -s /mnt/python-http-client/python_http_client
15+
echo "Linked mounted python-http-client's code to /root/python_http_client"
16+
fi
17+
18+
SENDGRID_PYTHON_VERSION=$(python2.7 -c 'import sendgrid; print(sendgrid.__version__)')
19+
echo "Welcome to sendgrid-python docker v${SENDGRID_PYTHON_VERSION}."
20+
echo
21+
22+
if [ "$1" != "--no-mock" ]
23+
then
24+
echo "Starting Prism in mock mode. Calls made to Prism will not actually send emails."
25+
echo "Disable this by running this container with --no-mock."
26+
prism run --mock --spec $OAI_SPEC_URL 2> /dev/null &
27+
else
28+
echo "Starting Prism in live (--no-mock) mode. Calls made to Prism will send emails."
29+
prism run --spec $OAI_SPEC_URL 2> /dev/null &
30+
fi
31+
echo "To use Prism, make API calls to localhost:4010. For example,"
32+
echo " sg = sendgrid.SendGridAPIClient("
33+
echo " host='http://localhost:4010/',"
34+
echo " api_key=os.environ.get('SENDGRID_API_KEY_CAMPAIGNS'))"
35+
echo "To stop Prism, run \"kill $!\" from the shell."
36+
37+
echo
38+
echo "Starting Python. Type \"import sendgrid\" to get started; return to shell with exit()."
39+
echo
40+
41+
python2.7
42+
43+
echo
44+
echo "To get back into Python, run one of the installed versions:"
45+
echo " $PYTHON_VERSIONS"
46+
echo "To test sendgrid-python, \"cd sendgrid\" and run \"tox\"."
47+
echo
48+
exec $SHELL

0 commit comments

Comments
 (0)