diff --git a/LyricsPy/buildConComposeProd.sh b/LyricsPy/buildConComposeProd.sh index f0ec60b..2345564 100644 --- a/LyricsPy/buildConComposeProd.sh +++ b/LyricsPy/buildConComposeProd.sh @@ -1,3 +1,3 @@ docker-compose -f docker-compose.prod.yml down -docker rmi lyrics_lyrics +docker rmi lyricspy_lyrics docker-compose -f docker-compose.prod.yml up -d --build diff --git a/LyricsPy/docker-compose.prod.yml b/LyricsPy/docker-compose.prod.yml index 61bc882..3ae0061 100644 --- a/LyricsPy/docker-compose.prod.yml +++ b/LyricsPy/docker-compose.prod.yml @@ -3,7 +3,7 @@ version: '2.2' services: lyrics: build: ./servicios - command: gunicorn --bind 0.0.0.0:5000 app:create_app() + command: gunicorn --bind 0.0.0.0:5000 lyrics:create_app() volumes: - lyrics_prod:/instance expose: @@ -14,7 +14,7 @@ services: nginx: build: ./servicios/nginx ports: - - 1337:80 + - 1338:80 depends_on: - lyrics diff --git a/LyricsPy/servicios/Dockerfile b/LyricsPy/servicios/Dockerfile index dff2a95..e3d73ed 100644 --- a/LyricsPy/servicios/Dockerfile +++ b/LyricsPy/servicios/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.8-slim-buster -WORKDIR / +WORKDIR /lyrics # set environment variables ENV PYTHONDONTWRITEBYTECODE 1 @@ -21,4 +21,4 @@ COPY . . # run entrypoint.sh -#ENTRYPOINT ["./entrypoint.sh"] +ENTRYPOINT ["/lyrics/entrypoint.sh"] diff --git a/LyricsPy/servicios/entrypoint.sh b/LyricsPy/servicios/entrypoint.sh new file mode 100755 index 0000000..5fc4448 --- /dev/null +++ b/LyricsPy/servicios/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +exec "$@" diff --git a/LyricsPy/servicios/instance/songs.db b/LyricsPy/servicios/instance/songs.db new file mode 100644 index 0000000..6262314 Binary files /dev/null and b/LyricsPy/servicios/instance/songs.db differ diff --git a/LyricsPy/servicios/lyrics/__init__.py b/LyricsPy/servicios/lyrics/__init__.py new file mode 100644 index 0000000..1ea8216 --- /dev/null +++ b/LyricsPy/servicios/lyrics/__init__.py @@ -0,0 +1,32 @@ +import os +from flask import Flask +from flask_sqlalchemy import SQLAlchemy + + +from lyrics import paginas + +def create_app(): + app = Flask(__name__) + app.config.from_prefixed_env() + + app.config['SECRET_KEY'] = 'secret-key-goes-here' + app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db' + + from .models import db + + db.init_app(app) + + from . import models + + with app.app_context(): + db.create_all() + +# basededatos.init_app(app) + + app.register_blueprint(paginas.bp) + + print(f"Current Environment: {os.getenv('ENVIRONMENT')}") + print(f"Using Database: {app.config.get('DATABASE')}") + + return app + diff --git a/LyricsPy/servicios/models.py b/LyricsPy/servicios/lyrics/models.py similarity index 100% rename from LyricsPy/servicios/models.py rename to LyricsPy/servicios/lyrics/models.py diff --git a/LyricsPy/servicios/app.py b/LyricsPy/servicios/lyrics/paginas.py similarity index 69% rename from LyricsPy/servicios/app.py rename to LyricsPy/servicios/lyrics/paginas.py index 0e775f9..397c336 100644 --- a/LyricsPy/servicios/app.py +++ b/LyricsPy/servicios/lyrics/paginas.py @@ -1,29 +1,20 @@ -from flask import Flask, render_template, request, redirect, url_for -from models import db, Song, Album +from flask import Blueprint, render_template, request, redirect, url_for +from .models import db, Song, Album -app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db' -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -db.init_app(app) +bp = Blueprint("paginas", __name__) -@app.before_request -def before_request(): - if not hasattr(app, 'db_initialized'): - db.create_all() - app.db_initialized = True - -@app.route('/') +@bp.route('/') def index(): songs = Song.query.all() albums = Album.query.all() return render_template('index.html', songs=songs, albums=albums) -@app.route('/song/') +@bp.route('/song/') def song(song_id): song = Song.query.get_or_404(song_id) return render_template('song.html', song=song) -@app.route('/add_song', methods=['GET', 'POST']) +@bp.route('/add_song', methods=['GET', 'POST']) def add_song(): if request.method == 'POST': title = request.form['title'] @@ -40,7 +31,7 @@ def add_song(): albums = Album.query.all() return render_template('add_song.html', albums=albums) -@app.route('/add_album', methods=['GET', 'POST']) +@bp.route('/add_album', methods=['GET', 'POST']) def add_album(): if request.method == 'POST': name = request.form['name'] @@ -55,13 +46,13 @@ def add_album(): return render_template('add_album.html') -@app.route('/album/') +@bp.route('/album/') def album(album_id): album = Album.query.get_or_404(album_id) songs = Song.query.filter_by(album_id=album_id).all() return render_template('album.html', album=album, songs=songs) -@app.route('/search') +@bp.route('/search') def search(): query = request.args.get('query', '') if query: @@ -69,8 +60,3 @@ def search(): else: songs = [] return render_template('search.html', query=query, songs=songs) - -if __name__ == '__main__': - with app.app_context(): - db.create_all() - app.run(debug=True) diff --git a/LyricsPy/servicios/static/style.css b/LyricsPy/servicios/lyrics/static/style.css similarity index 100% rename from LyricsPy/servicios/static/style.css rename to LyricsPy/servicios/lyrics/static/style.css diff --git a/LyricsPy/servicios/templates/add_album.html b/LyricsPy/servicios/lyrics/templates/add_album.html similarity index 100% rename from LyricsPy/servicios/templates/add_album.html rename to LyricsPy/servicios/lyrics/templates/add_album.html diff --git a/LyricsPy/servicios/templates/add_song.html b/LyricsPy/servicios/lyrics/templates/add_song.html similarity index 100% rename from LyricsPy/servicios/templates/add_song.html rename to LyricsPy/servicios/lyrics/templates/add_song.html diff --git a/LyricsPy/servicios/templates/album.html b/LyricsPy/servicios/lyrics/templates/album.html similarity index 63% rename from LyricsPy/servicios/templates/album.html rename to LyricsPy/servicios/lyrics/templates/album.html index 22cfa5b..268c27d 100644 --- a/LyricsPy/servicios/templates/album.html +++ b/LyricsPy/servicios/lyrics/templates/album.html @@ -9,10 +9,10 @@ -Back to Home +Back to Home {% endblock %} diff --git a/LyricsPy/servicios/templates/base.html b/LyricsPy/servicios/lyrics/templates/base.html similarity index 86% rename from LyricsPy/servicios/templates/base.html rename to LyricsPy/servicios/lyrics/templates/base.html index ebacb20..db4575f 100644 --- a/LyricsPy/servicios/templates/base.html +++ b/LyricsPy/servicios/lyrics/templates/base.html @@ -11,10 +11,10 @@

My Song Lyrics

{% endblock %} diff --git a/LyricsPy/servicios/templates/search.html b/LyricsPy/servicios/lyrics/templates/search.html similarity index 67% rename from LyricsPy/servicios/templates/search.html rename to LyricsPy/servicios/lyrics/templates/search.html index d0d6c03..42d53ce 100644 --- a/LyricsPy/servicios/templates/search.html +++ b/LyricsPy/servicios/lyrics/templates/search.html @@ -15,9 +15,9 @@ {% for song in songs %} - {{ song.title }} + {{ song.title }} {{ song.author }} - {{ song.album.name }} + {{ song.album.name }} {% endfor %} @@ -26,5 +26,5 @@

No songs found matching your query.

{% endif %} -Back to Home +Back to Home {% endblock %} diff --git a/LyricsPy/servicios/templates/song.html b/LyricsPy/servicios/lyrics/templates/song.html similarity index 100% rename from LyricsPy/servicios/templates/song.html rename to LyricsPy/servicios/lyrics/templates/song.html diff --git a/LyricsPy/servicios/requirements.txt b/LyricsPy/servicios/requirements.txt index 6b204e4..617696c 100644 --- a/LyricsPy/servicios/requirements.txt +++ b/LyricsPy/servicios/requirements.txt @@ -8,3 +8,4 @@ MarkupSafe==2.1.5 SQLAlchemy==2.0.31 typing_extensions==4.12.2 Werkzeug==3.0.3 +gunicorn==22.0.0