Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish Docker Image

on:
release:
types: [ published ]

env:
# GitHub repository is basically "$org/$repo"
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v2

# User triggering the action is authenticated to the container registry
- name: Log in to the Container registry
uses: docker/login-action@v1.10.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Basically sets the image tag from the release
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v3.6.0
with:
images: ghcr.io/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v2.7.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
14 changes: 14 additions & 0 deletions .github/workflows/try-build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Build Docker image.

on:
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ RUN apt-get clean \
&& apt-get -y update

WORKDIR /src
ADD requirements.txt /src
COPY requirements.txt /src
RUN pip install -r requirements.txt
ADD src /src/
COPY src /src/

ENV SECRET_KEY verysecretXd
ENV PORT 4001
EXPOSE $PORT

CMD uwsgi --enable-threads --http-socket :$PORT --module tv:app
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ A day starts at 5:00 and ends at 5:00 the next day. This means that an end date
The default priority is 0. If a PR has its priority set to 1, it will be the only PR shown until its end date (useful for pubs etc.).

## Running in Docker
```
git clone https://github.com/mightynerd/tvmannen
make build
make up-prod
```
***Important***: Change ```SECRET_KEY``` in ```src/config.py``` to something more secret.
The provided sample compose file should work out of the box provided a
`SECRET_KEY` env-variable. Aditional variables can be found in `src/config.py`.

See docker-compose.yml/docker-compose.prod.yml for ports, which you probably want to change. A default admin account will be created on first start (if no existing database is present). Visit ```/login``` and login with "admin" and "pass".
At first launc the database is populated with a user _admin_ with the password
_pass_. It is suggested you change this immediately.
7 changes: 0 additions & 7 deletions docker-compose.prod.yml

This file was deleted.

14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
version: '3'
version: '3.7'

services:
web:
build: .
restart: always
ports:
- "4001:4001"
- "4001:4001"
environment:
- SECRET_KEY
- DATABASE_URI=sqlite:////db/data
volumes:
- db:/db
- uploads:/src/static/pr

volumes:
db:
uploads:
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Flask==1.1.1
uWSGI==2.0.17.1
Flask-SQLAlchemy==2.4.1
flask_wtf==0.14.2
Flask-SQLAlchemy==2.5
flask_wtf==0.14.3
WTForms==2.2.1
flask_login==0.4.1
9 changes: 8 additions & 1 deletion src/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tv import login_manager, db, config, app
import os
import uuid
from datetime import datetime, timedelta
from flask_login import LoginManager, current_user, login_user, logout_user, login_required
from flask import Blueprint, flash, redirect, render_template, request
from data import User, PR, add_pr, fix_date
Expand Down Expand Up @@ -36,6 +37,7 @@ def check_priority(start, end, priority):
@login_required
def admin():
form = PRForm()

if form.validate_on_submit():
filename = form.file.data.filename
if not filename or not allowed_file(filename):
Expand Down Expand Up @@ -70,6 +72,11 @@ def admin():
user_id=current_user.id,
owner=current_user.username)
return redirect("/admin")
else:
# Change the default start and end dates
today = datetime.today()
form.start_date.data = today
form.end_date.data = today

if current_user.role == "admin":
pr = PR.query.all()
Expand Down Expand Up @@ -126,7 +133,7 @@ def modify():

form = ModifyPRForm()
if form.validate_on_submit():
start, end = fix_date(form.start_date.data, form.end_date.data)
start, end = fix_date(form.start_date.data, form.end_date.data, form.priority.data)
pr.start_date = start
pr.end_date = end
pr.priority = form.priority.data
Expand Down
19 changes: 14 additions & 5 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@


class Config(object):
SECRET_KEY = "verysecretXd"
MAX_CONTENT_LENGTH = 5 * 1024 * 1024
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(curdir, 'db.db')
SECRET_KEY = os.environ["SECRET_KEY"]
MAX_CONTENT_LENGTH = int(os.getenv("MAX_CONTENT_LENGTH", 5 * 1024 * 1024))
SQLALCHEMY_DATABASE_URI = os.getenv(
"DATABASE_URI",
"sqlite:///" + os.path.join(curdir, "db.db"),
)
SQLALCHEMY_TRACK_MODIFICATIONS = False
UPLOAD_FOLDER = os.path.join(curdir, "static", "pr")
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'mp4'}
UPLOAD_FOLDER = os.getenv("UPLOAD_FOLDER", os.path.join(curdir, "static", "pr"))
ALLOWED_EXTENSIONS = set(
os.getenv("ALLOWED_EXTENSIONS", "png,jpg,jpeg,mp4").split(",")
)
# Time for each PR in seconds
PR_TIME = int(os.getenv("PR_TIME", 30))
# How often the PR list is fetched
PR_FETCH_TIME = int(os.getenv("PR_FETCH_TIME", 120))
10 changes: 3 additions & 7 deletions src/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from wtforms.fields.html5 import DateField
from wtforms.validators import DataRequired, ValidationError, EqualTo, Length
from data import User
from datetime import datetime

roles = [('admin', "Admin"), ('pr', "PR")]

Expand Down Expand Up @@ -36,9 +35,6 @@ def validate_username(self, username):
raise ValidationError('Username already taken')

class PRForm(FlaskForm):
today = datetime.today()
tomorrow = today.replace(day=today.day + 1)

file = FileField(label="File:",
validators=[DataRequired()])

Expand All @@ -47,10 +43,10 @@ class PRForm(FlaskForm):
render_kw={"placeholder": "Hackkväll 24/12"})

start_date = DateField("Start date:",
validators=[DataRequired()], default=today)
validators=[DataRequired()])

end_date = DateField("End date:",
validators=[DataRequired()], default=tomorrow)
validators=[DataRequired()])

priority = BooleanField("Priority:")
submit = SubmitField('Upload PR')
Expand Down Expand Up @@ -82,7 +78,7 @@ class ModifyPRForm(FlaskForm):
validators=[DataRequired()])

end_date = DateField("End date:",
alidators=[DataRequired()])
validators=[DataRequired()])

priority = BooleanField("Priority:")
submit = SubmitField('Save changes')
2 changes: 1 addition & 1 deletion src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</p>
{% endif %}

<p>TV-Mannen</p>
<p><a href="https://github.com/dtekcth/tvmannen">TV-Mannen</a></p>
</footer>
</body>
</html>
60 changes: 31 additions & 29 deletions src/templates/pr.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- Page for displaying PRs -->
<!-- Could be static -->
<!DOCTYPE html>
<html>

Expand Down Expand Up @@ -36,10 +35,9 @@
left: 0;
width: 100%;
height: 100%;
}

}
</style>

<script>

var curr = 0;
Expand All @@ -49,18 +47,16 @@
body = document.getElementById("body");

// No PR -> show dtek logo
if (prs.length < 1)
{
if (prs.length < 1) {
body.style.backgroundImage = "url(https://dtek.se/static/datalogo.svg)";
body.style.backgroundColor = "#fa6607";
return;
}

// If a pr has been deleted since last call
curr %= prs.length;
curr %= prs.length;

if (prs[curr].endsWith(".mp4"))
{
if (prs[curr].endsWith(".mp4")) {
// Video (only mp4)
var video = document.createElement('video');
video.autoplay = true;
Expand All @@ -73,44 +69,50 @@
video.append(source);

body.innerHTML = "";
body.style.backgroundColor = "#000000";
body.style.backgroundColor = "#fa6607";
body.style.backgroundImage = "none";
body.appendChild(video);
}
else
{
else {
// Image
body.innerHTML = "";
body.style.backgroundColor = "#000000";
body.style.backgroundColor = "#fa6607";
body.style.backgroundImage = "url(" + prs[curr] + ")";
}

curr++;
curr %= prs.length;
}

// Get list of PRs from /pr
function get_prs() {
var request = new XMLHttpRequest();
request.open("GET", "/pr");
request.responseType = 'json';
request.send();

request.onload = function () {
var prev_prs = prs;
prs = request.response;

// Call next_pr on first load
if (prev_prs === undefined)
next_pr();
var request = new XMLHttpRequest();
request.open("GET", "/pr");
request.responseType = 'json';
request.send();

request.onload = function () {
var prev_prs = prs;
prs = request.response;

// Call next_pr on first load
if (prev_prs === undefined)
next_pr();
}
}

// Naively switch to next PR when pressing spacebar
document.onkeypress = function (e) {
if (e.keyCode === 32) {
next_pr()
}
};

// How long a PR is shown
setInterval(next_pr, 10000);
setInterval(next_pr, {{ pr_time }} * 1000);

// How often the PR list is updated
setInterval(get_prs, 60000)
setInterval(get_prs, {{ pr_fetch_time }} * 1000)

</script>
</head>
Expand All @@ -119,4 +121,4 @@
<br>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion src/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@app.route('/')
@app.route('/index')
def index():
return render_template("pr.html")
return render_template("pr.html", pr_time = config.PR_TIME, pr_fetch_time = config.PR_FETCH_TIME)

# Delete old PRs
def pr_cleanup():
Expand Down