Skip to content

Commit 9bc8c9c

Browse files
Merge pull request #329 from gabrielkrell/master
Add Docker for easy usage
2 parents aa8dc48 + 7c56e61 commit 9bc8c9c

File tree

9 files changed

+236
-27
lines changed

9 files changed

+236
-27
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ We welcome direct contributions to the sendgrid-python code base. Thank you!
6060

6161
### Development Environment ###
6262

63+
#### Using Docker ####
64+
You can use our Docker image to avoid setting up the development environment yourself. See [USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md).
65+
6366
#### Install and Run Locally ####
6467

6568
##### Prerequisites #####

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-python.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-python)
2+
[![Docker Badge](https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg)](https://hub.docker.com/r/sendgrid/sendgrid-python/)
23
[![Email Notifications Badge](https://dx.sendgrid.com/badge/python)](https://dx.sendgrid.com/newsletter/python)
34

4-
**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/python) for releases and breaking changes.
5+
**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/python) for releases and breaking changes.
6+
     Quickly get started with [Docker](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md).
57

68
**This library allows you to quickly and easily use the SendGrid Web API v3 via Python.**
79

activate.sh

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

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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Supported tags and respective `Dockerfile` links
2+
- `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-python/blob/master/docker/Dockerfile)
3+
4+
# Quick reference
5+
- **Where to get help:**
6+
[contact SendGrid Support](https://support.sendgrid.com/hc/en-us)
7+
8+
- **Where to file issues:**
9+
https://github.com/sendgrid/sendgrid-python/issues
10+
11+
- **Where to get more info:**
12+
[USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md)
13+
14+
- **Maintained by:**
15+
[SendGrid Inc.](https://sendgrid.com)
16+
17+
# Usage examples
18+
- Most recent version: `docker run -it sendgrid/sendgrid-python`.
19+
- Old version: `docker run -it sendgrid/sendgrid-python:v4.2.0`
20+
- Old version predating this Docker image:
21+
```sh-session
22+
$ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1
23+
$ realpath sendgrid-python
24+
/path/to/sendgrid-python
25+
$ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
26+
```
27+
- Your own fork:
28+
```sh-session
29+
$ git clone https://github.com/you/cool-sendgrid-python.git
30+
$ realpath cool-sendgrid-python
31+
/path/to/cool-sendgrid-python
32+
$ docker run -it -v /path/to/cool-sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
33+
```
34+
35+
For more detailed information, see [USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md).
36+
37+
# About
38+
39+
sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]).
40+
41+
sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc.
42+
43+
![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)

docker/USAGE.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:[email protected]).
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

test/test_sendgrid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ def setUpClass(cls):
3333
"https://raw.githubusercontent.com/stoplightio/"
3434
"prism/master/install.sh"],
3535
stdout=subprocess.PIPE)
36-
subprocess.Popen(
36+
prisminstaller = subprocess.Popen(
3737
["sh"], stdin=p1.stdout, stdout=subprocess.PIPE)
38+
prisminstaller.wait()
3839
except Exception as e:
3940
print(
4041
"Error downloading the prism binary, you can try "

tox.ini

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,34 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py26, py27, py32, py33, py34, py35, py36
7+
envlist = py26, py27, py34, py35, py36
88

99
[testenv]
1010
commands = {envbindir}/python -m unittest discover -v []
11-
deps =
12-
{py26,py27,py32,py33,py34,py35,py36}-full: python_http_client
11+
deps = -rrequirements.txt
1312

1413
[testenv:py26]
1514
commands = {envbindir}/unit2 discover -v []
1615
deps = unittest2
16+
{[testenv]deps}
1717
basepython = python2.6
1818

1919
[testenv:py27]
20-
commands = {envbindir}/python -m unittest discover -v []
21-
deps =
20+
commands = {[testenv]commands}
21+
deps = {[testenv]deps}
2222
basepython = python2.7
2323

24-
[testenv:py32]
25-
commands = {envbindir}/python -m unittest discover -v []
26-
deps =
27-
basepython = python3.2
28-
29-
[testenv:py33]
30-
commands = {envbindir}/python -m unittest discover -v []
31-
deps =
32-
basepython = python3.3
33-
3424
[testenv:py34]
35-
commands = {envbindir}/python -m unittest discover -v []
36-
deps =
25+
commands = {[testenv]commands}
26+
deps = {[testenv]deps}
3727
basepython = python3.4
3828

3929
[testenv:py35]
40-
commands = {envbindir}/python -m unittest discover -v []
41-
deps = -rrequirements.txt
30+
commands = {[testenv]commands}
31+
deps = {[testenv]deps}
4232
basepython = python3.5
4333

4434
[testenv:py36]
45-
commands = {envbindir}/python -m unittest discover -v []
46-
deps = -rrequirements.txt
35+
commands = {[testenv]commands}
36+
deps = {[testenv]deps}
4737
basepython = python3.6

0 commit comments

Comments
 (0)