Browse Source

Versión funcionando para docker

politica
Celestino Rey 1 year ago
parent
commit
8b281d8a30
17 changed files with 63 additions and 41 deletions
  1. +1
    -1
      LyricsPy/buildConComposeProd.sh
  2. +2
    -2
      LyricsPy/docker-compose.prod.yml
  3. +2
    -2
      LyricsPy/servicios/Dockerfile
  4. +3
    -0
      LyricsPy/servicios/entrypoint.sh
  5. BIN
      LyricsPy/servicios/instance/songs.db
  6. +32
    -0
      LyricsPy/servicios/lyrics/__init__.py
  7. +0
    -0
      LyricsPy/servicios/lyrics/models.py
  8. +9
    -23
      LyricsPy/servicios/lyrics/paginas.py
  9. +0
    -0
      LyricsPy/servicios/lyrics/static/style.css
  10. +0
    -0
      LyricsPy/servicios/lyrics/templates/add_album.html
  11. +0
    -0
      LyricsPy/servicios/lyrics/templates/add_song.html
  12. +2
    -2
      LyricsPy/servicios/lyrics/templates/album.html
  13. +4
    -4
      LyricsPy/servicios/lyrics/templates/base.html
  14. +4
    -4
      LyricsPy/servicios/lyrics/templates/index.html
  15. +3
    -3
      LyricsPy/servicios/lyrics/templates/search.html
  16. +0
    -0
      LyricsPy/servicios/lyrics/templates/song.html
  17. +1
    -0
      LyricsPy/servicios/requirements.txt

+ 1
- 1
LyricsPy/buildConComposeProd.sh View File

@ -1,3 +1,3 @@
docker-compose -f docker-compose.prod.yml down 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 docker-compose -f docker-compose.prod.yml up -d --build

+ 2
- 2
LyricsPy/docker-compose.prod.yml View File

@ -3,7 +3,7 @@ version: '2.2'
services: services:
lyrics: lyrics:
build: ./servicios 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: volumes:
- lyrics_prod:/instance - lyrics_prod:/instance
expose: expose:
@ -14,7 +14,7 @@ services:
nginx: nginx:
build: ./servicios/nginx build: ./servicios/nginx
ports: ports:
- 1337:80
- 1338:80
depends_on: depends_on:
- lyrics - lyrics


+ 2
- 2
LyricsPy/servicios/Dockerfile View File

@ -2,7 +2,7 @@
FROM python:3.8-slim-buster FROM python:3.8-slim-buster
WORKDIR /
WORKDIR /lyrics
# set environment variables # set environment variables
ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONDONTWRITEBYTECODE 1
@ -21,4 +21,4 @@ COPY . .
# run entrypoint.sh # run entrypoint.sh
#ENTRYPOINT ["./entrypoint.sh"]
ENTRYPOINT ["/lyrics/entrypoint.sh"]

+ 3
- 0
LyricsPy/servicios/entrypoint.sh View File

@ -0,0 +1,3 @@
#!/bin/bash
exec "$@"

BIN
LyricsPy/servicios/instance/songs.db View File


+ 32
- 0
LyricsPy/servicios/lyrics/__init__.py View File

@ -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

LyricsPy/servicios/models.py → LyricsPy/servicios/lyrics/models.py View File


LyricsPy/servicios/app.py → LyricsPy/servicios/lyrics/paginas.py View File

@ -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(): def index():
songs = Song.query.all() songs = Song.query.all()
albums = Album.query.all() albums = Album.query.all()
return render_template('index.html', songs=songs, albums=albums) return render_template('index.html', songs=songs, albums=albums)
@app.route('/song/<int:song_id>')
@bp.route('/song/<int:song_id>')
def song(song_id): def song(song_id):
song = Song.query.get_or_404(song_id) song = Song.query.get_or_404(song_id)
return render_template('song.html', song=song) return render_template('song.html', song=song)
@app.route('/add_song', methods=['GET', 'POST'])
@bp.route('/add_song', methods=['GET', 'POST'])
def add_song(): def add_song():
if request.method == 'POST': if request.method == 'POST':
title = request.form['title'] title = request.form['title']
@ -40,7 +31,7 @@ def add_song():
albums = Album.query.all() albums = Album.query.all()
return render_template('add_song.html', albums=albums) 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(): def add_album():
if request.method == 'POST': if request.method == 'POST':
name = request.form['name'] name = request.form['name']
@ -55,13 +46,13 @@ def add_album():
return render_template('add_album.html') return render_template('add_album.html')
@app.route('/album/<int:album_id>')
@bp.route('/album/<int:album_id>')
def album(album_id): def album(album_id):
album = Album.query.get_or_404(album_id) album = Album.query.get_or_404(album_id)
songs = Song.query.filter_by(album_id=album_id).all() songs = Song.query.filter_by(album_id=album_id).all()
return render_template('album.html', album=album, songs=songs) return render_template('album.html', album=album, songs=songs)
@app.route('/search')
@bp.route('/search')
def search(): def search():
query = request.args.get('query', '') query = request.args.get('query', '')
if query: if query:
@ -69,8 +60,3 @@ def search():
else: else:
songs = [] songs = []
return render_template('search.html', query=query, songs=songs) return render_template('search.html', query=query, songs=songs)
if __name__ == '__main__':
with app.app_context():
db.create_all()
app.run(debug=True)

LyricsPy/servicios/static/style.css → LyricsPy/servicios/lyrics/static/style.css View File


LyricsPy/servicios/templates/add_album.html → LyricsPy/servicios/lyrics/templates/add_album.html View File


LyricsPy/servicios/templates/add_song.html → LyricsPy/servicios/lyrics/templates/add_song.html View File


LyricsPy/servicios/templates/album.html → LyricsPy/servicios/lyrics/templates/album.html View File

@ -9,10 +9,10 @@
<ul> <ul>
{% for song in songs %} {% for song in songs %}
<li> <li>
<a href="{{ url_for('song', song_id=song.id) }}">{{ song.title }} by {{ song.author }}</a>
<a href="{{ url_for('paginas.song', song_id=song.id) }}">{{ song.title }} by {{ song.author }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<a href="{{ url_for('index') }}">Back to Home</a>
<a href="{{ url_for('paginas.index') }}">Back to Home</a>
{% endblock %} {% endblock %}

LyricsPy/servicios/templates/base.html → LyricsPy/servicios/lyrics/templates/base.html View File

@ -11,10 +11,10 @@
<div class="container"> <div class="container">
<h1>My Song Lyrics</h1> <h1>My Song Lyrics</h1>
<nav> <nav>
<a href="{{ url_for('index') }}">Home</a>
<a href="{{ url_for('add_song') }}">Add Song</a>
<a href="{{ url_for('add_album') }}">Add Album</a>
<form action="{{ url_for('search') }}" method="get" style="display:inline;">
<a href="{{ url_for('paginas.index') }}">Home</a>
<a href="{{ url_for('paginas.add_song') }}">Add Song</a>
<a href="{{ url_for('paginas.add_album') }}">Add Album</a>
<form action="{{ url_for('paginas.search') }}" method="get" style="display:inline;">
<input type="text" name="query" placeholder="Search songs..."> <input type="text" name="query" placeholder="Search songs...">
<button type="submit">Search</button> <button type="submit">Search</button>
</form> </form>

LyricsPy/servicios/templates/index.html → LyricsPy/servicios/lyrics/templates/index.html View File

@ -20,9 +20,9 @@
<tbody> <tbody>
{% for song in songs %} {% for song in songs %}
<tr> <tr>
<td><a href="{{ url_for('song', song_id=song.id) }}">{{ song.title }}</a></td>
<td><a href="{{ url_for('paginas.song', song_id=song.id) }}">{{ song.title }}</a></td>
<td>{{ song.author }}</td> <td>{{ song.author }}</td>
<td><a href="{{ url_for('album', album_id=song.album.id) }}">{{ song.album.name }}</a></td>
<td><a href="{{ url_for('paginas.album', album_id=song.album.id) }}">{{ song.album.name }}</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -37,11 +37,11 @@
<ul> <ul>
{% for album in albums %} {% for album in albums %}
<li> <li>
<a href="{{ url_for('album', album_id=album.id) }}">{{ album.name }} by {{ album.artist }} ({{ album.year }})</a>
<a href="{{ url_for('paginas.album', album_id=album.id) }}">{{ album.name }} by {{ album.artist }} ({{ album.year }})</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<hr> <hr>
<a href="{{ url_for('add_album') }}" class="button">Add New Album</a>
<a href="{{ url_for('paginas.add_album') }}" class="button">Add New Album</a>
</div> </div>
{% endblock %} {% endblock %}

LyricsPy/servicios/templates/search.html → LyricsPy/servicios/lyrics/templates/search.html View File

@ -15,9 +15,9 @@
<tbody> <tbody>
{% for song in songs %} {% for song in songs %}
<tr> <tr>
<td><a href="{{ url_for('song', song_id=song.id) }}">{{ song.title }}</a></td>
<td><a href="{{ url_for('paginas.song', song_id=song.id) }}">{{ song.title }}</a></td>
<td>{{ song.author }}</td> <td>{{ song.author }}</td>
<td><a href="{{ url_for('album', album_id=song.album.id) }}">{{ song.album.name }}</a></td>
<td><a href="{{ url_for('paginas.album', album_id=song.album.id) }}">{{ song.album.name }}</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -26,5 +26,5 @@
<p>No songs found matching your query.</p> <p>No songs found matching your query.</p>
{% endif %} {% endif %}
<a href="{{ url_for('index') }}">Back to Home</a>
<a href="{{ url_for('paginas.index') }}">Back to Home</a>
{% endblock %} {% endblock %}

LyricsPy/servicios/templates/song.html → LyricsPy/servicios/lyrics/templates/song.html View File


+ 1
- 0
LyricsPy/servicios/requirements.txt View File

@ -8,3 +8,4 @@ MarkupSafe==2.1.5
SQLAlchemy==2.0.31 SQLAlchemy==2.0.31
typing_extensions==4.12.2 typing_extensions==4.12.2
Werkzeug==3.0.3 Werkzeug==3.0.3
gunicorn==22.0.0

Loading…
Cancel
Save