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 Image #262

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
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.11-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.11-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 17357, 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