Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
feat: Add Dockerfile (#184)
Browse files Browse the repository at this point in the history
* feat: Add Dockerfile

* Edit readme

* Update readme

* Update port

* Add text

* add issue for header

* Update docs link
  • Loading branch information
amaury1093 authored Feb 15, 2021
1 parent 19c523f commit 9afbfe0
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
Dockerfile
22 changes: 22 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: tag

on:
push:
tags:
- "v*.*.*"

jobs:
docker-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set GITHUB_TAG env
id: vars
run: echo ::set-output name=GITHUB_TAG::${GITHUB_REF:10} # Remove /refs/head/
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: reacherhq/backend
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: "latest,${{ steps.vars.outputs.GITHUB_TAG }}"
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# From https://shaneutt.com/blog/rust-fast-small-docker-image-builds/

# ------------------------------------------------------------------------------
# Cargo Build Stage
# ------------------------------------------------------------------------------

FROM messense/rust-musl-cross:x86_64-musl as cargo-build

WORKDIR /usr/src/reacher

RUN rm -f target/x86_64-unknown-linux-musl/release/deps/reacher*

COPY . .

RUN cargo build --release --target=x86_64-unknown-linux-musl

# ------------------------------------------------------------------------------
# Final Stage
# ------------------------------------------------------------------------------

FROM alpine:latest

RUN addgroup -g 1000 reacher

RUN adduser -D -s /bin/sh -u 1000 -G reacher reacher

WORKDIR /home/reacher/bin/

COPY --from=cargo-build /usr/src/reacher/target/x86_64-unknown-linux-musl/release/heroku .

RUN chown reacher:reacher heroku

USER reacher

ENV RUST_LOG=reacher=info
ENV RCH_HTTP_HOST=0.0.0.0
ENV PORT=8080

EXPOSE 8080

CMD ["./heroku"]
53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
[![Actions Status](https://github.com/reacherhq/backend/workflows/pr/badge.svg)](https://github.com/reacherhq/backend/actions)
[![Github Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&link=https://github.com/sponsors/amaurymartiny)](https://github.com/sponsors/amaurymartiny)

<br /><br /><br />
<br /><br />

<p align="center"><img align="center" src="https://storage.googleapis.com/saasify-uploads-prod/696e287ad79f0e0352bc201b36d701849f7d55e7.svg" height="96" alt="reacher" /></p>
<h1 align="center">⚙️ Reacher Backend</h1>
<h4 align="center">Backend Server for Reacher Email Verification API: https://reacher.email.</h4>

<br /><br /><br />
<br /><br />

This repository holds the backend for [Reacher](https://reacher.email). The backend is a HTTP server with the following components:

- [`check-if-email-exists`](https://github.com/amaurymartiny/check-if-email-exists), which performs the core email verification logic,
- [`warp`](https://github.com/seanmonstar/warp) web framework.

## Documentation: https://reacher.email/docs
## Get Started

Also check the [`openapi.json`](./openapi.json) file for the OpenAPI v3 specification of the backend's API.
There are 3 ways you can run this backend.

## Get Started
### 1. One-Click Deploy to Heroku

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/reacherhq/backend)

After clicking on the button, just follow the instructions on screen.

### 2. Use Docker

The [Docker image](./Dockerfile) is hosted on Docker Hub: https://hub.docker.com/r/reacherhq/backend.

To run it, run the following command:

```bash
docker run -p 8080:8080 reacherhq/backend
```

You can then send a POST request with the following body to `http://localhost:8080/v0/check_email`:

```json
{
"to_email": "someone@gmail.com"
}
```

### 3. Run locally

If you prefer to run the server locally on your machine, just clone the repository and run:

```bash
Expand All @@ -30,14 +52,23 @@ cargo run

The server will then be listening on `http://127.0.0.1:8080`.

### Configuration

These are the environment variables used to configure the HTTP server:

| Env Var | Required? | Description | Default |
| ---------------- | --------- | --------------------------------------------------------- | ------------------ |
| `RCH_FROM_EMAIL` | No | The email to use in the `MAIL FROM:` SMTP command. | `user@example.org` |
| `RCH_HTTP_HOST` | No | The host name to bind the HTTP server to. | `127.0.0.1` |
| `PORT` | No | The port to bind the HTTP server to, populated by Heroku. | `8080` |
| `RCH_SENTRY_DSN` | No | [Sentry](https://sentry.io) DSN used for bug reports. | not defined |
| Env Var | Required? | Description | Default |
| -------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| `RCH_FROM_EMAIL` | No | The email to use in the `MAIL FROM:` SMTP command. | `user@example.org` |
| `RCH_HTTP_HOST` | No | The host name to bind the HTTP server to. | `127.0.0.1` |
| `PORT` | No | The port to bind the HTTP server to, populated by Heroku. | `8080` |
| `RCH_SENTRY_DSN` | No | [Sentry](https://sentry.io) DSN used for bug reports. | not defined |
| `RCH_SAASIFY_SECRET` | No | All requests must have a `x-saasify-proxy-secret` header set, equal to the value of `RCH_SAASIFY_SECRET`. Also see [#185](https://github.com/reacherhq/backend/issues/185). | `reacher_dev_secret` |

## REST API Documentation

See https://help.reacher.email/rest-api-documentation.

Also check the [`openapi.json`](./openapi.json) file for the OpenAPI v3 specification of the backend's API.

## Licensing

Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "Reacher backend OpenAPIv3 specification.",
"license": {
"name": "AGPL-3.0",
"url": "https://github.com/reacherhq/backend/blob/master/LICENSE"
"url": "https://github.com/reacherhq/backend/blob/master/LICENSE.md"
},
"contact": {
"name": "Reacher",
Expand Down

0 comments on commit 9afbfe0

Please sign in to comment.