Skip to content

feat: Adding Docker support #67

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 4 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM store/oracle/serverjre:8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this file is in the "docker" directory (this is awesome btw)
can you please make a change to src/test/TestRequiredFilesExist.java to fix the file path for the DockerFile?

line 10 should look like this:

    @Test public void checkDockerExists() {
        boolean dockerExists = new File("./docker/Dockerfile").exists() ||
        new File("./docker/Docker").exists();
        assertTrue(dockerExists);
    }


ENV OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json"

RUN yum install -y git

WORKDIR /root

# install Prism
ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh
RUN chmod +x ./install.sh && sync && \
./install.sh && \
rm ./install.sh

# set up default sendgrid env
WORKDIR /root/sources
RUN git clone https://github.com/sendgrid/java-http-client.git

WORKDIR /root
RUN ln -s /root/sources/java-http-client/sendgrid

COPY entrypoint.sh entrypoint.sh
RUN chmod +x entrypoint.sh

# Set entrypoint
ENTRYPOINT ["./entrypoint.sh"]
CMD ["--mock"]
37 changes: 37 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Supported tags and respective `Dockerfile` links
- `v1.0.0`, `latest` [(Dockerfile)](https://github.com/sendgrid/java-http-client/blob/master/docker/Dockerfile)

# Quick reference
Due to Oracle's JDK license, you must build this Docker image using the official Oracle image located in the Docker Store. You will need a Docker store account. Once you have an account, you must accept the Oracle license [here](https://store.docker.com/images/oracle-serverjre-8). On the command line, type `docker login` and provide your credentials. You may then build the image using this command `docker build -t sendgrid/java-http-client -f Dockerfile .`

- **Where to get help:**
[Contact SendGrid Support](https://support.sendgrid.com/hc/en-us)

- **Where to file issues:**
https://github.com/sendgrid/java-http-client/issues

- **Where to get more info:**
[USAGE.md](https://github.com/sendgrid/java-http-client/blob/master/docker/USAGE.md)

- **Maintained by:**
[SendGrid Inc.](https://sendgrid.com)

# Usage examples
- Most recent version: `docker run -it sendgrid/java-http-client`.
- Your own fork:
```sh-session
$ git clone https://github.com/you/cool-java-http-client.git
$ realpath cool-java-http-client
/path/to/cool-java-http-client
$ docker run -it -v /path/to/cool-java-http-client:/mnt/java-http-client sendgrid/java-http-client
```

For more detailed information, see [USAGE.md](https://github.com/sendgrid/java-http-client/blob/master/docker/USAGE.md).

# About

java-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).

java-http-client is maintained and funded by SendGrid, Inc. The names and logos for java-http-client are trademarks of SendGrid, Inc.

![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
35 changes: 35 additions & 0 deletions docker/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
You can use Docker to easily try out or test java-http-client.

<a name="Quickstart"></a>
# Quickstart

1. Install Docker on your machine.
2. If you have not done so, create a Docker Store account [here](https://store.docker.com/signup?next=%2F)
3. Navigate [here](https://store.docker.com/images/oracle-serverjre-8) and click the "Proceed to Checkout" link (don't worry, it's free).
4. On the command line, execute `docker login` and provide your credentials.
5. Build the Docker image using the command `docker build -t sendgrid/java-http-client -f Dockerfile .`
6. Run `docker run -it sendgrid/java-http-client`.

<a name="Info"></a>
# Info

This Docker image contains
- `java-http-client`
- Stoplight's Prism, which lets you try out the API without actually sending email

Run it in interactive mode with `-it`.

You can mount repositories in the `/mnt/java-http-client` and `/mnt/java-http-client` directories to use them instead of the default SendGrid libraries. Read on for more info.

<a name="Testing"></a>
# Testing
Testing is easy! Run the container, `cd sendgrid`, and run `./gradlew test`.

<a name="about"></a>
# About

java-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).

java-http-client is maintained and funded by SendGrid, Inc. The names and logos for java-http-client are trademarks of SendGrid, Inc.

![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
31 changes: 31 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#! /bin/bash
clear

# check for + link mounted libraries:
if [ -d /mnt/java-http-client ]
then
rm /root/sendgrid
ln -s /mnt/java-http-client/sendgrid
echo "Linked mounted java-http-client's code to /root/sendgrid"
fi

SENDGRID_JAVA_VERSION="1.0.0"
echo "Welcome to java-http-client docker v${SENDGRID_JAVA_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."

bash
2 changes: 1 addition & 1 deletion src/test/java/com/sendgrid/TestRequiredFilesExist.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TestRequiredFilesExist {

// ./Docker or docker/Docker
@Test public void checkDockerExists() {
boolean dockerExists = new File("./Docker").exists() ||
boolean dockerExists = new File("./docker/Dockerfile").exists() ||
new File("./docker/Docker").exists();
assertTrue(dockerExists);
}
Expand Down