image created
This commit is contained in:
50
Dockerfile
Normal file
50
Dockerfile
Normal file
@@ -0,0 +1,50 @@
|
||||
# Use the official Python image from the Docker Hub
|
||||
FROM python:3.11-slim AS build
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
|
||||
# Install build tools and libraries
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
libffi-dev \
|
||||
libssl-dev \
|
||||
python3-dev \
|
||||
cargo \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Rust
|
||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||
|
||||
# Copy the current directory contents into the container at /app
|
||||
COPY . /app
|
||||
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Stage 2: Runtime stage
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only the necessary files from the build stage
|
||||
COPY --from=build /app /app
|
||||
COPY --from=build /root/.cargo /root/.cargo
|
||||
|
||||
# Install runtime dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libffi-dev \
|
||||
libssl-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Gunicorn
|
||||
RUN pip install gunicorn
|
||||
|
||||
# Make port 5000 available to the world outside this container
|
||||
EXPOSE 5000
|
||||
|
||||
# Run the clear_db script, then the initialization script, and then Gunicorn
|
||||
CMD ["sh", "-c", "python clear_db.py && python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app"]
|
||||
Binary file not shown.
13
app.py
13
app.py
@@ -9,8 +9,8 @@ from flask_migrate import Migrate
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Set the secret key to a fixed value
|
||||
app.config['SECRET_KEY'] = 'Ana_Are_Multe_Mere-Si_Nu_Are_Pere'
|
||||
# Set the secret key from environment variable or use a default value
|
||||
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'Ana_Are_Multe_Mere-Si_Nu_Are_Pere')
|
||||
|
||||
# Configurare baza de date SQLite
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dashboard.db'
|
||||
@@ -239,6 +239,15 @@ def delete_group_content(content_id):
|
||||
db.session.commit()
|
||||
return redirect(url_for('manage_group', group_id=group_id))
|
||||
|
||||
@app.route('/group/<int:group_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
@admin_required
|
||||
def delete_group(group_id):
|
||||
group = Group.query.get_or_404(group_id)
|
||||
db.session.delete(group)
|
||||
db.session.commit()
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
@app.route('/player/<int:player_id>')
|
||||
@login_required
|
||||
def player_page(player_id):
|
||||
|
||||
10
clear_db.py
Normal file
10
clear_db.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from app import app, db
|
||||
|
||||
def clear_database():
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
print("Database cleared and structure recreated.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
clear_database()
|
||||
16
docker-compose.yml
Normal file
16
docker-compose.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
web:
|
||||
image: digi_signage_server_app:latest
|
||||
ports:
|
||||
- "7100:5000"
|
||||
environment:
|
||||
- FLASK_APP=app.py
|
||||
- FLASK_RUN_HOST=0.0.0.0
|
||||
- ADMIN_USER=admin
|
||||
- ADMIN_PASSWORD=Matei
|
||||
- SECRET_KEY=Ma_Duc_Dupa_Merele_Lui_Ana
|
||||
volumes:
|
||||
- .:/app
|
||||
command: sh -c "python clear_db.py && python init_db.py && gunicorn -w 4 -b 0.0.0.0:5000 app:app"
|
||||
20
init_db.py
Normal file
20
init_db.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
from app import app, db, User, bcrypt
|
||||
|
||||
def create_admin_user():
|
||||
admin_username = os.getenv('ADMIN_USER', 'admin')
|
||||
admin_password = os.getenv('ADMIN_PASSWORD', 'admin')
|
||||
hashed_password = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
||||
|
||||
if not User.query.filter_by(username=admin_username).first():
|
||||
admin_user = User(username=admin_username, password=hashed_password, role='admin')
|
||||
db.session.add(admin_user)
|
||||
db.session.commit()
|
||||
print(f"Admin user '{admin_username}' created with password '{admin_password}'")
|
||||
else:
|
||||
print(f"Admin user '{admin_username}' already exists")
|
||||
|
||||
if __name__ == '__main__':
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
create_admin_user()
|
||||
Binary file not shown.
@@ -3,7 +3,7 @@ bcrypt==4.2.1
|
||||
blinker==1.9.0
|
||||
click==8.1.8
|
||||
Flask==3.1.0
|
||||
Flask-Bcrypt==1.0.1
|
||||
|
||||
Flask-Login==0.6.3
|
||||
Flask-Migrate==4.1.0
|
||||
Flask-SQLAlchemy==3.1.1
|
||||
@@ -15,3 +15,5 @@ MarkupSafe==3.0.2
|
||||
SQLAlchemy==2.0.37
|
||||
typing_extensions==4.12.2
|
||||
Werkzeug==3.1.3
|
||||
gunicorn==20.1.0
|
||||
Flask-Bcrypt==1.0.1
|
||||
@@ -81,6 +81,11 @@
|
||||
<div>
|
||||
<a href="{{ url_for('manage_group', group_id=group.id) }}" class="btn btn-sm btn-secondary">Manage Group</a>
|
||||
<a href="{{ url_for('group_fullscreen', group_id=group.id) }}" class="btn btn-sm btn-primary">Full Screen</a>
|
||||
{% if current_user.role == 'admin' %}
|
||||
<form action="{{ url_for('delete_group', group_id=group.id) }}" method="post" style="display:inline;">
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this group?');">Delete</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user