-
Notifications
You must be signed in to change notification settings - Fork 724
Add Docker for easy usage #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
eb6df37
Remove unsupported versions, inherit dependencies
gabrielkrell 72382b9
Fix timing error
gabrielkrell 4ff41ec
Remove config-specific activate file
gabrielkrell c5c86c1
Inherit tox commands from default
gabrielkrell 3c76365
Add Dockerfile, readme
gabrielkrell 0266f5b
Fix formatting
gabrielkrell 41ac104
Improve README.md
gabrielkrell 8fce318
Clarify README (again)
gabrielkrell 84e36f6
Improve entrypoint.sh, tweak readme again
gabrielkrell f68dfac
Update source for prod
gabrielkrell 4711cf6
Add syntax highlighting in Readme
gabrielkrell 31fea3a
Add code review suggestions
gabrielkrell 74bffd7
Move README to USAGE, new README
gabrielkrell 720a812
Add "about" footer in readme
gabrielkrell 975d885
Add Docker badge
gabrielkrell 7c56e61
Add Docker references in contributing, main readme
gabrielkrell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| FROM ubuntu:xenial | ||
| ENV PYTHON_VERSIONS='python2.6 python2.7 python3.4 python3.5 python3.6' \ | ||
| OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json" | ||
|
|
||
| # install testing versions of python, including old versions, from deadsnakes | ||
| RUN set -x \ | ||
| && apt-get update \ | ||
| && apt-get install -y --no-install-recommends software-properties-common \ | ||
| && apt-add-repository -y ppa:fkrull/deadsnakes \ | ||
| && apt-get update \ | ||
| && apt-get install -y --no-install-recommends $PYTHON_VERSIONS \ | ||
| git \ | ||
| curl \ | ||
| && apt-get purge -y --auto-remove software-properties-common \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| WORKDIR /root | ||
|
|
||
| # install Prism | ||
| ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh | ||
| RUN chmod +x ./install.sh && \ | ||
| ./install.sh && \ | ||
| rm ./install.sh | ||
|
|
||
| # install pip, tox | ||
| ADD https://bootstrap.pypa.io/get-pip.py get-pip.py | ||
| RUN python2.7 get-pip.py && \ | ||
| pip install tox && \ | ||
| rm get-pip.py | ||
|
|
||
| # set up default sendgrid env | ||
| WORKDIR /root/sources | ||
| RUN git clone https://github.com/sendgrid/sendgrid-python.git && \ | ||
| git clone https://github.com/sendgrid/python-http-client.git | ||
| WORKDIR /root | ||
| RUN ln -s /root/sources/sendgrid-python/sendgrid && \ | ||
| ln -s /root/sources/python-http-client/python_http_client | ||
|
|
||
| COPY entrypoint.sh entrypoint.sh | ||
| RUN chmod +x entrypoint.sh | ||
| ENTRYPOINT ["./entrypoint.sh"] | ||
| CMD ["--mock"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Supported tags and respective `Dockerfile` links | ||
| - `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-python/blob/master/docker/Dockerfile) | ||
|
|
||
| # Quick reference | ||
| - **Where to get help:** | ||
| [contact SendGrid Support](https://support.sendgrid.com/hc/en-us) | ||
|
|
||
| - **Where to file issues:** | ||
| https://github.com/sendgrid/sendgrid-python/issues | ||
|
|
||
| - **Where to get more info:** | ||
| [USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md) | ||
|
|
||
| - **Maintained by:** | ||
| [SendGrid Inc.](https://sendgrid.com) | ||
|
|
||
| # Usage examples | ||
| - Most recent version: `docker run -it sendgrid/sendgrid-python`. | ||
| - Old version: `docker run -it sendgrid/sendgrid-python:v4.2.0` | ||
| - Old version predating this Docker image: | ||
| ```sh-session | ||
| $ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1 | ||
| $ realpath sendgrid-python | ||
| /path/to/sendgrid-python | ||
| $ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python | ||
| ``` | ||
| - Your own fork: | ||
| ```sh-session | ||
| $ git clone https://github.com/you/cool-sendgrid-python.git | ||
| $ realpath cool-sendgrid-python | ||
| /path/to/cool-sendgrid-python | ||
| $ docker run -it -v /path/to/cool-sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python | ||
| ``` | ||
|
|
||
| For more detailed information, see [USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md). | ||
|
|
||
| # About | ||
|
|
||
| sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]). | ||
|
|
||
| sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc. | ||
|
|
||
|  |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| You can use Docker to easily try out or test sendgrid-python. | ||
|
|
||
| <a name="Quickstart"></a> | ||
| # Quickstart | ||
|
|
||
| 1. Install Docker on your machine. | ||
| 2. Run `docker run -it sendgrid/sendgrid-python`. | ||
|
|
||
| <a name="Info"></a> | ||
| # Info | ||
|
|
||
| This Docker image contains | ||
| - `sendgrid-python` and `python-http-client` | ||
| - Stoplight's Prism, which lets you try out the API without actually sending email | ||
| - `tox` and all supported Python versions, set up to test `sendgrid-python` or your own fork | ||
|
|
||
| Run it in interactive mode with `-it`. | ||
|
|
||
| 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. | ||
|
|
||
| <a name="Options"></a> | ||
| # Options | ||
|
|
||
| ## Using an old version | ||
|
|
||
| The easiest way to use an old version is to use an [old tag](https://github.com/sendgrid/sendgrid-python/releases). | ||
|
|
||
| ```sh-session | ||
| $ docker run -it sendgrid/sendgrid-python:v3.6.1 | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| <a name="Versions"></a> | ||
| ## Specifying specific versions | ||
|
|
||
| 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. | ||
|
|
||
| For instance, to install sendgrid-python 3.6.1 and use the current python-http-client: | ||
|
|
||
| ```sh-session | ||
| $ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1 | ||
| $ realpath sendgrid-python | ||
| /path/to/sendgrid-python | ||
| $ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python | ||
| ``` | ||
|
|
||
| To install sendgrid-python v3.6.1 and use an older version of python-http-client: | ||
|
|
||
| ```sh-session | ||
| $ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1 | ||
| $ realpath sendgrid-python | ||
| /path/to/sendgrid-python | ||
| $ git clone https://github.com/sendgrid/python-http-client.git --branch v1.2.4 | ||
| $ realpath python-http-client | ||
| /path/to/python-http-client | ||
| $ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python \ | ||
| > -v /path/to/python-http-client:/mnt/python-http-client \ | ||
| > sendgrid/sendgrid-python | ||
| ``` | ||
|
|
||
| ## Specifying your own fork: | ||
|
|
||
| ```sh-session | ||
| $ git clone https://github.com/you/cool-sendgrid-python.git | ||
| $ realpath cool-sendgrid-python | ||
| /path/to/cool-sendgrid-python | ||
| $ docker run -it -v /path/to/cool-sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python | ||
| ``` | ||
|
|
||
| Note that the paths you specify in `-v` must be absolute. | ||
|
|
||
| <a name="Testing"></a> | ||
| # Testing | ||
| Testing is easy! Run the container, `cd sendgrid`, and run `tox`. | ||
|
|
||
| <a name="about"></a> | ||
| # About | ||
|
|
||
| sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]). | ||
|
|
||
| sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc. | ||
|
|
||
|  |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #! /bin/bash | ||
| clear | ||
|
|
||
| # check for + link mounted libraries: | ||
| if [ -d /mnt/sendgrid-python ] | ||
| then | ||
| rm /root/sendgrid | ||
| ln -s /mnt/sendgrid-python/sendgrid | ||
| echo "Linked mounted sendgrid-python's code to /root/sendgrid" | ||
| fi | ||
| if [ -d /mnt/python_http_client ] | ||
| then | ||
| rm /root/python_http_client | ||
| ln -s /mnt/python-http-client/python_http_client | ||
| echo "Linked mounted python-http-client's code to /root/python_http_client" | ||
| fi | ||
|
|
||
| SENDGRID_PYTHON_VERSION=$(python2.7 -c 'import sendgrid; print(sendgrid.__version__)') | ||
| echo "Welcome to sendgrid-python docker v${SENDGRID_PYTHON_VERSION}." | ||
| echo | ||
|
|
||
| if [ "$1" != "--no-mock" ] | ||
| then | ||
| echo "Starting Prism in mock mode. Calls made to Prism will not actually send emails." | ||
| echo "Disable this by running this container with --no-mock." | ||
| prism run --mock --spec $OAI_SPEC_URL 2> /dev/null & | ||
| else | ||
| echo "Starting Prism in live (--no-mock) mode. Calls made to Prism will send emails." | ||
| prism run --spec $OAI_SPEC_URL 2> /dev/null & | ||
| fi | ||
| echo "To use Prism, make API calls to localhost:4010. For example," | ||
| echo " sg = sendgrid.SendGridAPIClient(" | ||
| echo " host='http://localhost:4010/'," | ||
| echo " api_key=os.environ.get('SENDGRID_API_KEY_CAMPAIGNS'))" | ||
| echo "To stop Prism, run \"kill $!\" from the shell." | ||
|
|
||
| echo | ||
| echo "Starting Python. Type \"import sendgrid\" to get started; return to shell with exit()." | ||
| echo | ||
|
|
||
| python2.7 | ||
|
|
||
| echo | ||
| echo "To get back into Python, run one of the installed versions:" | ||
| echo " $PYTHON_VERSIONS" | ||
| echo "To test sendgrid-python, \"cd sendgrid\" and run \"tox\"." | ||
| echo | ||
| exec $SHELL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's copying to the same directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using COPY as an alternative to ADD; apparently it's best-practice. It copies
entrypoint.shfrom the directory the Dockerfile is in into/root(set withWORKDIRearlier) and runs from there later on. The final directory structure looks like this:/root entrypoint.sh sendgrid python_http_client /sources /python-http-client README.md /python_http_client ... /sendgrid-python README.md /sendgrid ...