Move example files to extras directory
This commit is contained in:
8
extras/.env.example
Normal file
8
extras/.env.example
Normal file
@ -0,0 +1,8 @@
|
||||
# Domain where we server files from, not where we upload files to
|
||||
DOMAIN=https://i.example.com/
|
||||
|
||||
# Path to the directory where we store files
|
||||
UPLOAD_FOLDER=/Uploads
|
||||
|
||||
# Discord Webhook URL
|
||||
WEBHOOK_URL=https://discordapp.com/api/webhooks/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
|
65
extras/Dockerfile
Normal file
65
extras/Dockerfile
Normal file
@ -0,0 +1,65 @@
|
||||
# We need gcc, build-essential and git to install our requirements but we
|
||||
# don't need them when run the application so we can selectively copy artifacts
|
||||
# from this stage (compile-image) to second one (runtime-image), leaving
|
||||
# behind everything we don't need in the final build.
|
||||
FROM python:3.9-slim as requirements-stage
|
||||
|
||||
WORKDIR /tmp
|
||||
|
||||
RUN pip install poetry
|
||||
|
||||
COPY ./pyproject.toml ./poetry.lock /tmp/
|
||||
|
||||
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
|
||||
|
||||
FROM python:3.9-slim
|
||||
|
||||
# TODO: Remove this
|
||||
# We don't want apt-get to interact with us,
|
||||
# and we want the default answers to be used for all questions.
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Update packages and install needed packages to build our requirements.
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends build-essential ffmpeg
|
||||
|
||||
# Create user so we don't run as root.
|
||||
RUN useradd --create-home botuser
|
||||
|
||||
# Change ownership of directories
|
||||
RUN chown -R botuser:botuser /home/botuser && chmod -R 755 /home/botuser
|
||||
|
||||
# Change user
|
||||
USER botuser
|
||||
|
||||
# Change directory to where we will run the application.
|
||||
WORKDIR /home/botuser
|
||||
|
||||
ENV PATH "$PATH:/home/botuser/.local/bin"
|
||||
|
||||
# Copy our Python application to our home directory.
|
||||
COPY --from=requirements-stage /tmp/requirements.txt /home/botuser/requirements.txt
|
||||
|
||||
RUN pip install --no-cache-dir --upgrade -r /home/botuser/requirements.txt
|
||||
|
||||
COPY main.py ./
|
||||
|
||||
# Don't generate byte code (.pyc-files).
|
||||
# These are only needed if we run the python-files several times.
|
||||
# Docker doesn't keep the data between runs so this adds nothing.
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
|
||||
# Force the stdout and stderr streams to be unbuffered.
|
||||
# Will allow log messages to be immediately dumped instead of being buffered.
|
||||
# This is useful when the application crashes before writing messages stuck in the buffer.
|
||||
# Has a minor performance loss. We don't have many log messages so probably makes zero difference.
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
# Use our virtual environment that we created in the other stage.
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
# Expose the web port
|
||||
EXPOSE 5000
|
||||
|
||||
# Run bot.
|
||||
CMD ["uvicorn", "main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "5000"]
|
17
extras/discord-embed.service
Normal file
17
extras/discord-embed.service
Normal file
@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=discord-embed
|
||||
Requires=discord-embed.socket
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
# Change lovinator to your username
|
||||
User=lovinator
|
||||
Group=lovinator
|
||||
ExecStart=/home/lovinator/.local/bin/poetry run gunicorn --workers=3 --threads=3 -k uvicorn.workers.UvicornWorker --bind unix:/run/discord-embed.sock --access-logfile /var/log/discord-embed/access.log --error-logfile /var/log/discord-embed/error.log main:app
|
||||
WorkingDirectory=/home/lovinator/discord-embed
|
||||
Environment="DOMAIN=https://i.lovinator.space/"
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
11
extras/discord-embed.socket
Normal file
11
extras/discord-embed.socket
Normal file
@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Socket that Nginx will use to communicate with Gunicorn.
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/discord-embed.sock
|
||||
|
||||
# Change this to the user that runs nginx. On Arch it is http, on others it is www-data. You can check with "ps aux | grep nginx"
|
||||
SocketUser=http
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
16
extras/docker-compose.yml
Normal file
16
extras/docker-compose.yml
Normal file
@ -0,0 +1,16 @@
|
||||
version: "3"
|
||||
services:
|
||||
discord-nice-embed-maker-for-my-yoy:
|
||||
image: thelovinator/discord-nice-embed-maker-for-my-yoy
|
||||
container_name: discord-nice-embed-maker-for-my-yoy
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- DOMAIN=${DOMAIN}
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- uploads:/home/botuser/Uploads
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
uploads:
|
98
extras/nginx.conf
Normal file
98
extras/nginx.conf
Normal file
@ -0,0 +1,98 @@
|
||||
worker_processes auto;
|
||||
events {
|
||||
multi_accept on;
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
charset utf-8;
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
types_hash_max_size 4096;
|
||||
types_hash_bucket_size 64;
|
||||
server_tokens off;
|
||||
client_max_body_size 0M;
|
||||
set_real_ip_from 192.168.1.31;
|
||||
|
||||
# MIME
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Log Format
|
||||
log_format cloudflare '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $http_cf_ray $http_cf_connecting_ip $http_x_forwarded_for $http_x_forwarded_proto $http_true_client_ip $http_cf_ipcountry $http_cf_visitor $http_cdn_loop';
|
||||
|
||||
# Logging
|
||||
access_log /var/log/nginx/access.log cloudflare;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
|
||||
# Load configs
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
# This is the URL where we will upload images to
|
||||
server_name upload.lovinator.space;
|
||||
root /usr/share/nginx/html;
|
||||
# discord-embed needs to be running before we can use it
|
||||
location / {
|
||||
proxy_pass http://unix:/run/discord-embed.sock;
|
||||
}
|
||||
|
||||
# logging
|
||||
access_log /var/log/nginx/lovinator.space.access.log cloudflare;
|
||||
error_log /var/log/nginx/lovinator.space.error.log warn;
|
||||
|
||||
# favicon.ico
|
||||
location = /favicon.ico {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# robots.txt
|
||||
location = /robots.txt {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# gzip
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
# This is the URL that the images will be served from
|
||||
server_name i.lovinator.space;
|
||||
|
||||
# Where the images and videos are stored. Should be the same as "Environment="DOMAIN=https://i.lovinator.space/"" in discord-embed.service
|
||||
root /Uploads;
|
||||
location / {
|
||||
try_files $uri $uri/ $uri.html;
|
||||
}
|
||||
|
||||
# logging
|
||||
access_log /var/log/nginx/lovinator.space.access.log cloudflare;
|
||||
error_log /var/log/nginx/lovinator.space.error.log warn;
|
||||
|
||||
# favicon.ico
|
||||
location = /favicon.ico {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# gzip
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user