feat: docker alpine support & misc fixes

This commit is contained in:
2024-01-14 14:33:16 +01:00
parent 7553f1b3df
commit b980ef46df
4 changed files with 34 additions and 20 deletions

View File

@@ -1,22 +1,13 @@
FROM python:3.9-slim-buster
FROM alpine
RUN apt update
RUN apt install python3-pip -y
RUN python3 -m pip install --upgrade pip
RUN apt autoremove -y
RUN apt clean
RUN apk add --no-cache py3-pip
RUN python3 -m pip install --no-cache-dir --break-system-packages waitress
COPY req.txt .
RUN python3 -m pip install --no-cache-dir --break-system-packages -r req.txt
RUN mkdir /app
WORKDIR /app
COPY ./ .
RUN python3 -m pip install waitress
COPY req.txt .
RUN python3 -m pip install --no-cache-dir -r req.txt
RUN mkdir /app/pictures
EXPOSE 5000/tcp
ENTRYPOINT ["waitress-serve"]
CMD ["--host", "0.0.0.0", "--port", "5000", "--call", "app:createApp"]

View File

@@ -53,5 +53,20 @@ For automatic redirection after upload you must have a reverse proxy setting a h
}
}
# With Docker-Compose
version: '3'
services:
image-factory:
image: atlantis-image-factory
restart: always
ports:
- "5000:5000"
environment:
UPLOAD_ENABLED: yes
PICTURES_DIRECTORY: picture
volumes:
- "/data/image-factory/pictures/:/app/pictures/"
# Further explanation
I wrote a small article with some more example on how to best use this to optimize your website -if you want to use it for that: [Medium](https://medium.com/anti-clickbait-coalition/responsive-image-factory-f1ed6e61d13c)

6
app.py
View File

@@ -1,4 +1,6 @@
import server as moduleContainingApp
import server as main
def createApp(envivorment=None, start_response=None):
return moduleContainingApp.app
with main.app.app_context():
main.create_app()
return main.app

View File

@@ -8,11 +8,14 @@ import werkzeug.utils
import json
app = flask.Flask("Picture factory app", static_folder=None)
PICTURE_DIR = "pictures/"
app.config['MAX_CONTENT_PATH'] = 32+1000*1000
app.config['UPLOAD_FOLDER'] = PICTURE_DIR
app.config['UPLOAD_ENABLED'] = os.path.isfile("./upload.enable")
PICTURE_DIR = os.environ.get("PICTURES_DIRECTORY") or "pictures/"
app.config['UPLOAD_FOLDER'] = PICTURE_DIR
ENV_UPLOAD_ENABLED = os.environ.get("UPLOAD_ENABLED").lower() in ["yes", "true", "1"]
app.config['UPLOAD_ENABLED'] = os.path.isfile("./upload.enable") or
def generatePicture(pathToOrig, scaleX, scaleY, encoding, crop):
'''Generate an pictures with the requested scales and encoding if it doesn't already exist'''
@@ -167,6 +170,9 @@ def upload():
else:
return flask.render_template("upload.html")
def create_app():
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Picture Factory',