mirror of
https://github.com/FAUSheppy/python-flask-picture-factory
synced 2025-12-05 22:51:36 +01:00
feat: docker alpine support & misc fixes
This commit is contained in:
21
Dockerfile
21
Dockerfile
@@ -1,22 +1,13 @@
|
|||||||
FROM python:3.9-slim-buster
|
FROM alpine
|
||||||
|
|
||||||
RUN apt update
|
RUN apk add --no-cache py3-pip
|
||||||
RUN apt install python3-pip -y
|
RUN python3 -m pip install --no-cache-dir --break-system-packages waitress
|
||||||
RUN python3 -m pip install --upgrade pip
|
COPY req.txt .
|
||||||
RUN apt autoremove -y
|
RUN python3 -m pip install --no-cache-dir --break-system-packages -r req.txt
|
||||||
RUN apt clean
|
|
||||||
|
|
||||||
|
RUN mkdir /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY ./ .
|
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"]
|
ENTRYPOINT ["waitress-serve"]
|
||||||
CMD ["--host", "0.0.0.0", "--port", "5000", "--call", "app:createApp"]
|
CMD ["--host", "0.0.0.0", "--port", "5000", "--call", "app:createApp"]
|
||||||
|
|||||||
15
README.md
15
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
|
# 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)
|
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
6
app.py
@@ -1,4 +1,6 @@
|
|||||||
import server as moduleContainingApp
|
import server as main
|
||||||
|
|
||||||
def createApp(envivorment=None, start_response=None):
|
def createApp(envivorment=None, start_response=None):
|
||||||
return moduleContainingApp.app
|
with main.app.app_context():
|
||||||
|
main.create_app()
|
||||||
|
return main.app
|
||||||
|
|||||||
12
server.py
12
server.py
@@ -8,11 +8,14 @@ import werkzeug.utils
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
app = flask.Flask("Picture factory app", static_folder=None)
|
app = flask.Flask("Picture factory app", static_folder=None)
|
||||||
PICTURE_DIR = "pictures/"
|
|
||||||
|
|
||||||
app.config['MAX_CONTENT_PATH'] = 32+1000*1000
|
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):
|
def generatePicture(pathToOrig, scaleX, scaleY, encoding, crop):
|
||||||
'''Generate an pictures with the requested scales and encoding if it doesn't already exist'''
|
'''Generate an pictures with the requested scales and encoding if it doesn't already exist'''
|
||||||
@@ -167,6 +170,9 @@ def upload():
|
|||||||
else:
|
else:
|
||||||
return flask.render_template("upload.html")
|
return flask.render_template("upload.html")
|
||||||
|
|
||||||
|
def create_app():
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Picture Factory',
|
parser = argparse.ArgumentParser(description='Picture Factory',
|
||||||
|
|||||||
Reference in New Issue
Block a user