mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Improve Docker configurations
This commit is contained in:
parent
6f230ee4b2
commit
095494f96f
@ -1,3 +1,5 @@
|
||||
.git
|
||||
data
|
||||
uploads
|
||||
*.pyc
|
||||
__pycache__
|
||||
|
11
Dockerfile
11
Dockerfile
@ -5,15 +5,18 @@ RUN groupadd -g 5123 cdb && \
|
||||
|
||||
WORKDIR /home/cdb
|
||||
|
||||
RUN mkdir /var/cdb
|
||||
RUN chown -R cdb:cdb /var/cdb
|
||||
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install -r ./requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
RUN pip install gunicorn
|
||||
|
||||
COPY utils utils
|
||||
COPY config.cfg ./config.cfg
|
||||
COPY config.cfg config.cfg
|
||||
COPY migrations migrations
|
||||
COPY app app
|
||||
|
||||
RUN mkdir /home/cdb/app/public/uploads/
|
||||
RUN chown cdb:cdb /home/cdb -R
|
||||
RUN chown -R cdb:cdb /home/cdb
|
||||
|
||||
USER cdb
|
||||
|
@ -72,7 +72,7 @@ from flask_login import logout_user
|
||||
|
||||
@app.route("/uploads/<path:path>")
|
||||
def send_upload(path):
|
||||
return send_from_directory("public/uploads", path)
|
||||
return send_from_directory(app.config['UPLOAD_DIR'], path)
|
||||
|
||||
@menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
|
||||
@app.route('/<path:path>/')
|
||||
|
@ -25,10 +25,10 @@ from PIL import Image
|
||||
ALLOWED_RESOLUTIONS=[(100,67), (270,180), (350,233)]
|
||||
|
||||
def mkdir(path):
|
||||
assert(path != "" and path is not None)
|
||||
if not os.path.isdir(path):
|
||||
os.mkdir(path)
|
||||
|
||||
mkdir("app/public/thumbnails/")
|
||||
|
||||
def resize_and_crop(img_path, modified_path, size):
|
||||
img = Image.open(img_path)
|
||||
@ -65,10 +65,15 @@ def make_thumbnail(img, level):
|
||||
|
||||
w, h = ALLOWED_RESOLUTIONS[level - 1]
|
||||
|
||||
mkdir("app/public/thumbnails/{:d}/".format(level))
|
||||
upload_dir = current_app.config["UPLOAD_DIR"]
|
||||
thumbnail_dir = current_app.config["THUMBNAIL_DIR"]
|
||||
mkdir(thumbnail_dir)
|
||||
|
||||
cache_filepath = "public/thumbnails/{:d}/{}".format(level, img)
|
||||
source_filepath = "public/uploads/" + img
|
||||
output_dir = os.path.join(thumbnail_dir, str(level))
|
||||
mkdir(output_dir)
|
||||
|
||||
resize_and_crop("app/" + source_filepath, "app/" + cache_filepath, (w, h))
|
||||
cache_filepath = os.path.join(output_dir, img)
|
||||
source_filepath = os.path.join(upload_dir, img)
|
||||
|
||||
resize_and_crop(source_filepath, cache_filepath, (w, h))
|
||||
return send_file(cache_filepath)
|
||||
|
@ -389,7 +389,7 @@ def makeVCSRelease(id, branch):
|
||||
|
||||
try:
|
||||
filename = randomString(10) + ".zip"
|
||||
destPath = os.path.join("app/public/uploads", filename)
|
||||
destPath = os.path.join(app.config["UPLOAD_DIR"], filename)
|
||||
with open(destPath, "wb") as fp:
|
||||
repo.archive(fp, format="zip")
|
||||
|
||||
@ -424,7 +424,7 @@ def importRepoScreenshot(id):
|
||||
sourcePath = gitDir + "/screenshot." + ext
|
||||
if os.path.isfile(sourcePath):
|
||||
filename = randomString(10) + "." + ext
|
||||
destPath = os.path.join("app/public/uploads", filename)
|
||||
destPath = os.path.join(app.config["UPLOAD_DIR"], filename)
|
||||
shutil.copyfile(sourcePath, destPath)
|
||||
|
||||
ss = PackageScreenshot()
|
||||
|
@ -46,6 +46,8 @@ def randomString(n):
|
||||
return ''.join(random.choice(string.ascii_lowercase + \
|
||||
string.ascii_uppercase + string.digits) for _ in range(n))
|
||||
|
||||
assert(os.path.isdir(app.config["UPLOAD_DIR"]), "UPLOAD_DIR must exist")
|
||||
|
||||
def doFileUpload(file, fileType, fileTypeDesc):
|
||||
if not file or file is None or file.filename == "":
|
||||
flash("No selected file", "error")
|
||||
@ -73,7 +75,7 @@ def doFileUpload(file, fileType, fileTypeDesc):
|
||||
file.stream.seek(0)
|
||||
|
||||
filename = randomString(10) + "." + ext
|
||||
file.save(os.path.join("app/public/uploads", filename))
|
||||
file.save(os.path.join(app.config["UPLOAD_DIR"], filename))
|
||||
return "/uploads/" + filename
|
||||
|
||||
def make_flask_user_password(plaintext_str):
|
||||
|
@ -25,6 +25,9 @@ MAIL_PORT=587
|
||||
MAIL_USE_TLS=True
|
||||
MAIL_UTILS_ERROR_SEND_TO=[""]
|
||||
|
||||
UPLOAD_DIR="/var/cdb/uploads/"
|
||||
THUMBNAIL_DIR="/var/cdb/thumbnails/"
|
||||
|
||||
LANGUAGES = {
|
||||
'en': 'English',
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ services:
|
||||
ports:
|
||||
- 5123:5123
|
||||
volumes:
|
||||
- "./data/uploads:/home/cdb/app/public/uploads"
|
||||
- "./app:/home/cdb/appsrc"
|
||||
- "./migrations:/home/cdb/migrations"
|
||||
- "./data/uploads:/var/cdb/uploads"
|
||||
depends_on:
|
||||
- db
|
||||
- redis
|
||||
@ -36,7 +34,7 @@ services:
|
||||
environment:
|
||||
- FLASK_CONFIG=../config.cfg
|
||||
volumes:
|
||||
- "./data/uploads:/home/cdb/app/public/uploads"
|
||||
- "./data/uploads:/var/cdb/uploads"
|
||||
depends_on:
|
||||
- redis
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user