Skip to content
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

Initial dockerfile #557

Merged
merged 3 commits into from
Oct 31, 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
34 changes: 34 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM microsoft/dotnet:1.0-sdk

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

# Clone sources
WORKDIR /root/sources
RUN git clone https://github.com/sendgrid/sendgrid-csharp.git

# Set up symlink
RUN ln -s /root/sources/sendgrid-csharp /root/sendgrid-csharp
WORKDIR /root/sendgrid-csharp

# Restore packages
RUN dotnet restore

# Set up prism
ENV OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json"
RUN mkdir prism/bin && ./prism/prism.sh
ENV PATH="${PATH}:$PWD/prism/bin/"

# Hack to prevent tests from attempting to start (windows) prism
ENV TRAVIS="true"

# Start prism with the container
COPY entrypoint.sh entrypoint.sh
RUN chmod +x entrypoint.sh

# Set entrypoint
ENTRYPOINT ["./entrypoint.sh"]
CMD ["--mock"]
31 changes: 31 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
You can use Docker to easily try out or test sendgrid-csharp.

# Quickstart

1. Install Docker on your machine.
2. Build the latest container with `docker build -t sendgrid/sendgrid-csharp docker`
3. Run `docker run -it sendgrid/sendgrid-csharp`.

# Info

This Docker image contains
- `sendgrid-csharp`
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's what I tried:

$ git pull https://github.com/FireEater64/sendgrid-csharp.git initial-dockerfile
$ git remote add upstream https://github.com/sendgrid/sendgrid-csharp.git
$ git merge upstream master
$ git fetch
$ docker run -it -v /Users/mbernier/Sites/branches/FireEater64:/mnt/sendgrid-csharp sendgrid/sendgrid-csharp

The error I got:

Unable to find image 'sendgrid/sendgrid-csharp:latest' locally
docker: Error response from daemon: pull access denied for sendgrid/sendgrid-csharp, repository does not exist or may require 'docker login'.

I also tried:

$ docker run -it sendgrid/sendgrid-csharp

and got a similar error:

Unable to find image 'sendgrid/sendgrid-csharp:latest' locally
docker: Error response from daemon: pull access denied for sendgrid/sendgrid-csharp, repository does not exist or may require 'docker login'

Do you know what I did incorrectly?

Copy link
Contributor

Choose a reason for hiding this comment

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

@FireEater64 Can you please give this a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @mbernier - I wrote these instructions under the assumption that someone @sendgrid would build and push this container to the docker hub. Since I'm not a member of the sendgrid org, I can't do it myself, at least not under that name.

I can rework the instructions if you'd like - but to build the container yourself, just check out the branch and run docker build -t sendgrid/sendgrid-csharp . Then the instructions you mentioned above should work 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, gotcha! Yes, we will eventually get this into docker hub. Until then, we want to make sure that people can run it from the library.

When we add it to docker hub we will update the docs accordingly!!
Can you please make the suggested change? Then we will get this merged.

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course - should be done 👍

- Stoplight's Prism, which lets you try out the API without actually sending email

Run it in interactive mode with `-it`.

You can mount a repository in the `/mnt/sendgrid-csharp` directory to use it instead of the default SendGrid library.

# Testing
Testing is easy! Run the container, then `dotnet test ./tests/SendGrid.Tests/SendGrid.Tests.csproj -c Release -f netcoreapp1.0`

# Usage examples

- Most recent version: docker run -it sendgrid/sendgrid-csharp.
- Your own fork:
```sh-session
$ git clone https://github.com/you/cool-sendgrid-csharp.git
$ realpath cool-sendgrid-csharp
/path/to/cool-sendgrid-csharp
$ docker run -it -v /path/to/cool-sendgrid-csharp:/mnt/sendgrid-csharp sendgrid/sendgrid-csharp
```
29 changes: 29 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /bin/bash

# check for + link mounted libraries:
if [ -d /mnt/sendgrid-csharp ]
then
rm /root/sendgrid-csharp
ln -s /mnt/sendgrid-csharp /root/sendgrid-csharp
echo "Linked mounted sendgrid-csharp"
fi

echo "Welcome to sendgrid-csharp docker."
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 " var sg = new SendGridClient(Environment.GetEnvironmentVariable('SENDGRID_API_KEY_CAMPAIGNS'),
'http://localhost:4010')"
echo "To stop Prism, run \"kill $!\" from the shell."

cd /root/sendgrid-csharp
exec $SHELL