Set up web server for img

This commit is contained in:
Gal 2024-04-06 00:05:25 +02:00
parent 548bd4db3e
commit 83ebf548f5
Signed by: gal
GPG Key ID: F035BC65003BC00B
4 changed files with 106 additions and 2 deletions

77
render/Dockerfile Normal file
View File

@ -0,0 +1,77 @@
# Use the official Python image as a base image
FROM python:3.9
# Install required system dependencies
RUN apt-get update && apt-get install -y \
zlib1g-dev \
gconf-service \
libasound2 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
ca-certificates \
fonts-liberation \
libappindicator1 \
libnss3 \
lsb-release \
xdg-utils \
wget \
&& rm -rf /var/lib/apt/lists/*
# Pyppeteer
RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
--no-install-recommends \
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
--no-install-recommends
# It won't run from the root user.
RUN groupadd chrome && useradd -g chrome -s /bin/bash -G audio,video chrome \
&& mkdir -p /home/chrome && chown -R chrome:chrome /home/chrome
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed dependencies specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Expose the port that Gunicorn will listen on
EXPOSE 8000
# Define the command to run the application using Gunicorn
CMD ["gunicorn", "app:app", "-b", "0.0.0.0:8000"]

20
render/docker-compose.yml Normal file
View File

@ -0,0 +1,20 @@
version: '3'
services:
img:
build: .
ports:
- "${IMG_HOST_PORT}:8000"
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.img.rule=Host(`${IMG_URL}`)"
- "traefik.http.routers.img.entrypoints=websecure"
- "traefik.http.routers.img.tls.certresolver=myresolver"
- "traefik.http.services.img.loadbalancer.server.port=8000"
networks:
- traefik_network
networks:
traefik_network:
external: true

View File

@ -8,7 +8,8 @@ import io
app = Flask(__name__)
async def render_html_to_png(html_file_name, css_file_name, output_file_name):
browser = await launch()
#browser = await launch()
browser = await launch(executablePath='/usr/bin/google-chrome-stable', headless=True, args=['--no-sandbox'])
page = await browser.newPage()
await page.setViewport({'width': 800, 'height': 480})
@ -37,4 +38,4 @@ def generate_weather_image():
return send_file(output_file_path, mimetype='image/png')
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5233)
app.run(host='0.0.0.0', port=5233)

6
render/requirements.txt Normal file
View File

@ -0,0 +1,6 @@
Flask==2.2.2
Werkzeug==2.3.7
gunicorn==20.1.0
asyncio==3.4.3
pyppeteer==2.0.0
Pillow==9.0.0