Skip to content

Commit

Permalink
Merge pull request #293 from freezingsaddles/fix-confusing-login-mess…
Browse files Browse the repository at this point in the history
…age-take-2

Fix confusing login message, add version banner
  • Loading branch information
obscurerichard authored Nov 30, 2024
2 parents 9400e05 + ac583f3 commit 3d6dd00
Show file tree
Hide file tree
Showing 29 changed files with 148 additions and 38 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build/*
dist/*
env*/*
data/*
*.cfg
*.db
*.dump
.idea
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4

- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Fix metadata
run: |
if [ -x bin/freeze.sh ]; then
bin/freeze.sh
else
echo "No bin/freeze.sh found, skipping"
fi
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -48,13 +65,15 @@ jobs:
if: ${{ github.actor == 'dependabot[bot]' }}
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: ${{ inputs.org }}/${{ inputs.repo }}:${{ inputs.tag }}
-
name: Build and push
if: ${{ github.actor != 'dependabot[bot]' }}
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ inputs.org }}/${{ inputs.repo }}:${{ inputs.tag }}

4 changes: 2 additions & 2 deletions .github/workflows/build-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
jobs:

build:
uses: freezingsaddles/freezing-web/.github/workflows/build-docker.yml@1.4.18
concurrency: build-deploy-and-test
uses: freezingsaddles/freezing-web/.github/workflows/build-docker.yml@1.5.6
concurrency: build-deploy-and-teset
with:
tag: latest
secrets: inherit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
uses: freezingsaddles/freezing-web/.github/workflows/build-docker.yml@1.4.18
uses: freezingsaddles/freezing-web/.github/workflows/build-docker.yml@1.5.6
with:
tag: ${{ github.ref_name }}
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: pull_request

jobs:
build:
uses: freezingsaddles/freezing-web/.github/workflows/build-docker.yml@1.4.18
uses: freezingsaddles/freezing-web/.github/workflows/build-docker.yml@1.5.6
with:
tag: latest-actions-build
secrets: inherit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
*.cfg
*.egg-info
*.pyc
*.tmp
.env*
.venv*
/*.iml
/build
/data/cache/*
/dist
/env
/freezing/web/utils/meta.py
/local_settings.py
/resources/docker/db/sql-scripts
/resources/docker/settings.cfg
/src
tmp.*
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ADD . /app
RUN mkdir -p /data
COPY leaderboards /data/leaderboards
WORKDIR /app
RUN pip3 install .
ENV LEADERBOARDS_DIR=/data/leaderboards
USER freezing
EXPOSE 8000
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ mysql> select a.name, sum(ds.distance), sum(ds.points) from daily_scores ds inne
+-------------------+-------------------+-------------------+
2 rows in set (0.02 sec)
```

# Legal

This software is a community-driven effort, and as such the contributions are owned by the individual contributors:
Expand Down
19 changes: 19 additions & 0 deletions bin/freeze.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
#
# freeze.sh
#
# Overwrite freezing/meta.py with the current commit, branch name and build date.

# Set unofficial bash strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'

# Thanks https://stackoverflow.com/a/64195658/424301
SHORT_SHA="$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8)"
GITHUB_REF_NAME=${GITHUB_REF_NAME:-unknown}

cat <<EOF > "freezing/meta.py"
commit = "$SHORT_SHA"
branch = "$GITHUB_REF_NAME"
build_date = "$(date -u +'%Y%m%dT%H%M%SZ')"
EOF
42 changes: 42 additions & 0 deletions freezing/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# meta.py
#
# Metadata about the built version of this package
#
# The bin/freeze.sh script will replace this file with
# frozen values of commit, build_date, and branch.

import datetime
import subprocess


# Thanks https://stackoverflow.com/a/21901260/424301
def get_git_revision_short_hash() -> str:
return (
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
.decode("ascii")
.strip()
)


def get_git_branch() -> str:
return (
subprocess.check_output(["git", "symbolic-ref", "-q", "HEAD"])
.decode("ascii")
.strip()
.replace("refs/heads/", "")
)


def freeze():
return f"""
commit = "{get_git_revision_short_hash()}"
build_date = "{datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%SZ')}"
branch = "{get_git_branch()}"
"""


# Thanks https://stackoverflow.com/a/4546755/424301 for inspiration
commit = get_git_revision_short_hash()
build_date = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")
branch = get_git_branch()
3 changes: 3 additions & 0 deletions freezing/web/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Flask, g, session

from freezing.model import init_model, meta

from .config import config
Expand Down Expand Up @@ -59,6 +60,8 @@ def teardown_request(exception):
def inject_config():
return {
"competition_title": config.COMPETITION_TITLE,
"environment": config.ENVIRONMENT,
"registration_site": config.REGISTRATION_SITE,
"forum_site": config.FORUM_SITE,
"version_string": config.VERSION_STRING,
}
14 changes: 13 additions & 1 deletion freezing/web/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import logging
import os
from datetime import datetime, tzinfo
from importlib.metadata import version
from typing import List

import arrow
import pytz
from colorlog import ColoredFormatter
from envparse import env

from freezing.meta import branch, build_date, commit

envfile = os.environ.get("APP_SETTINGS", os.path.join(os.getcwd(), ".env"))

if os.path.exists(envfile):
Expand Down Expand Up @@ -56,6 +59,12 @@ class Config:
)
REGISTRATION_SITE: str = env("REGISTRATION_SITE", "https://freezingsaddles.info/")

VERSION_NUM = version("freezing-web")

VERSION_STRING = f"{VERSION_NUM}+{branch}.{commit}.{build_date}"

ENVIRONMENT = env("ENVIRONMENT", default="localdev")


config = Config()

Expand Down Expand Up @@ -89,8 +98,9 @@ def init_logging(loglevel: int = logging.INFO, color: bool = False):

ch.setFormatter(formatter)

logger = logging.getLogger("freezing")
loggers = [
logging.getLogger("freezing"),
logger,
logging.getLogger("stravalib"),
logging.getLogger("requests"),
logging.root,
Expand All @@ -102,3 +112,5 @@ def init_logging(loglevel: int = logging.INFO, color: bool = False):
else:
logger.setLevel(logging.INFO)
logger.addHandler(ch)

logger.info(f"logging initialized for app version {config.VERSION_STRING}")
16 changes: 8 additions & 8 deletions freezing/web/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
import logging
import re

from geoalchemy import WKTSpatialElement
from instagram import InstagramAPIError, InstagramClientError
from requests.exceptions import HTTPError
from sqlalchemy import and_
from stravalib import Client
from stravalib import model as strava_model
from stravalib import unithelper

from freezing.model import meta, orm
from freezing.model.orm import (
Athlete,
Expand All @@ -17,14 +25,6 @@
RideTrack,
Team,
)
from geoalchemy import WKTSpatialElement
from instagram import InstagramAPIError, InstagramClientError
from requests.exceptions import HTTPError
from sqlalchemy import and_
from stravalib import Client
from stravalib import model as strava_model
from stravalib import unithelper

from freezing.web import config
from freezing.web.autolog import log
from freezing.web.exc import (
Expand Down
5 changes: 4 additions & 1 deletion freezing/web/templates/authorization_success.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>Authorization Results</h1>
Or maybe the app just needs to be updated to know about the Strava teams.
</li>
{% else %}
<li>you are not registered with <a href="{{ main_team_page }}">this year's main Freezing Saddles team.</a> Go join the team and then log in again.
<li>you are not registered with <a href="{{ main_team_page }}">this year's main Freezing Saddles team.</a> <strong>Go join the team</strong> and <strong>login again</strong>.
</li>
{% endif %}
</ol>
Expand Down Expand Up @@ -51,6 +51,9 @@ <h1>Authorization Results</h1>
<li><em>Later</em>, you will need to join a <strong>competition team Strava club</strong> as well; please attend the season opener Happy Hour (watch the <a href="{{ forum_site }}">forum for an announcement</a>) and check your email for updates. That will make you show up on the <a href="/leaderboard/team">team</a> <a href="/leaderboard/team_text">leaderboards</a>.
</li>
{% endif %}
<li>
See <a href="/people">other folks who have registered for the event</a>.
</li>
<li>
View your <a href={{ rides_url }}>personal rides page</a>.
</li>
Expand Down
1 change: 1 addition & 0 deletions freezing/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
</div>
</div>

<div style="font-size: 80%; text-align: center">freezing-web version {{ version_string }} {{ environment }}</a></div

</body>
</html>
4 changes: 2 additions & 2 deletions freezing/web/utils/genericboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from typing import Any, Dict, List, Tuple

import yaml
from freezing.model import meta
from freezing.model.msg import BaseMessage, BaseSchema
from marshmallow import fields

from freezing.model import meta
from freezing.model.msg import BaseMessage, BaseSchema
from freezing.web.config import config
from freezing.web.exc import ObjectNotFound

Expand Down
2 changes: 1 addition & 1 deletion freezing/web/utils/hashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from typing import List

import yaml
from freezing.model.msg import BaseMessage, BaseSchema
from marshmallow import fields

from freezing.model.msg import BaseMessage, BaseSchema
from freezing.web.config import config
from freezing.web.exc import ObjectNotFound

Expand Down
2 changes: 1 addition & 1 deletion freezing/web/utils/tribes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from typing import List

import yaml
from freezing.model.msg import BaseMessage, BaseSchema
from marshmallow import fields

from freezing.model.msg import BaseMessage, BaseSchema
from freezing.web.config import config
from freezing.web.exc import ObjectNotFound

Expand Down
2 changes: 1 addition & 1 deletion freezing/web/views/alt_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from statistics import median

from flask import Blueprint, render_template
from freezing.model import meta
from sqlalchemy import text

from freezing.model import meta
from freezing.web import config
from freezing.web.views.shared_sql import (
indiv_freeze_query,
Expand Down
4 changes: 2 additions & 2 deletions freezing/web/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import arrow
import pytz
from flask import Blueprint, jsonify, request
from freezing.model import meta
from freezing.model.orm import Athlete, Ride, RidePhoto, RideTrack
from sqlalchemy import text

from freezing.model import meta
from freezing.model.orm import Athlete, Ride, RidePhoto, RideTrack
from freezing.web import config
from freezing.web.autolog import log
from freezing.web.serialize import RidePhotoSchema
Expand Down
4 changes: 2 additions & 2 deletions freezing/web/views/chartdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

from dateutil import rrule
from flask import Blueprint, current_app, jsonify
from freezing.model import meta
from freezing.model.orm import Team
from pytz import utc
from sqlalchemy import text

from freezing.model import meta
from freezing.model.orm import Team
from freezing.web import config
from freezing.web.utils import gviz_api
from freezing.web.utils.dates import parse_competition_timestamp
Expand Down
Loading

0 comments on commit 3d6dd00

Please sign in to comment.