Skip to content

Commit 3c76365

Browse files
committed
Add Dockerfile, readme
See gabrielkrell/sendgrid-python-docker for commit history. Dockerfile downloads python versions, Prism, tox, default (latest at build time) SendGrid libs. Maintains symlinks for easy use.
1 parent c5c86c1 commit 3c76365

3 files changed

Lines changed: 128 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:latest
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/gabrielkrell/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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
To easily install sendgrid-python, you can use Docker.
2+
3+
# Installation
4+
5+
1. Install Docker on your machine
6+
2. Pull the latest Docker image with `docker code here`
7+
3. Run it with `docker code here`.
8+
9+
# Info
10+
11+
This Docker image contains
12+
- `sendgrid-python` and `python-http-client`
13+
- Stoplight's Prism, which lets you try out the API without actually sending email
14+
- A complete setup for testing the repository or your own fork
15+
16+
# Options
17+
18+
To use a different version of sendgrid-python or python-http-client, mount it with the `-v <host_dir>:<container_dir>` option. If you put it under `/mnt`, the container will automatically detect it and make the proper symlinks under root.
19+
20+
For instance, to install v3.6.1:
21+
$ DOCKER PULL CODE HERE
22+
$ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1
23+
$ realpath sendgrid-python
24+
/foo/sendgrid-python
25+
$ DOCKER RUN CODE HERE
26+
To install your own version:
27+
$ DOCKER PULL CODE HERE
28+
$ git clone https://github.com/foo/cool-sendgrid-python.git
29+
$ realpath sendgrid-python
30+
/foo/cool-sendgrid-python
31+
$ DOCKER RUN CODE HERE
32+
33+
# Testing
34+
Testing is easy! Just `cd sendgrid` and run `tox`.

docker/entrypoint.sh

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

0 commit comments

Comments
 (0)