diff --git a/Dockerfile b/Dockerfile index b3ed1b9..f228eee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 76f1d18..6ed4478 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/app.py b/app.py index ee46265..7582d61 100644 --- a/app.py +++ b/app.py @@ -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 diff --git a/server.py b/server.py index edf8ba4..d7129fc 100755 --- a/server.py +++ b/server.py @@ -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',