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

Docker #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
virtual-env
.vscode
db.sqlite
postgres_data
postgres_data
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dist/
.python-version

.mypy_cache/
env
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Stage 1 - Install Python Requirement and Response
FROM python:3.7-slim as builder

WORKDIR /src

RUN apt-get update && apt-get install -y gcc libpq-dev

RUN pip install uwsgi

COPY ./response/ /src/response/
COPY ./setup.py /src/
COPY ./README.md /src/
COPY ./MANIFEST.in /src/
COPY ./LICENSE /src/

RUN pip install .

# Stage 2 - Install/Obtain supercronic for cron
FROM python:3.7-slim as supercronic

RUN apt-get update && apt-get install -y curl

ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.11/supercronic-linux-amd64 \
SUPERCRONIC=supercronic-linux-amd64 \
SUPERCRONIC_SHA1SUM=a2e2d47078a8dafc5949491e5ea7267cc721d67c

RUN curl -fsSLO "$SUPERCRONIC_URL" \
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
&& chmod +x "$SUPERCRONIC" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

# Stage 3 - FINAL - Put the pieces together
FROM python:3.7-slim

WORKDIR /app
ENTRYPOINT ["/app/entrypoint.sh"]

RUN apt-get update && apt-get install -y wget netcat postgresql-client && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY --from=supercronic /usr/local/bin/supercronic /usr/local/bin/supercronic
COPY --from=builder /usr/local/lib/python3.7/site-packages/ /usr/local/lib/python3.7/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/

COPY ./app/ /app/
COPY ./entrypoint.sh /app/entrypoint.sh
COPY ./crontab /app/crontab

RUN mkdir -p /app/static && chown -R nobody /app/static

USER nobody
File renamed without changes.
2 changes: 1 addition & 1 deletion demo/manage.py → app/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.prod")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
10 changes: 4 additions & 6 deletions demo/demo/settings/base.py → app/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for demo project.
Django settings for response project.

Generated by 'django-admin startproject' using Django 2.2.3.

Expand All @@ -22,7 +22,6 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

Expand All @@ -47,7 +46,7 @@
"after_response",
"rest_framework",
"bootstrap4",
"response.apps.ResponseConfig",
"response.apps.ResponseConfig"
]

MIDDLEWARE = [
Expand All @@ -60,7 +59,7 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "demo.urls"
ROOT_URLCONF = "urls"

TEMPLATES = [
{
Expand All @@ -78,7 +77,7 @@
}
]

WSGI_APPLICATION = "demo.wsgi.application"
WSGI_APPLICATION = "wsgi.application"


# Database
Expand Down Expand Up @@ -125,7 +124,6 @@
STATIC_URL = "/static/"
STATIC_ROOT = "static"


# Django Rest Framework
# https://www.django-rest-framework.org/

Expand Down
2 changes: 2 additions & 0 deletions demo/demo/settings/prod.py → app/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@
INCIDENT_REPORT_CHANNEL_ID = os.getenv(
"INCIDENT_REPORT_CHANNEL_ID"
) or SLACK_CLIENT.get_channel_id(INCIDENT_REPORT_CHANNEL_NAME)

SECRET_KEY = os.getenv("SECRET_KEY")
8 changes: 5 additions & 3 deletions demo/demo/urls.py → app/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""demo URL Configuration
"""response app URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Expand All @@ -15,10 +15,12 @@
"""
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path("admin/", admin.site.urls),
path("slack/", include("response.slack.urls")),
path("core/", include("response.core.urls")),
path("", include("response.ui.urls")),
]
path("", include("response.ui.urls"))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
4 changes: 2 additions & 2 deletions demo/demo/wsgi.py → app/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
WSGI config for demo project.
WSGI config for response app project.

It exposes the WSGI callable as a module-level variable named ``application``.

Expand All @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings.dev")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.prod")

application = get_wsgi_application()
1 change: 1 addition & 0 deletions crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* * * * * wget -qO- $RESPONSE_URL/slack/cron_minute
7 changes: 0 additions & 7 deletions demo/Dockerfile.cron

This file was deleted.

14 changes: 0 additions & 14 deletions demo/Dockerfile.response

This file was deleted.

59 changes: 11 additions & 48 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
# Response Demo App
# Response

This is an example Django project using the django-incident-response package that you can use to test drive Response locally. You'll need access to be able to add and configure apps in a Slack workspace of your choosing - you can sign up for a free account, if necessary.

All commands should be run from this directory (`demo`).

---

# Quick Start

The following steps explain how to create a Slack app, run Response locally, and configure everything to develop and test locally.

Broadly speaking, this sets things up as below:
<p align="center">
<img width="600px" src="../docs/response.svg">
</p>
The easiest way to get started is with docker!

## 1. Create a Slack App

Follow [these instructions](../docs/slack_app_create.md) to create a new Slack App.

## 2. Configure the demo app
## 2. Configure Response!

The demo app is configured using environment variables in a `.env` file. Create your own:
```
Expand All @@ -34,47 +21,23 @@ and update the variables in it:
| `INCIDENT_CHANNEL_NAME` | When an incident is declared, a 'headline' post is sent to a central channel.<br /><br />The default channel is `incidents` - change `INCIDENT_CHANNEL_NAME` if you want them to be sent somewhere else (note: do not include the #). |
| `INCIDENT_BOT_NAME` | We want to invite the Bot to all Incident Channels, so need to know its ID. You can find/configure this in the App Home section of the Slack App.<br /><br />The default bot name is `incident` - change the `INCIDENT_BOT_NAME` if your app uses something different.<br /><br />⚠️ If your chosen username has ever been used on your Slack workspace, Slack will silently change the underlying username and won't show you the actual name in use anywhere. The easiest way to find the exact name you need to use is to make the API call directly [here](https://api.slack.com/methods/users.list/test), using your bot token from above, and searching the response for you APP ID, which is shown in the Basic Info page. |

## 3. Run Response

From the root of the Response directory run:

```
docker-compose up
```

This starts the following containers:

- response: the main Response app
- postgres: the DB used by the app to store incident data
- cron: a container running cron, configured to hit an endpoint in Response every minute
- ngrok: ngrok in a container, providing a public URL pointed at Response.

## 3. Start Postgres

You can tail the logs of all containers with:
```
docker-compose logs -f
```bash
docker-compose up -d db
```

Ngrok establishes a new, random, URL any time it starts. You'll need this to complete the Slack app setup, so look for an entry like this and make note of the https://abc123.ngrok.io address - this is your public URL.
## 4. Run Response

```
ngrok | The ngrok tunnel is active
ngrok | https://6bb315c8.ngrok.io ---> response:8000
```

If everything has started successfully, you should see logs that look like this:

```
response | Django version 2.1.7, using settings 'response.settings.dev'
response | Starting development server at http://0.0.0.0:8000/
response | Quit the server with CONTROL-C.
```bash
docker run -it --rm --env-file .env --ports 8000:8000 response
```

## 4. Complete the Slack App Setup
## 5. Complete the Slack App Setup

Head back to the Slack web UI and complete the configuration of your app, as [described here](../docs/slack_app_config.md).

## 5. Test it's working!
## 6. Test it's working!

In Slack, start an incident with `/incident Something's happened`. You should see a post in your incidents channel!

Expand Down
63 changes: 0 additions & 63 deletions demo/demo/settings/dev.py

This file was deleted.

Loading