-
Notifications
You must be signed in to change notification settings - Fork 47
Pack the serivce into docker image. #352
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
Open
duchenpaul
wants to merge
1
commit into
bepasty:master
Choose a base branch
from
duchenpaul:image_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| docker/Dockerfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Publish Docker image | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| push_to_registry: | ||
| name: Push Docker image to Docker Hub | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out the repo | ||
| uses: actions/checkout@v7 | ||
|
|
||
| - name: Log in to Docker Hub | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Extract metadata (tags, labels) for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v6 | ||
| with: | ||
| images: duchenpaul/bepasty | ||
|
|
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v7 | ||
| with: | ||
| context: . | ||
| file: ./docker/Dockerfile | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,4 @@ coverage.xml | |
| docs/build/ | ||
|
|
||
| .idea | ||
| .vscode/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| FROM python:3.14-slim AS builder | ||
|
|
||
| # hadolint ignore=DL3008 | ||
| RUN true \ | ||
| && mkdir /app \ | ||
| && apt-get update \ | ||
| && apt-get install --no-install-recommends -y git \ | ||
| && python -m venv /app/env \ | ||
| && /app/env/bin/pip install wheel gunicorn | ||
|
|
||
| COPY . /usr/local/src/bepasty | ||
| RUN /app/env/bin/pip install /usr/local/src/bepasty | ||
|
|
||
| # --- | ||
|
|
||
| FROM python:3.14-slim | ||
|
|
||
| RUN true \ | ||
| && mkdir /app \ | ||
| && adduser -u 17357 --system --home /app/data --disabled-login --disabled-password paste | ||
|
|
||
| COPY 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 | ||
| COPY docker/autoconfig.py /etc/bepasty.conf | ||
|
|
||
| # hadolint ignore=DL3066 | ||
| USER paste | ||
| CMD ["/usr/local/bin/init.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # 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 in the [bepasty quickstart configuration docs][1]. | ||
|
|
||
| * `BEPASTY_SITENAME` (**required**) | ||
| * `BEPASTY_APP_BASE_PATH` | ||
| * `BEPASTY_APP_STORAGE_FILESYSTEM_DIRECTORY` | ||
| * `BEPASTY_DEFAULT_PERMISSIONS` | ||
| * `BEPASTY_SECRET_KEY` | ||
| * `BEPASTY_MAX_ALLOWED_FILE_SIZE` | ||
| * `BEPASTY_MAX_BODY_SIZE` | ||
|
|
||
| [1]: https://bepasty-server.readthedocs.io/en/latest/quickstart.html#configuring-bepasty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import os | ||
| import sys | ||
|
|
||
|
|
||
| def error_exit(message): | ||
| print("\n\n%s" % message) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| SITENAME = os.environ.get("BEPASTY_SITENAME") | ||
| if SITENAME is None: | ||
| error_exit("Environment variable BEPASTY_SITENAME must be set.") | ||
|
|
||
| SECRET_KEY = os.environ.get("BEPASTY_SECRET_KEY") | ||
| if SECRET_KEY is None: | ||
| error_exit("Environment variable BEPASTY_SECRET_KEY must be set.") | ||
|
|
||
| APP_BASE_PATH = os.environ.get("BEPASTY_APP_BASE_PATH") | ||
|
|
||
| # Keep defaults in sync with bepasty by only setting values that are | ||
| # explicitly provided via environment variables. | ||
| storage_filesystem_directory = os.environ.get("BEPASTY_STORAGE_FILESYSTEM_DIRECTORY") | ||
| if storage_filesystem_directory is not None: | ||
| STORAGE_FILESYSTEM_DIRECTORY = storage_filesystem_directory | ||
|
|
||
| default_permissions = os.environ.get("BEPASTY_DEFAULT_PERMISSIONS") | ||
| if default_permissions is not None: | ||
| DEFAULT_PERMISSIONS = default_permissions | ||
|
|
||
| max_allowed_file_size = os.environ.get("BEPASTY_MAX_ALLOWED_FILE_SIZE") | ||
| if max_allowed_file_size is not None: | ||
| try: | ||
| MAX_ALLOWED_FILE_SIZE = int(max_allowed_file_size) | ||
| except ValueError as err: | ||
| error_exit("Invalid BEPASTY_MAX_ALLOWED_FILE_SIZE: %s" % str(err)) | ||
|
|
||
| max_body_size = os.environ.get("BEPASTY_MAX_BODY_SIZE") | ||
| if max_body_size is not None: | ||
| try: | ||
| MAX_BODY_SIZE = int(max_body_size) | ||
| except ValueError as err: | ||
| error_exit("Invalid BEPASTY_MAX_BODY_SIZE: %s" % str(err)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| command: | ||
| app-import: | ||
| exec: /app/env/bin/python -c "import bepasty.app; print('bepasty import ok')" | ||
| exit-status: 0 | ||
| stdout: | ||
| - /bepasty import ok/ | ||
|
|
||
| http: | ||
| http://127.0.0.1:8000/: | ||
| status: 200 | ||
| timeout: 10000 | ||
|
duchenpaul marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.