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