diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..266c5c80 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,24 @@ +.coverage +.git +.github +.gitignore +.mypy_cache +.nvmrc +.python-version +.vscode +**/__pycache__ +**/.gitignore +**/dist +CHANGELOG.md +CODE_OF_CONDUCT.md +compose.yml +CONTRIBUTING.md +env +LICENSE +README.md +requirements_dev.in +requirements_dev.txt +requirements.in +setup.cfg +tests +venv \ No newline at end of file diff --git a/.github/workflows/webpack.yml b/.github/workflows/webpack.yml new file mode 100644 index 00000000..af8e50f2 --- /dev/null +++ b/.github/workflows/webpack.yml @@ -0,0 +1,29 @@ +name: NodeJS with Webpack + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Build + run: | + cd web + npm install + npx webpack diff --git a/.gitignore b/.gitignore index 57f55498..4c30647e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,5 @@ -# Created by https://www.toptal.com/developers/gitignore/api/git,osx,venv,flask,linux,macos,python,windows,certificates,visualstudio,jetbrains+all,visualstudiocode -# Edit at https://www.toptal.com/developers/gitignore?templates=git,osx,venv,flask,linux,macos,python,windows,certificates,visualstudio,jetbrains+all,visualstudiocode - -### certificates ### -*.pem -*.key -*.crt -*.cer -*.der -*.priv +# Created by https://www.toptal.com/developers/gitignore/api/git,flask,linux,macos,python,windows,jetbrains+all,visualstudiocode,venv +# Edit at https://www.toptal.com/developers/gitignore?templates=git,flask,linux,macos,python,windows,jetbrains+all,visualstudiocode,venv ### Flask ### instance/* @@ -278,10 +270,6 @@ fabric.properties !.idea/codeStyles !.idea/runConfigurations -# Azure Toolkit for IntelliJ plugin -# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij -.idea/**/azureSettings.xml - ### Linux ### *~ @@ -330,17 +318,6 @@ Temporary Items # iCloud generated files *.icloud -### OSX ### -# General - -# Icon must end with two \r - -# Thumbnails - -# Files that might appear in the root of a volume - -# Directories potentially created on remote AFP share - ### Python ### # Byte-compiled / optimized / DLL files @@ -490,391 +467,4 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -### VisualStudio ### -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.tlog -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio 6 auto-generated project file (contains which files were open etc.) -*.vbp - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) -*.dsw -*.dsp - -# Visual Studio 6 technical files - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# Visual Studio History (VSHistory) files -.vshistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -*.code-workspace - -# Local History for Visual Studio Code - -# Windows Installer files from build outputs - -# JetBrains Rider -*.sln.iml - -### VisualStudio Patch ### -# Additional files built by Visual Studio - -# End of https://www.toptal.com/developers/gitignore/api/git,osx,venv,flask,linux,macos,python,windows,certificates,visualstudio,jetbrains+all,visualstudiocode +# End of https://www.toptal.com/developers/gitignore/api/git,flask,linux,macos,python,windows,jetbrains+all,visualstudiocode,venv \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..deed13c0 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/jod diff --git a/.python-version b/.python-version index 2c073331..24ee5b1b 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.11 +3.13 diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f653a1..01a09944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased](https://github.com/MashSoftware/time-tracker/compare/main...develop) +## [1.0.0](https://github.com/MashSoftware/time-tracker/compare/v0.29.0...v1.0.0) - 2025-04-xx + ## [0.29.0](https://github.com/MashSoftware/time-tracker/compare/v0.28.3...v0.29.0) - 2023-10-30 ### Added diff --git a/Dockerfile b/Dockerfile index ec758642..cabc2285 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,43 @@ -FROM python:3.11-slim +# Build stage +FROM python:3.13-slim AS builder -RUN useradd containeruser - -WORKDIR /home/containeruser +WORKDIR /build +# Install dependencies needed to build psycopg2 RUN apt-get update && \ apt-get install -y libpq-dev gcc -COPY app app -COPY time_tracker.py config.py docker-entrypoint.sh requirements.txt ./ -RUN pip install -r requirements.txt \ - && chmod +x docker-entrypoint.sh \ - && chown -R containeruser:containeruser ./ +# Install requirements +COPY requirements.txt ./ +RUN pip wheel --no-cache-dir --no-deps --wheel-dir /build/wheels -r requirements.txt + +# Run stage +FROM python:3.13-slim + +# Create app group and user +RUN addgroup --system appgroup && adduser --system --group appuser + +WORKDIR /home/appuser # Set environment variables ENV FLASK_APP=time_tracker.py \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 -USER containeruser +# Install dependency needed to run psycopg2 +RUN apt-get update && \ + apt-get install -y libpq-dev + +# Copy and install requirements from build stage +COPY --chown=appuser:appgroup --from=builder /build/wheels /wheels +COPY --chown=appuser:appgroup --from=builder /build/requirements.txt . +RUN pip install --no-cache /wheels/* + +# Copy runtime code +COPY --chown=appuser:appgroup app app +COPY --chown=appuser:appgroup migrations migrations +COPY --chown=appuser:appgroup --chmod=500 time_tracker.py config.py docker-entrypoint.sh ./ + +USER appuser -EXPOSE 8000 ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/app/__init__.py b/app/__init__.py index d0f72af4..1a3d034b 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,20 +1,15 @@ import logging from flask import Flask -from flask_assets import Bundle, Environment -from flask_compress import Compress from flask_limiter import Limiter from flask_limiter.util import get_remote_address from flask_login import LoginManager from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy -from flask_talisman import Talisman from flask_wtf.csrf import CSRFProtect from config import Config -assets = Environment() -compress = Compress() csrf = CSRFProtect() db = SQLAlchemy() limiter = Limiter(key_func=get_remote_address, default_limits=["2 per second", "60 per minute"]) @@ -25,7 +20,6 @@ login.needs_refresh_message_category = "info" login.refresh_view = "auth.login" migrate = Migrate() -talisman = Talisman() def create_app(config_class=Config): @@ -34,29 +28,12 @@ def create_app(config_class=Config): app.jinja_env.trim_blocks = True app.jinja_env.lstrip_blocks = True - # Set content security policy - csp = { - "default-src": "'self'", - "style-src": "https://cdn.jsdelivr.net", - "font-src": "https://cdn.jsdelivr.net", - "script-src": ["https://cdn.jsdelivr.net", "'self'"], - "img-src": ["data:", "'self'"], - } - # Initialise app extensions - assets.init_app(app) - compress.init_app(app) csrf.init_app(app) db.init_app(app) limiter.init_app(app) login.init_app(app) migrate.init_app(app, db) - talisman.init_app(app, content_security_policy=csp, content_security_policy_nonce_in=["style-src"]) - - # Create static asset bundles - js = Bundle("src/js/*.js", filters="jsmin", output="dist/js/custom-%(version)s.min.js") - if "js" not in assets: - assets.register("js", js) # Register blueprints from app.account import bp as account_bp diff --git a/app/main/routes.py b/app/main/routes.py index 6e4ee2f2..e7bb606f 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -8,7 +8,6 @@ redirect, render_template, request, - send_from_directory, url_for, ) from flask_login import current_user @@ -26,24 +25,6 @@ def index(): return render_template("index.html") -@bp.route("/favicon.ico") -def favicon(): - return send_from_directory( - os.path.join(current_app.root_path, "static"), - "favicon.ico", - mimetype="image/x-icon", - ) - - -@bp.route("/apple-touch-icon.png") -def apple_touch_icon(): - return send_from_directory( - os.path.join(current_app.root_path, "static"), - "apple-touch-icon.png", - mimetype="image/png", - ) - - @bp.route("/help") def help(): return render_template("help.html", title="Help") diff --git a/app/static/src/js/cookie-banner.js b/app/static/src/js/cookie-banner.js deleted file mode 100644 index 9449cbf9..00000000 --- a/app/static/src/js/cookie-banner.js +++ /dev/null @@ -1,51 +0,0 @@ -(function () { - // Dont display if cookies policy already set - if ( - !document.cookie - .split(";") - .some((item) => item.trim().startsWith("cookies_policy=")) - ) { - const cookieBanner = document.getElementById("cookie-banner"); - const defaultMessage = document.getElementById("default-message"); - const acceptedMessage = document.getElementById("accepted-message"); - const rejectedMessage = document.getElementById("rejected-message"); - - // Accept additional cookies - document - .getElementById("accept-cookies") - .addEventListener("click", function () { - // If only using one category of cookie, ammend the policy content as appropriate - document.cookie = - 'cookies_policy={"analytics": "yes", "functional": "yes"}; max-age=31557600; path=/; secure; samesite=lax'; - defaultMessage.hidden = true; - acceptedMessage.hidden = false; - }); - - // Reject additional cookies - document - .getElementById("reject-cookies") - .addEventListener("click", function () { - // If only using one category of cookie, ammend the policy content as appropriate - document.cookie = - 'cookies_policy={"analytics": "no", "functional": "no"}; max-age=31557600; path=/; secure; samesite=lax'; - defaultMessage.hidden = true; - rejectedMessage.hidden = false; - }); - - // Hide accepted message - document - .getElementById("accepted-hide") - .addEventListener("click", function () { - acceptedMessage.hidden = true; - cookieBanner.hidden = true; - }); - - // Hide rejected message - document - .getElementById("rejected-hide") - .addEventListener("click", function () { - rejectedMessage.hidden = true; - cookieBanner.hidden = true; - }); - } -})(); diff --git a/app/templates/base.html b/app/templates/base.html index 274cb9d4..48989c33 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -15,7 +15,7 @@ - + @@ -23,19 +23,18 @@ - - - + + + - + - - + Mash Time Tracker{% if title %} | {{ title }}{% endif %} @@ -45,7 +44,7 @@ {% endif %}