Skip to content

Commit

Permalink
provide a docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
foosinn committed Jan 8, 2021
1 parent f4f8d97 commit 528c9bf
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker/Dockerfile
30 changes: 30 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.9-slim AS builder

RUN true \
&& mkdir /app \
&& apt update \
&& apt install --no-install-recommends -y git \
&& python -m venv /app/env \
&& /app/env/bin/pip install wheel gunicorn

ADD . /usr/local/src/bepasty
RUN /app/env/bin/pip install /usr/local/src/bepasty

# ---

FROM python:3.9-slim

RUN true \
&& mkdir /app \
&& adduser -u 17357 --system --home /app/data --disabled-login --disabled-password paste

ADD docker/init.sh /usr/local/bin/init.sh
COPY --from=builder /app/env /app/env

ENV WORKERS 4
ENV LISTEN 0.0.0.0:8000
ENV BEPASTY_CONFIG /etc/bepasty.conf
ADD docker/autoconfig.py /etc/bepasty.conf

USER paste
CMD /usr/local/bin/init.sh
53 changes: 53 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# bepasty Docker image

A Docker image that provides very basic configuration via environment variables.

**Notes**

* For a more advanced configuration mount a custom configuration to
`/etc/bepasty.conf`.
* All data will be owned by UID 117356, to change this you can use the
`--user <uid>` option from `docker run`.

## Quickstart

```sh
# build from the repository root
docker build -f docker/Dockerfile -t bepasty .

# create datadir
mkdir data
sudo chown 17357:0 data

# run
docker run -it \
-p 8000:8000 \
-v $PWD/data:/app/data \
-e BEPASTY_SECRET_KEY=$(openssl rand -hex 16) \
-e BEPASTY_SITENAME=localhost \
bepasty

# visit http://localhost:8000
```

## Docker image environment variables

* `WORKERS`: Number of Gunicorn workers (default: `4`)
* `LISTEN`: IP and address to listen on (default: `0.0.0.0:8000`)
* `BEPASTY_CONFIG`: Path to bepasty configuration (default: `/etc/bepasty.conf`)

## Bepasty environment variables

These match the bepasty options described [here][1]

* `BEPASTY_SITENAME` (**required**)
* `BEPASTY_APP_BASE_PATH`
* `BEPASTY_APP_STORAGE_FILESYSTEM_DIRECTORY`
* `BEPASTY_DEFAULT_PERMISSIONS`
* `BEPASTY_ADMIN_SECRET`
* `BEPASTY_SECRET_KEY`
* `BEPASTY_MAX_ALLOWED_FILE_SIZE`
* `BEPASTY_MAX_BODY_SIZE`

[1]: https://bepasty-server.readthedocs.io/en/latest/quickstart.html#configuring-bepasty

41 changes: 41 additions & 0 deletions docker/autoconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/python

import os
import sys

SITENAME = os.environ.get("BEPASTY_SITENAME", None)
if SITENAME is None:
print("\n\nEnvironment variable BEPASTY_SITENAME must be set.")
sys.exit(1)

SECRET_KEY = os.environ.get("BEPASTY_SECRET_KEY", None)
if SECRET_KEY is None:
print("\n\nEnvironment variable BEPASTY_SECRET_KEY must be set.")
sys.exit(1)

APP_BASE_PATH = os.environ.get("BEPASTY_APP_BASE_PATH", None)

STORAGE_FILESYSTEM_DIRECTORY = os.environ.get(
"BEPASTY_STORAGE_FILESYSTEM_DIRECTORY", "/app/data",
)

DEFAULT_PERMISSIONS = os.environ.get("BEPASTY_DEFAULT_PERMISSIONS", "create,read")

PERMISSIONS = {}
admin_secret = os.environ.get("BEPASTY_ADMIN_SECRET", None)
if admin_secret is not None:
PERMISSIONS.update({admin_secret: "admin,list,create,modify,read,delete"})

try:
max_allowed_file_size = os.environ.get("BEPASTY_MAX_ALLOWED_FILE_SIZE", 5000000000)
MAX_ALLOWED_FILE_SIZE = int(max_allowed_file_size)
except ValueError as err:
print("\n\nInvalid BEPASTY_MAX_ALLOWED_FILE_SIZE: %s", str(err))
sys.exit(1)

try:
max_body_size = os.environ.get("BEPASTY_MAX_BODY_SIZE", 1040384)
MAX_BODY_SIZE = int(max_body_size)
except ValueError as err:
print("\n\nInvalid BEPASTY_MAX_BODY_SIZE: %s", str(err))
sys.exit(1)
12 changes: 12 additions & 0 deletions docker/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

if [ ! -f "$BEPASTY_CONFIG" ]; then
echo "Please please mount a configuration file to '$BEPASTY_CONFIG'."
exit 1
fi

if ! python "$BEPASTY_CONFIG"; then
exit 1
fi

exec /app/env/bin/gunicorn -b "$LISTEN" --workers="$WORKERS" bepasty.wsgi:application

0 comments on commit 528c9bf

Please sign in to comment.