changes for docker compose
This commit is contained in:
parent
2a4201d68f
commit
7969b3f9a0
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,5 +2,6 @@ env
|
||||
.env
|
||||
movielist.sqlite
|
||||
posters/*
|
||||
db/*
|
||||
__pycache__
|
||||
*~
|
||||
|
31
Dockerfile
Normal file
31
Dockerfile
Normal file
@ -0,0 +1,31 @@
|
||||
# Use an official Python runtime as the base image
|
||||
FROM python:3.9-slim
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the project files into the container
|
||||
COPY . .
|
||||
RUN chmod +x docker-entrypoint.sh
|
||||
|
||||
# Create a volume for the posters
|
||||
VOLUME /app/posters
|
||||
VOLUME /app/db
|
||||
|
||||
# Install the project dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Set environment variables
|
||||
ENV FLASK_APP=kinolist
|
||||
ENV FLASK_RUN_HOST=0.0.0.0
|
||||
ENV FLASK_DATABASE=/app/db/movielist.sqlite
|
||||
ENV FLASK_IMAGE_WIDTH=200
|
||||
|
||||
# Initialize the database
|
||||
RUN flask --app kinolist init-db
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 8000
|
||||
|
||||
# Run the application
|
||||
CMD ["/app/docker-entrypoint.sh"]
|
@ -50,6 +50,3 @@ If you are not in the virtual environment (the `(env)` keyword does not appear i
|
||||
python -m flask --app kinolist run --port 8000 --debug
|
||||
```
|
||||
You can access the site at the adress `localhost:8000` on your web browser. Do `Ctrl+C` to stop the server.
|
||||
|
||||
# Remarks
|
||||
For some reasons, I need a symbolic link from `posters/` to `kinolist/posters/`, I guess it is because python keeps changing the base directory, so the fix I have found is to have two `posters` folders which are actually the same.
|
||||
|
10
configure.sh
10
configure.sh
@ -1,10 +0,0 @@
|
||||
if [ ! -d env ]; then
|
||||
python -m venv env
|
||||
source env/bin/activate
|
||||
python -m pip install -r requirements.txt
|
||||
fi
|
||||
|
||||
if [ ! -f movielist.sqlite ]; then
|
||||
source env/bin/activate
|
||||
python -m flask --app kinolist init-db
|
||||
fi
|
22
docker-compose.yml
Normal file
22
docker-compose.yml
Normal file
@ -0,0 +1,22 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./posters:/app/posters
|
||||
- ./db/:/app/db
|
||||
environment:
|
||||
- FLASK_SECRET_KEY=${FLASK_SECRET_KEY}
|
||||
- FLASK_OMDB_KEY=${FLASK_OMDB_KEY}
|
||||
- FLASK_ADMIN_PASSWORD=${FLASK_ADMIN_PASSWORD}
|
||||
- FLASK_DATABASE=/app/db/movielist.sqlite
|
||||
- FLASK_IMAGE_WIDTH=200
|
||||
env_file:
|
||||
- .env
|
||||
|
||||
volumes:
|
||||
posters:
|
||||
db:
|
10
docker-entrypoint.sh
Normal file
10
docker-entrypoint.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Check if the database file exists
|
||||
if [ ! -f /app/db/movielist.sqlite ]; then
|
||||
echo "Initializing database..."
|
||||
python -m flask --app kinolist init-db
|
||||
fi
|
||||
|
||||
# Start the Flask application
|
||||
exec gunicorn --bind 0.0.0.0:8000 "kinolist:create_app()"
|
@ -13,4 +13,10 @@ def create_app():
|
||||
database.init_app(app)
|
||||
|
||||
app.register_blueprint(pages.bp)
|
||||
|
||||
base_dir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
# Set the UPLOAD_FOLDER to the parent directory of your project
|
||||
app.config['UPLOAD_FOLDER'] = os.path.join(base_dir, '..', 'posters')
|
||||
|
||||
return app
|
||||
|
@ -76,7 +76,7 @@ def manage():
|
||||
poster = request.files["poster"]
|
||||
filename = posters.save(poster.filename, poster.read())
|
||||
update_poster(id, filename)
|
||||
return filename;
|
||||
return filename
|
||||
elif "plot" in request.form:
|
||||
update_plot(id, request.form["plot"])
|
||||
elif "watched" in request.form:
|
||||
|
@ -1 +0,0 @@
|
||||
../posters
|
@ -1,15 +1,17 @@
|
||||
from flask import (current_app, send_from_directory)
|
||||
from hashlib import sha1
|
||||
from pathlib import Path
|
||||
from os import path
|
||||
import os
|
||||
|
||||
def save(name, content):
|
||||
h = sha1(content).hexdigest()
|
||||
filename = h + Path(name).suffix
|
||||
file = open(path.join(current_app.config['UPLOAD_FOLDER'], filename), "wb")
|
||||
file.write(content)
|
||||
file.close()
|
||||
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
|
||||
|
||||
with open(file_path, "wb") as file:
|
||||
file.write(content)
|
||||
|
||||
return filename
|
||||
|
||||
def get(name):
|
||||
return send_from_directory(current_app.config["UPLOAD_FOLDER"], name)
|
||||
return send_from_directory(current_app.config['UPLOAD_FOLDER'], name)
|
||||
|
@ -3,4 +3,4 @@ Flask
|
||||
Flask-Login
|
||||
python-dotenv
|
||||
requests
|
||||
|
||||
gunicorn
|
||||
|
Loading…
Reference in New Issue
Block a user