diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml new file mode 100644 index 0000000..4f04cd4 --- /dev/null +++ b/.github/workflows/publish-docker-image.yml @@ -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 }} diff --git a/.github/workflows/try-build-docker-image.yml b/.github/workflows/try-build-docker-image.yml new file mode 100644 index 0000000..8e70971 --- /dev/null +++ b/.github/workflows/try-build-docker-image.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 0e6bb05..7780c86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ \ No newline at end of file +COPY src /src/ + +ENV SECRET_KEY verysecretXd +ENV PORT 4001 +EXPOSE $PORT + +CMD uwsgi --enable-threads --http-socket :$PORT --module tv:app diff --git a/Makefile b/Makefile deleted file mode 100644 index 44f8f8b..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -#!make - -build: - sudo -E docker-compose build - -up-prod: - sudo -E docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d \ No newline at end of file diff --git a/README.md b/README.md index fb20a3f..755a308 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml deleted file mode 100644 index 8b20814..0000000 --- a/docker-compose.prod.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: '3' - -services: - web: - command: uwsgi --enable-threads --socket :4001 --module tv:app - volumes: - - ./src:/src \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 37dbfb0..afc4d3c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,18 @@ -version: '3' +version: '3.7' services: web: build: . restart: always ports: - - "4001:4001" \ No newline at end of file + - "4001:4001" + environment: + - SECRET_KEY + - DATABASE_URI=sqlite:////db/data + volumes: + - db:/db + - uploads:/src/static/pr + +volumes: + db: + uploads: diff --git a/requirements.txt b/requirements.txt index 072abbc..27032c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/src/config.py b/src/config.py index 50abf43..eb1187b 100644 --- a/src/config.py +++ b/src/config.py @@ -3,11 +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'} - PR_TIME = 30 # Time for each PR in seconds - PR_FETCH_TIME = 120 # How often the PR list is fetched + 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))